diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/access-array-data-with-indexes.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/access-array-data-with-indexes.md index 3bc677b78c..f71b808172 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/access-array-data-with-indexes.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/access-array-data-with-indexes.md @@ -18,9 +18,9 @@ dashedName: access-array-data-with-indexes **示例** ```js -var array = [50,60,70]; +const array = [50, 60, 70]; array[0]; -var data = array[1]; +const data = array[1]; ``` 現在 `array[0]` 的值是 `50`, `data` 的值爲 `60`. @@ -76,7 +76,7 @@ if(typeof myArray !== "undefined" && typeof myData !== "undefined"){(function(y, ## --seed-contents-- ```js -var myArray = [50,60,70]; +const myArray = [50, 60, 70]; ``` @@ -84,6 +84,6 @@ var myArray = [50,60,70]; # --solutions-- ```js -var myArray = [50,60,70]; -var myData = myArray[0]; +const myArray = [50, 60, 70]; +const myData = myArray[0]; ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/access-multi-dimensional-arrays-with-indexes.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/access-multi-dimensional-arrays-with-indexes.md index f3a008e9b2..9378814a42 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/access-multi-dimensional-arrays-with-indexes.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/access-multi-dimensional-arrays-with-indexes.md @@ -14,12 +14,13 @@ dashedName: access-multi-dimensional-arrays-with-indexes **例如:** ```js -var arr = [ - [1,2,3], - [4,5,6], - [7,8,9], - [[10,11,12], 13, 14] +const arr = [ + [1, 2, 3], + [4, 5, 6], + [7, 8, 9], + [[10, 11, 12], 13, 14] ]; + arr[3]; arr[3][0]; arr[3][0][1]; @@ -58,14 +59,19 @@ if(typeof myArray !== "undefined"){(function(){return "myData: " + myData + " my ## --seed-contents-- ```js -var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]]; +const myArray = [ + [1, 2, 3], + [4, 5, 6], + [7, 8, 9], + [[10, 11, 12], 13, 14], +]; -var myData = myArray[0][0]; +const myData = myArray[0][0]; ``` # --solutions-- ```js -var myArray = [[1,2,3],[4,5,6], [7,8,9], [[10,11,12], 13, 14]]; -var myData = myArray[2][1]; +const myArray = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [[10, 11, 12], 13, 14]]; +const myData = myArray[2][1]; ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-arrays.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-arrays.md index 710204a32d..f6d97b04c5 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-arrays.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-arrays.md @@ -14,7 +14,7 @@ dashedName: accessing-nested-arrays 下面是訪問嵌套數組的例子: ```js -var ourPets = [ +const ourPets = [ { animalType: "cat", names: [ @@ -32,6 +32,7 @@ var ourPets = [ ] } ]; + ourPets[0].names[1]; ourPets[1].names[0]; ``` @@ -72,7 +73,7 @@ assert(/=\s*myPlants\[1\].list\[1\]/.test(code)); ## --seed-contents-- ```js -var myPlants = [ +const myPlants = [ { type: "flowers", list: [ @@ -91,13 +92,13 @@ var myPlants = [ } ]; -var secondTree = ""; +const secondTree = ""; ``` # --solutions-- ```js -var myPlants = [ +const myPlants = [ { type: "flowers", list: [ @@ -116,5 +117,5 @@ var myPlants = [ } ]; -var secondTree = myPlants[1].list[1]; +const secondTree = myPlants[1].list[1]; ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-objects.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-objects.md index 5f02f3269c..c170f0179c 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-objects.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-objects.md @@ -14,7 +14,7 @@ dashedName: accessing-nested-objects 這是一個嵌套對象: ```js -var ourStorage = { +const ourStorage = { "desk": { "drawer": "stapler" }, @@ -26,6 +26,7 @@ var ourStorage = { "bottom drawer": "soda" } }; + ourStorage.cabinet["top drawer"].folder2; ourStorage.desk.drawer; ``` @@ -66,7 +67,7 @@ assert(/=\s*myStorage\.car\.inside\[\s*("|')glove box\1\s*\]/g.test(code)); ## --seed-contents-- ```js -var myStorage = { +const myStorage = { "car": { "inside": { "glove box": "maps", @@ -78,13 +79,13 @@ var myStorage = { } }; -var gloveBoxContents = undefined; +const gloveBoxContents = undefined; ``` # --solutions-- ```js -var myStorage = { +const myStorage = { "car":{ "inside":{ "glove box":"maps", @@ -95,5 +96,5 @@ var myStorage = { } } }; -var gloveBoxContents = myStorage.car.inside["glove box"]; +const gloveBoxContents = myStorage.car.inside["glove box"]; ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-bracket-notation.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-bracket-notation.md index 9e95bc1935..fae451f97b 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-bracket-notation.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-bracket-notation.md @@ -16,11 +16,12 @@ dashedName: accessing-object-properties-with-bracket-notation 這是一個使用方括號表示法讀取對象屬性的例子: ```js -var myObj = { +const myObj = { "Space Name": "Kirk", "More Space": "Spock", "NoSpace": "USS Enterprise" }; + myObj["Space Name"]; myObj['More Space']; myObj["NoSpace"]; @@ -78,26 +79,25 @@ assert(code.match(/testObj\s*?\[('|")[^'"]+\1\]/g).length > 1); ```js // Setup -var testObj = { +const testObj = { "an entree": "hamburger", "my side": "veggies", "the drink": "water" }; // Only change code below this line - -var entreeValue = testObj; // Change this line -var drinkValue = testObj; // Change this line +const entreeValue = testObj; // Change this line +const drinkValue = testObj; // Change this line ``` # --solutions-- ```js -var testObj = { +const testObj = { "an entree": "hamburger", "my side": "veggies", "the drink": "water" }; -var entreeValue = testObj["an entree"]; -var drinkValue = testObj['the drink']; +const entreeValue = testObj["an entree"]; +const drinkValue = testObj['the drink']; ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-dot-notation.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-dot-notation.md index e7e0008a15..961e84417b 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-dot-notation.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-dot-notation.md @@ -16,15 +16,17 @@ dashedName: accessing-object-properties-with-dot-notation 這裏是一個用點符號(`.`)讀取對象屬性的示例: ```js -var myObj = { +const myObj = { prop1: "val1", prop2: "val2" }; -var prop1val = myObj.prop1; -var prop2val = myObj.prop2; + +const prop1val = myObj.prop1; +const prop2val = myObj.prop2; ``` `prop1val` 的值將爲字符串 `val1`,並且`prop2val` 的值將爲字符串 `val2`。 + # --instructions-- 使用點號讀取 `testObj` 的屬性值。 將變量 `hatValue` 的值設置爲該對象的 `hat` 屬性的值,並將變量 `shirtValue` 的值設置爲該對象的 `shirt` 屬性的值。 @@ -73,27 +75,26 @@ assert(code.match(/testObj\.\w+/g).length > 1); ```js // Setup -var testObj = { +const testObj = { "hat": "ballcap", "shirt": "jersey", "shoes": "cleats" }; // Only change code below this line - -var hatValue = testObj; // Change this line -var shirtValue = testObj; // Change this line +const hatValue = testObj; // Change this line +const shirtValue = testObj; // Change this line ``` # --solutions-- ```js -var testObj = { +const testObj = { "hat": "ballcap", "shirt": "jersey", "shoes": "cleats" }; -var hatValue = testObj.hat; -var shirtValue = testObj.shirt; +const hatValue = testObj.hat; +const shirtValue = testObj.shirt; ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-variables.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-variables.md index 4209de1bec..fb59c32bfd 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-variables.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-variables.md @@ -14,11 +14,14 @@ dashedName: accessing-object-properties-with-variables 以下是一個使用變量來訪問屬性的例子: ```js -var dogs = { - Fido: "Mutt", Hunter: "Doberman", Snoopie: "Beagle" +const dogs = { + Fido: "Mutt", + Hunter: "Doberman", + Snoopie: "Beagle" }; -var myDog = "Hunter"; -var myBreed = dogs[myDog]; + +const myDog = "Hunter"; +const myBreed = dogs[myDog]; console.log(myBreed); ``` @@ -27,14 +30,16 @@ console.log(myBreed); 使用這一概念的另一種情況是:屬性的名字是在程序運行期間動態收集得到的。如下所示: ```js -var someObj = { +const someObj = { propName: "John" }; + function propPrefix(str) { - var s = "prop"; + const s = "prop"; return s + str; } -var someProp = propPrefix("Name"); + +const someProp = propPrefix("Name"); console.log(someObj[someProp]); ``` @@ -96,26 +101,25 @@ if(typeof player !== "undefined"){(function(v){return v;})(player);} ```js // Setup -var testObj = { +const testObj = { 12: "Namath", 16: "Montana", 19: "Unitas" }; // Only change code below this line - -var playerNumber; // Change this line -var player = testObj; // Change this line +const playerNumber = 42; // Change this line +const player = testObj; // Change this line ``` # --solutions-- ```js -var testObj = { +const testObj = { 12: "Namath", 16: "Montana", 19: "Unitas" }; -var playerNumber = 16; -var player = testObj[playerNumber]; +const playerNumber = 16; +const player = testObj[playerNumber]; ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/add-new-properties-to-a-javascript-object.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/add-new-properties-to-a-javascript-object.md index 8019c13315..b99d7e1d72 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/add-new-properties-to-a-javascript-object.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/add-new-properties-to-a-javascript-object.md @@ -28,7 +28,7 @@ ourDog["bark"] = "bow-wow"; 例如: ```js -var ourDog = { +const ourDog = { "name": "Camper", "legs": 4, "tails": 1, @@ -67,7 +67,7 @@ assert(!/bark[^\n]:/.test(code)); ## --seed-contents-- ```js -var myDog = { +const myDog = { "name": "Happy Coder", "legs": 4, "tails": 1, @@ -80,7 +80,7 @@ var myDog = { # --solutions-- ```js -var myDog = { +const myDog = { "name": "Happy Coder", "legs": 4, "tails": 1, diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/add-two-numbers-with-javascript.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/add-two-numbers-with-javascript.md index 233f3fd80c..12a23a3a84 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/add-two-numbers-with-javascript.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/add-two-numbers-with-javascript.md @@ -18,7 +18,7 @@ JavaScript 中,我們通過符號 `+` 來進行加法運算。 **代碼示例:** ```js -myVar = 5 + 10; +const myVar = 5 + 10; ``` 現在,變量 `myVar` 的值爲 `15`。 @@ -52,11 +52,11 @@ assert(/\+/.test(code)); ## --seed-contents-- ```js -var sum = 10 + 0; +const sum = 10 + 0; ``` # --solutions-- ```js -var sum = 10 + 10; +const sum = 10 + 10; ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/adding-a-default-option-in-switch-statements.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/adding-a-default-option-in-switch-statements.md index 433b0df9a6..b6f5dae2fe 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/adding-a-default-option-in-switch-statements.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/adding-a-default-option-in-switch-statements.md @@ -92,7 +92,7 @@ assert(code.match(/break/g).length > 2); ```js function switchOfStuff(val) { - var answer = ""; + let answer = ""; // Only change code below this line @@ -108,7 +108,7 @@ switchOfStuff(1); ```js function switchOfStuff(val) { - var answer = ""; + let answer = ""; switch(val) { case "a": diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/appending-variables-to-strings.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/appending-variables-to-strings.md index d23fb4ecf1..4456968254 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/appending-variables-to-strings.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/appending-variables-to-strings.md @@ -14,8 +14,8 @@ dashedName: appending-variables-to-strings 示例: ```js -var anAdjective = "awesome!"; -var ourStr = "freeCodeCamp is "; +const anAdjective = "awesome!"; +let ourStr = "freeCodeCamp is "; ourStr += anAdjective; ``` @@ -64,15 +64,14 @@ assert(code.match(/myStr\s*\+=\s*someAdjective\s*/).length > 0); ```js // Change code below this line - -var someAdjective; -var myStr = "Learning to code is "; +const someAdjective = ""; +let myStr = "Learning to code is "; ``` # --solutions-- ```js -var someAdjective = "neat"; -var myStr = "Learning to code is "; +const someAdjective = "neat"; +let myStr = "Learning to code is "; myStr += someAdjective; ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/build-javascript-objects.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/build-javascript-objects.md index 408956d1dd..6e1cb8200a 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/build-javascript-objects.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/build-javascript-objects.md @@ -18,7 +18,7 @@ dashedName: build-javascript-objects 這裏是一個貓對象的樣本: ```js -var cat = { +const cat = { "name": "Whiskers", "legs": 4, "tails": 1, @@ -29,7 +29,7 @@ var cat = { 在此示例中,所有屬性都存儲爲字符串,例如 `name`、`legs` 和 `tails`。 然而,你也可以使用數字作爲屬性。 你甚至可以省略單字字符串屬性中的引號,如下所示: ```js -var anotherObject = { +const anotherObject = { make: "Ford", 5: "five", "model": "focus" @@ -139,18 +139,18 @@ assert( ## --seed-contents-- ```js -var myDog = { -// Only change code below this line +const myDog = { + // Only change code below this line -// Only change code above this line + // Only change code above this line }; ``` # --solutions-- ```js -var myDog = { +const myDog = { "name": "Camper", "legs": 4, "tails": 1, diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-equality-operator.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-equality-operator.md index 1a4b2e96a8..76ad74cb44 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-equality-operator.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-equality-operator.md @@ -16,7 +16,7 @@ dashedName: comparison-with-the-equality-operator ```js function equalityTest(myVal) { if (myVal == 10) { - return "Equal"; + return "Equal"; } return "Not Equal"; } diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-addition.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-addition.md index c571ebc638..03ea0eed42 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-addition.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-addition.md @@ -20,7 +20,7 @@ myVar = myVar + 5; 其中一種就是 `+=` 運算符。 ```js -var myVar = 1; +let myVar = 1; myVar += 5; console.log(myVar); ``` @@ -61,9 +61,9 @@ assert(code.match(/\+=/g).length === 3); ```js assert( - /var a = 3;/.test(code) && - /var b = 17;/.test(code) && - /var c = 12;/.test(code) + /let a = 3;/.test(code) && + /let b = 17;/.test(code) && + /let c = 12;/.test(code) ); ``` @@ -78,9 +78,9 @@ assert( ## --seed-contents-- ```js -var a = 3; -var b = 17; -var c = 12; +let a = 3; +let b = 17; +let c = 12; // Only change code below this line a = a + 12; @@ -91,9 +91,9 @@ c = c + 7; # --solutions-- ```js -var a = 3; -var b = 17; -var c = 12; +let a = 3; +let b = 17; +let c = 12; a += 12; b += 9; diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-division.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-division.md index ce826e7084..8f72ef5937 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-division.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-division.md @@ -55,9 +55,9 @@ assert(code.match(/\/=/g).length === 3); ```js assert( - /var a = 48;/.test(code) && - /var b = 108;/.test(code) && - /var c = 33;/.test(code) + /let a = 48;/.test(code) && + /let b = 108;/.test(code) && + /let c = 33;/.test(code) ); ``` @@ -72,9 +72,9 @@ assert( ## --seed-contents-- ```js -var a = 48; -var b = 108; -var c = 33; +let a = 48; +let b = 108; +let c = 33; // Only change code below this line a = a / 12; @@ -85,9 +85,9 @@ c = c / 11; # --solutions-- ```js -var a = 48; -var b = 108; -var c = 33; +let a = 48; +let b = 108; +let c = 33; a /= 12; b /= 4; diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-multiplication.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-multiplication.md index d416d51a24..e7af129721 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-multiplication.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-multiplication.md @@ -55,9 +55,9 @@ assert(code.match(/\*=/g).length === 3); ```js assert( - /var a = 5;/.test(code) && - /var b = 12;/.test(code) && - /var c = 4\.6;/.test(code) + /let a = 5;/.test(code) && + /let b = 12;/.test(code) && + /let c = 4\.6;/.test(code) ); ``` @@ -72,9 +72,9 @@ assert( ## --seed-contents-- ```js -var a = 5; -var b = 12; -var c = 4.6; +let a = 5; +let b = 12; +let c = 4.6; // Only change code below this line a = a * 5; @@ -85,9 +85,9 @@ c = c * 10; # --solutions-- ```js -var a = 5; -var b = 12; -var c = 4.6; +let a = 5; +let b = 12; +let c = 4.6; a *= 5; b *= 3; diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-subtraction.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-subtraction.md index 0f5b4749ae..1bf3a6d2d2 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-subtraction.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-subtraction.md @@ -55,7 +55,7 @@ assert(code.match(/-=/g).length === 3); ```js assert( - /var a = 11;/.test(code) && /var b = 9;/.test(code) && /var c = 3;/.test(code) + /let a = 11;/.test(code) && /let b = 9;/.test(code) && /let c = 3;/.test(code) ); ``` @@ -70,9 +70,9 @@ assert( ## --seed-contents-- ```js -var a = 11; -var b = 9; -var c = 3; +let a = 11; +let b = 9; +let c = 3; // Only change code below this line a = a - 6; @@ -83,9 +83,9 @@ c = c - 1; # --solutions-- ```js -var a = 11; -var b = 9; -var c = 3; +let a = 11; +let b = 9; +let c = 3; a -= 6; b -= 15; diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-the-plus-equals-operator.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-the-plus-equals-operator.md index f983cd7eb6..6c93e3a891 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-the-plus-equals-operator.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-the-plus-equals-operator.md @@ -16,7 +16,7 @@ dashedName: concatenating-strings-with-the-plus-equals-operator 例如: ```js -var ourStr = "I come first. "; +let ourStr = "I come first. "; ourStr += "I come second."; ``` @@ -57,14 +57,12 @@ assert(code.match(/myStr\s*\+=\s*(["']).*\1/g)); ## --seed-contents-- ```js -// Only change code below this line - -var myStr; +let myStr; ``` # --solutions-- ```js -var myStr = "This is the first sentence. "; +let myStr = "This is the first sentence. "; myStr += "This is the second sentence."; ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/constructing-strings-with-variables.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/constructing-strings-with-variables.md index 496537114d..61655e5ba6 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/constructing-strings-with-variables.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/constructing-strings-with-variables.md @@ -14,8 +14,8 @@ dashedName: constructing-strings-with-variables 例如: ```js -var ourName = "freeCodeCamp"; -var ourStr = "Hello, our name is " + ourName + ", how are you?"; +const ourName = "freeCodeCamp"; +const ourStr = "Hello, our name is " + ourName + ", how are you?"; ``` `ourStr` 值爲 `Hello, our name is freeCodeCamp, how are you?` @@ -63,13 +63,13 @@ assert(code.match(/["']\s*\+\s*myName\s*\+\s*["']/g).length > 0); ```js // Only change code below this line -var myName; -var myStr; +const myName = ""; +const myStr = ""; ``` # --solutions-- ```js -var myName = "Bob"; -var myStr = "My name is " + myName + " and I am well!"; +const myName = "Bob"; +const myStr = "My name is " + myName + " and I am well!"; ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/counting-cards.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/counting-cards.md index 5a75fe2de2..fe9c860c58 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/counting-cards.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/counting-cards.md @@ -159,7 +159,7 @@ assert( ## --seed-contents-- ```js -var count = 0; +let count = 0; function cc(card) { // Only change code below this line @@ -175,7 +175,7 @@ cc(2); cc(3); cc(7); cc('K'); cc('A'); # --solutions-- ```js -var count = 0; +let count = 0; function cc(card) { switch(card) { case 2: diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/create-decimal-numbers-with-javascript.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/create-decimal-numbers-with-javascript.md index df7e68bc57..b29629c788 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/create-decimal-numbers-with-javascript.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/create-decimal-numbers-with-javascript.md @@ -42,13 +42,14 @@ assert(myDecimal % 1 != 0); ## --seed-contents-- ```js -var ourDecimal = 5.7; +const ourDecimal = 5.7; // Only change code below this line + ``` # --solutions-- ```js -var myDecimal = 9.9; +const myDecimal = 9.9; ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/decrement-a-number-with-javascript.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/decrement-a-number-with-javascript.md index e573f61d88..936ad97e8e 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/decrement-a-number-with-javascript.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/decrement-a-number-with-javascript.md @@ -39,7 +39,7 @@ assert(myVar === 10); ```js assert( - /var\s*myVar\s*=\s*11;\s*\/*.*\s*([-]{2}\s*myVar|myVar\s*[-]{2});/.test(code) + /let\s*myVar\s*=\s*11;\s*\/*.*\s*([-]{2}\s*myVar|myVar\s*[-]{2});/.test(code) ); ``` @@ -52,7 +52,7 @@ assert(/[-]{2}\s*myVar|myVar\s*[-]{2}/.test(code)); 不應修改註釋上方的代碼。 ```js -assert(/var myVar = 11;/.test(code)); +assert(/let myVar = 11;/.test(code)); ``` # --seed-- @@ -66,7 +66,7 @@ assert(/var myVar = 11;/.test(code)); ## --seed-contents-- ```js -var myVar = 11; +let myVar = 11; // Only change code below this line myVar = myVar - 1; @@ -75,6 +75,6 @@ myVar = myVar - 1; # --solutions-- ```js -var myVar = 11; +let myVar = 11; myVar--; ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/delete-properties-from-a-javascript-object.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/delete-properties-from-a-javascript-object.md index 639da32315..358361c0dc 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/delete-properties-from-a-javascript-object.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/delete-properties-from-a-javascript-object.md @@ -18,7 +18,7 @@ delete ourDog.bark; 例如: ```js -var ourDog = { +const ourDog = { "name": "Camper", "legs": 4, "tails": 1, @@ -70,7 +70,7 @@ assert(code.match(/"tails": 1/g).length > 0); ```js // Setup -var myDog = { +const myDog = { "name": "Happy Coder", "legs": 4, "tails": 1, @@ -79,12 +79,13 @@ var myDog = { }; // Only change code below this line + ``` # --solutions-- ```js -var myDog = { +const myDog = { "name": "Happy Coder", "legs": 4, "tails": 1, diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-decimal-by-another-with-javascript.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-decimal-by-another-with-javascript.md index 13331312e7..25b0e99164 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-decimal-by-another-with-javascript.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-decimal-by-another-with-javascript.md @@ -46,11 +46,11 @@ assert(code.match(/quotient/g).length === 1); ## --seed-contents-- ```js -var quotient = 0.0 / 2.0; // Change this line +const quotient = 0.0 / 2.0; // Change this line ``` # --solutions-- ```js -var quotient = 4.4 / 2.0; +const quotient = 4.4 / 2.0; ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-number-by-another-with-javascript.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-number-by-another-with-javascript.md index 4852f262ed..8b0e9eef96 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-number-by-another-with-javascript.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-number-by-another-with-javascript.md @@ -16,7 +16,7 @@ JavaScript 中使用 `/` 符號做除法運算。 **示例** ```js -myVar = 16 / 2; +const myVar = 16 / 2; ``` 現在,變量 `myVar` 的值爲 `8`。 @@ -49,11 +49,11 @@ assert(/\d+\s*\/\s*\d+/.test(code)); ## --seed-contents-- ```js -var quotient = 66 / 0; +const quotient = 66 / 0; ``` # --solutions-- ```js -var quotient = 66 / 33; +const quotient = 66 / 33; ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/escape-sequences-in-strings.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/escape-sequences-in-strings.md index f96a754cb2..bccac3a392 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/escape-sequences-in-strings.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/escape-sequences-in-strings.md @@ -89,11 +89,11 @@ console.log('myStr:\n' + myStr);}})(); ## --seed-contents-- ```js -var myStr; // Change this line +const myStr = ""; // Change this line ``` # --solutions-- ```js -var myStr = "FirstLine\n\t\\SecondLine\nThirdLine"; +const myStr = "FirstLine\n\t\\SecondLine\nThirdLine"; ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/escaping-literal-quotes-in-strings.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/escaping-literal-quotes-in-strings.md index 45942bb07b..54e3c539f7 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/escaping-literal-quotes-in-strings.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/escaping-literal-quotes-in-strings.md @@ -14,7 +14,7 @@ dashedName: escaping-literal-quotes-in-strings 在 JavaScript 中,可以通過在引號前面使用反斜槓(`\`)來轉義引號。 ```js -var sampleStr = "Alan said, \"Peter is learning JavaScript\"."; +const sampleStr = "Alan said, \"Peter is learning JavaScript\"."; ``` 有了轉義符號,JavaScript 就知道這個單引號或雙引號並不是字符串的結尾,而是字符串內的字符。 所以,上面的字符串打印到控制檯的結果爲: @@ -62,11 +62,11 @@ assert(/I am a "double quoted" string inside "double quotes(\."|"\.)$/.test(mySt ## --seed-contents-- ```js -var myStr = ""; // Change this line +const myStr = ""; // Change this line ``` # --solutions-- ```js -var myStr = "I am a \"double quoted\" string inside \"double quotes\"."; +const myStr = "I am a \"double quoted\" string inside \"double quotes\"."; ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/finding-a-remainder-in-javascript.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/finding-a-remainder-in-javascript.md index b00b736b66..46232cd76d 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/finding-a-remainder-in-javascript.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/finding-a-remainder-in-javascript.md @@ -31,7 +31,7 @@ dashedName: finding-a-remainder-in-javascript 變量 `remainder` 應該被初始化。 ```js -assert(/var\s+?remainder/.test(code)); +assert(/(const|let|var)\s+?remainder/.test(code)); ``` `remainder` 的值應該等於 `2`。 @@ -57,13 +57,11 @@ assert(/\s+?remainder\s*?=\s*?.*%.*;?/.test(code)); ## --seed-contents-- ```js -// Only change code below this line - -var remainder; +const remainder = 0; ``` # --solutions-- ```js -var remainder = 11 % 3; +const remainder = 11 % 3; ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/global-vs.-local-scope-in-functions.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/global-vs.-local-scope-in-functions.md index 9499047290..70d72bd977 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/global-vs.-local-scope-in-functions.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/global-vs.-local-scope-in-functions.md @@ -14,9 +14,10 @@ dashedName: global-vs--local-scope-in-functions 下面爲例: ```js -var someVar = "Hat"; +const someVar = "Hat"; + function myFun() { - var someVar = "Head"; + const someVar = "Head"; return someVar; } ``` @@ -53,13 +54,11 @@ assert(/return outerWear/.test(code)); ```js // Setup -var outerWear = "T-Shirt"; +const outerWear = "T-Shirt"; function myOutfit() { // Only change code below this line - - // Only change code above this line return outerWear; } @@ -70,9 +69,9 @@ myOutfit(); # --solutions-- ```js -var outerWear = "T-Shirt"; +const outerWear = "T-Shirt"; function myOutfit() { - var outerWear = "sweater"; + const outerWear = "sweater"; return outerWear; } ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/golf-code.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/golf-code.md index 8dade6734c..da6e34d887 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/golf-code.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/golf-code.md @@ -90,7 +90,8 @@ assert(golfScore(5, 9) === 'Go Home!'); ## --seed-contents-- ```js -var names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"]; +const names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"]; + function golfScore(par, strokes) { // Only change code below this line diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/increment-a-number-with-javascript.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/increment-a-number-with-javascript.md index 777a1bc649..ca78824c50 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/increment-a-number-with-javascript.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/increment-a-number-with-javascript.md @@ -39,7 +39,7 @@ assert(myVar === 88); ```js assert( - /var\s*myVar\s*=\s*87;\s*\/*.*\s*([+]{2}\s*myVar|myVar\s*[+]{2});/.test(code) + /let\s*myVar\s*=\s*87;\s*\/*.*\s*([+]{2}\s*myVar|myVar\s*[+]{2});/.test(code) ); ``` @@ -52,7 +52,7 @@ assert(/[+]{2}\s*myVar|myVar\s*[+]{2}/.test(code)); 不應該修改註釋上面的代碼。 ```js -assert(/var myVar = 87;/.test(code)); +assert(/let myVar = 87;/.test(code)); ``` # --seed-- @@ -66,7 +66,7 @@ assert(/var myVar = 87;/.test(code)); ## --seed-contents-- ```js -var myVar = 87; +let myVar = 87; // Only change code below this line myVar = myVar + 1; @@ -75,6 +75,6 @@ myVar = myVar + 1; # --solutions-- ```js -var myVar = 87; +let myVar = 87; myVar++; ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/introducing-else-statements.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/introducing-else-statements.md index 9e3ff3c710..37f119c593 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/introducing-else-statements.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/introducing-else-statements.md @@ -64,7 +64,7 @@ assert(testElse(10) === 'Bigger than 5'); 不要修改相應註釋的上面或下面的代碼。 ```js -assert(/var result = "";/.test(code) && /return result;/.test(code)); +assert(/let result = "";/.test(code) && /return result;/.test(code)); ``` # --seed-- @@ -73,7 +73,7 @@ assert(/var result = "";/.test(code) && /return result;/.test(code)); ```js function testElse(val) { - var result = ""; + let result = ""; // Only change code below this line if (val > 5) { @@ -95,7 +95,7 @@ testElse(4); ```js function testElse(val) { - var result = ""; + let result = ""; if(val > 5) { result = "Bigger than 5"; } else { diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-through-an-array-with-a-for-loop.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-through-an-array-with-a-for-loop.md index 677aea61e9..95eebdca77 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-through-an-array-with-a-for-loop.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-through-an-array-with-a-for-loop.md @@ -12,8 +12,9 @@ dashedName: iterate-through-an-array-with-a-for-loop JavaScript 中的一個常見任務是遍歷數組的內容。 一種方法是使用 `for` 循環。 下面的代碼將輸出數組 `arr` 的每個元素到控制檯: ```js -var arr = [10, 9, 8, 7, 6]; -for (var i = 0; i < arr.length; i++) { +const arr = [10, 9, 8, 7, 6]; + +for (let i = 0; i < arr.length; i++) { console.log(arr[i]); } ``` @@ -62,18 +63,19 @@ assert(!__helpers.removeWhiteSpace(code).match(/total[=+-]0*[1-9]+/gm)); ```js // Setup -var myArr = [ 2, 3, 4, 5, 6]; +const myArr = [2, 3, 4, 5, 6]; // Only change code below this line + ``` # --solutions-- ```js -var myArr = [ 2, 3, 4, 5, 6]; -var total = 0; +const myArr = [2, 3, 4, 5, 6]; +let total = 0; -for (var i = 0; i < myArr.length; i++) { +for (let i = 0; i < myArr.length; i++) { total += myArr[i]; } ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-do...while-loops.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-do...while-loops.md index b64f2bac08..9eb71f2857 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-do...while-loops.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-do...while-loops.md @@ -12,8 +12,9 @@ dashedName: iterate-with-javascript-do---while-loops 下一種循環叫作 `do...while` 循環。 它被稱爲 `do...while` 循環,是因爲不論什麼情況,它都會首先 `do`(運行)循環裏的第一部分代碼,然後 `while`(當)規定的條件被評估爲 `true`(真)的時候,它會繼續運行循環。 ```js -var ourArray = []; -var i = 0; +const ourArray = []; +let i = 0; + do { ourArray.push(i); i++; @@ -23,8 +24,9 @@ do { 上面的示例行爲類似於其他類型的循環,由此產生的數組將看起來像 `[0, 1, 2, 3, 4]`。 然而,`do...while` 不同於其他循環的地方,是第一次循環檢查失敗時的行爲。 讓我們看看代碼中的區別:這裏是一個常規的 `while` 循環,只要 `i < 5`,就會在循環中運行代碼: ```js -var ourArray = []; -var i = 5; +const ourArray = []; +let i = 5; + while (i < 5) { ourArray.push(i); i++; @@ -34,8 +36,9 @@ while (i < 5) { 這個例子中,定義了一個空數組 `ourArray` 以及一個值爲 5 的 `i` 。 當執行 `while` 循環時,因爲 `i` 不小於 5,所以循環條件爲 `false`,循環內的代碼將不會執行。 `ourArray` 最終沒有添加任何內容,因此示例中的所有代碼執行完時,ourArray 仍然是`[]`。 現在,看一下 `do...while` 循環。 ```js -var ourArray = []; -var i = 5; +const ourArray = []; +let i = 5; + do { ourArray.push(i); i++; @@ -80,8 +83,8 @@ if(typeof myArray !== "undefined"){(function(){return myArray;})();} ```js // Setup -var myArray = []; -var i = 10; +const myArray = []; +let i = 10; // Only change code below this line while (i < 5) { @@ -93,8 +96,8 @@ while (i < 5) { # --solutions-- ```js -var myArray = []; -var i = 10; +const myArray = []; +let i = 10; do { myArray.push(i); i++; diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/local-scope-and-functions.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/local-scope-and-functions.md index a288458974..a3af68c767 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/local-scope-and-functions.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/local-scope-and-functions.md @@ -15,9 +15,10 @@ dashedName: local-scope-and-functions ```js function myTest() { - var loc = "foo"; + const loc = "foo"; console.log(loc); } + myTest(); console.log(loc); ``` @@ -38,6 +39,7 @@ console.log(loc); function declared() { myVar; } + assert.throws(declared, ReferenceError); ``` @@ -57,7 +59,6 @@ assert( ```js function myLocalScope() { - // Only change code below this line console.log('inside myLocalScope', myVar); @@ -73,9 +74,8 @@ console.log('outside myLocalScope', myVar); ```js function myLocalScope() { - // Only change code below this line - var myVar; + let myVar; console.log('inside myLocalScope', myVar); } myLocalScope(); diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-push.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-push.md index 777ce483d8..b8eef3075f 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-push.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-push.md @@ -16,10 +16,10 @@ dashedName: manipulate-arrays-with-push 示例: ```js -var arr1 = [1,2,3]; +const arr1 = [1, 2, 3]; arr1.push(4); -var arr2 = ["Stimpson", "J", "cat"]; +const arr2 = ["Stimpson", "J", "cat"]; arr2.push(["happy", "joy"]); ``` @@ -64,14 +64,15 @@ assert( ```js // Setup -var myArray = [["John", 23], ["cat", 2]]; +const myArray = [["John", 23], ["cat", 2]]; // Only change code below this line + ``` # --solutions-- ```js -var myArray = [["John", 23], ["cat", 2]]; +const myArray = [["John", 23], ["cat", 2]]; myArray.push(["dog",3]); ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/manipulating-complex-objects.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/manipulating-complex-objects.md index a011884850..f303012dad 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/manipulating-complex-objects.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/manipulating-complex-objects.md @@ -14,7 +14,7 @@ dashedName: manipulating-complex-objects 這是一個複雜數據結構的示例: ```js -var ourMusic = [ +const ourMusic = [ { "artist": "Daft Punk", "title": "Homework", @@ -135,7 +135,7 @@ myMusic.forEach(object => { ## --seed-contents-- ```js -var myMusic = [ +const myMusic = [ { "artist": "Billy Joel", "title": "Piano Man", @@ -153,7 +153,7 @@ var myMusic = [ # --solutions-- ```js -var myMusic = [ +const myMusic = [ { "artist": "Billy Joel", "title": "Piano Man", diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/multiple-identical-options-in-switch-statements.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/multiple-identical-options-in-switch-statements.md index fbe5f63ad5..b94f5c079d 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/multiple-identical-options-in-switch-statements.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/multiple-identical-options-in-switch-statements.md @@ -12,7 +12,7 @@ dashedName: multiple-identical-options-in-switch-statements 如果你忘了給 `switch` 的每一條 `case` 添加 `break`,那麼後續的 `case` 會一直執行,直到遇見 `break` 爲止。 如果你想爲 `switch` 中的多個不同的輸入設置相同的結果,可以這樣寫: ```js -var result = ""; +let result = ""; switch(val) { case 1: case 2: @@ -109,7 +109,7 @@ assert(code.match(/case/g).length === 9); ```js function sequentialSizes(val) { - var answer = ""; + let answer = ""; // Only change code below this line @@ -125,7 +125,7 @@ sequentialSizes(1); ```js function sequentialSizes(val) { - var answer = ""; + let answer = ""; switch(val) { case 1: diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-decimals-with-javascript.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-decimals-with-javascript.md index c3cfa69726..b3696fed5c 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-decimals-with-javascript.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-decimals-with-javascript.md @@ -42,11 +42,11 @@ assert(/\*/.test(code)); ## --seed-contents-- ```js -var product = 2.0 * 0.0; +const product = 2.0 * 0.0; ``` # --solutions-- ```js -var product = 2.0 * 2.5; +const product = 2.0 * 2.5; ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-numbers-with-javascript.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-numbers-with-javascript.md index b94896fa86..68345e124f 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-numbers-with-javascript.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-numbers-with-javascript.md @@ -16,7 +16,7 @@ JavaScript 使用 `*` 符號表示兩數相乘。 **示例** ```js -myVar = 13 * 13; +const myVar = 13 * 13; ``` 現在,變量 `myVar` 的值爲 `169`。 @@ -50,11 +50,11 @@ assert(/\*/.test(code)); ## --seed-contents-- ```js -var product = 8 * 0; +const product = 8 * 0; ``` # --solutions-- ```js -var product = 8 * 10; +const product = 8 * 10; ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/nest-one-array-within-another-array.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/nest-one-array-within-another-array.md index 1d1a824772..80950a3b85 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/nest-one-array-within-another-array.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/nest-one-array-within-another-array.md @@ -12,7 +12,7 @@ dashedName: nest-one-array-within-another-array 您也可以在其他數組中嵌套數組,如: ```js -[["Bulls", 23], ["White Sox", 45]] +const teams = [["Bulls", 23], ["White Sox", 45]]; ``` 這也叫做多維數組(multi-dimensional array)。 @@ -41,11 +41,11 @@ if(typeof myArray !== "undefined"){(function(){return myArray;})();} ```js // Only change code below this line -var myArray = []; +const myArray = []; ``` # --solutions-- ```js -var myArray = [[1,2,3]]; +const myArray = [[1, 2, 3]]; ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/profile-lookup.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/profile-lookup.md index 69aef8d388..0d35c8f304 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/profile-lookup.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/profile-lookup.md @@ -68,34 +68,33 @@ assert(lookUpProfile('Akira', 'address') === 'No such property'); ```js // Setup -var contacts = [ - { - "firstName": "Akira", - "lastName": "Laine", - "number": "0543236543", - "likes": ["Pizza", "Coding", "Brownie Points"] - }, - { - "firstName": "Harry", - "lastName": "Potter", - "number": "0994372684", - "likes": ["Hogwarts", "Magic", "Hagrid"] - }, - { - "firstName": "Sherlock", - "lastName": "Holmes", - "number": "0487345643", - "likes": ["Intriguing Cases", "Violin"] - }, - { - "firstName": "Kristian", - "lastName": "Vos", - "number": "unknown", - "likes": ["JavaScript", "Gaming", "Foxes"] - } +const contacts = [ + { + firstName: "Akira", + lastName: "Laine", + number: "0543236543", + likes: ["Pizza", "Coding", "Brownie Points"], + }, + { + firstName: "Harry", + lastName: "Potter", + number: "0994372684", + likes: ["Hogwarts", "Magic", "Hagrid"], + }, + { + firstName: "Sherlock", + lastName: "Holmes", + number: "0487345643", + likes: ["Intriguing Cases", "Violin"], + }, + { + firstName: "Kristian", + lastName: "Vos", + number: "unknown", + likes: ["JavaScript", "Gaming", "Foxes"], + }, ]; - function lookUpProfile(name, prop) { // Only change code below this line @@ -108,44 +107,38 @@ lookUpProfile("Akira", "likes"); # --solutions-- ```js -var contacts = [ - { - "firstName": "Akira", - "lastName": "Laine", - "number": "0543236543", - "likes": ["Pizza", "Coding", "Brownie Points"] - }, - { - "firstName": "Harry", - "lastName": "Potter", - "number": "0994372684", - "likes": ["Hogwarts", "Magic", "Hagrid"] - }, - { - "firstName": "Sherlock", - "lastName": "Holmes", - "number": "0487345643", - "likes": ["Intriguing Cases", "Violin"] - }, - { - "firstName": "Kristian", - "lastName": "Vos", - "number": "unknown", - "likes": ["JavaScript", "Gaming", "Foxes"] - }, +const contacts = [ + { + firstName: "Akira", + lastName: "Laine", + number: "0543236543", + likes: ["Pizza", "Coding", "Brownie Points"], + }, + { + firstName: "Harry", + lastName: "Potter", + number: "0994372684", + likes: ["Hogwarts", "Magic", "Hagrid"], + }, + { + firstName: "Sherlock", + lastName: "Holmes", + number: "0487345643", + likes: ["Intriguing Cases", "Violin"], + }, + { + firstName: "Kristian", + lastName: "Vos", + number: "unknown", + likes: ["JavaScript", "Gaming", "Foxes"], + }, ]; - - -//Write your function in between these comments -function lookUpProfile(name, prop){ - for(var i in contacts){ - if(contacts[i].firstName === name) { - return contacts[i][prop] || "No such property"; - } +function lookUpProfile(name, prop) { + for (let i in contacts) { + if (contacts[i].firstName === name) { + return contacts[i][prop] || "No such property"; } - return "No such contact"; + } + return "No such contact"; } -//Write your function in between these comments - -lookUpProfile("Akira", "likes"); ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/quoting-strings-with-single-quotes.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/quoting-strings-with-single-quotes.md index 3474275e9c..d80d8fb1a5 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/quoting-strings-with-single-quotes.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/quoting-strings-with-single-quotes.md @@ -12,21 +12,21 @@ dashedName: quoting-strings-with-single-quotes JavaScript 中的字符串可以使用開始和結束都是同類型的單引號或雙引號表示。 與其他一些編程語言不同的是,單引號和雙引號的功能在 JavaScript 中是相同的。 ```js -doubleQuoteStr = "This is a string"; -singleQuoteStr = 'This is also a string'; +const doubleQuoteStr = "This is a string"; +const singleQuoteStr = 'This is also a string'; ``` 當你需要在一個字符串中使用多個引號的時候,你可以使用單引號包裹雙引號或者相反。 常見的場景比如在字符串中包含對話的句子需要用引號包裹。 另外比如在一個包含有 `` 標籤的字符串中,標籤的屬性值需要用引號包裹。 ```js -conversation = 'Finn exclaims to Jake, "Algebraic!"'; +const conversation = 'Finn exclaims to Jake, "Algebraic!"'; ``` 然而,如果你需要在其中使用外面的引號,這就成爲一個問題。 記住,一個字符串在開頭和結尾處有相同的引號。 要知道,字符串在開頭和結尾都有相同的引號,如果在中間使用了相同的引號,字符串會提前中止並拋出錯誤。 ```js -goodStr = 'Jake asks Finn, "Hey, let\'s go on an adventure?"'; -badStr = 'Finn responds, "Let's go!"'; +const goodStr = 'Jake asks Finn, "Hey, let\'s go on an adventure?"'; +const badStr = 'Finn responds, "Let's go!"'; ``` 在這裏 `badStr` 會產生一個錯誤。 @@ -71,11 +71,11 @@ assert(code.match(/"/g).length === 4 && code.match(/'/g).length === 2); ## --seed-contents-- ```js -var myStr = "Link"; +const myStr = "Link"; ``` # --solutions-- ```js -var myStr = 'Link'; +const myStr = 'Link'; ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/record-collection.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/record-collection.md index e361219904..2c700ef03f 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/record-collection.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/record-collection.md @@ -115,7 +115,7 @@ const _recordCollection = { ```js // Setup -var recordCollection = { +const recordCollection = { 2548: { albumTitle: 'Slippery When Wet', artist: 'Bon Jovi', @@ -146,7 +146,7 @@ updateRecords(recordCollection, 5439, 'artist', 'ABBA'); # --solutions-- ```js -var recordCollection = { +const recordCollection = { 2548: { albumTitle: 'Slippery When Wet', artist: 'Bon Jovi', diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/replace-loops-using-recursion.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/replace-loops-using-recursion.md index b0f92e916b..6a73a9abbb 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/replace-loops-using-recursion.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/replace-loops-using-recursion.md @@ -14,9 +14,9 @@ dashedName: replace-loops-using-recursion ```js function multiply(arr, n) { - var product = 1; - for (var i = 0; i < n; i++) { - product *= arr[i]; + let product = 1; + for (let i = 0; i < n; i++) { + product *= arr[i]; } return product; } diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/replacing-if-else-chains-with-switch.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/replacing-if-else-chains-with-switch.md index 3ef0e72f7e..8ebaddff5b 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/replacing-if-else-chains-with-switch.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/replacing-if-else-chains-with-switch.md @@ -108,7 +108,7 @@ assert(chainToSwitch(156) === ''); ```js function chainToSwitch(val) { - var answer = ""; + let answer = ""; // Only change code below this line if (val === "bob") { @@ -134,7 +134,7 @@ chainToSwitch(7); ```js function chainToSwitch(val) { - var answer = ""; + let answer = ""; switch(val) { case "bob": diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/return-a-value-from-a-function-with-return.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/return-a-value-from-a-function-with-return.md index 4416139da4..f794893418 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/return-a-value-from-a-function-with-return.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/return-a-value-from-a-function-with-return.md @@ -17,7 +17,8 @@ dashedName: return-a-value-from-a-function-with-return function plusThree(num) { return num + 3; } -var answer = plusThree(5); + +const answer = plusThree(5); ``` `answer` 的值爲 `8`。 diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/selecting-from-many-options-with-switch-statements.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/selecting-from-many-options-with-switch-statements.md index fe19b80933..e105889415 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/selecting-from-many-options-with-switch-statements.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/selecting-from-many-options-with-switch-statements.md @@ -78,7 +78,7 @@ assert(code.match(/break/g).length > 2); ```js function caseInSwitch(val) { - var answer = ""; + let answer = ""; // Only change code below this line @@ -94,7 +94,7 @@ caseInSwitch(1); ```js function caseInSwitch(val) { - var answer = ""; + let answer = ""; switch(val) { case 1: diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/shopping-list.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/shopping-list.md index 3712d37fd3..821da4e8ed 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/shopping-list.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/shopping-list.md @@ -81,13 +81,13 @@ var hasNumber = false; ## --seed-contents-- ```js -var myList = []; +const myList = []; ``` # --solutions-- ```js -var myList = [ +const myList = [ ["Candy", 10], ["Potatoes", 12], ["Eggs", 12], diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/stand-in-line.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/stand-in-line.md index 5c4ea46a83..25a8a539ef 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/stand-in-line.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/stand-in-line.md @@ -93,12 +93,10 @@ function nextInLine(arr, item) { return item; // Only change code above this line - - } // Setup -var testArr = [1,2,3,4,5]; +const testArr = [1, 2, 3, 4, 5]; // Display code console.log("Before: " + JSON.stringify(testArr)); @@ -109,7 +107,7 @@ console.log("After: " + JSON.stringify(testArr)); # --solutions-- ```js -var testArr = [ 1,2,3,4,5]; +const testArr = [1, 2, 3, 4, 5]; function nextInLine(arr, item) { arr.push(item); diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/store-multiple-values-in-one-variable-using-javascript-arrays.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/store-multiple-values-in-one-variable-using-javascript-arrays.md index 4b1cab278e..20adb9f4ae 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/store-multiple-values-in-one-variable-using-javascript-arrays.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/store-multiple-values-in-one-variable-using-javascript-arrays.md @@ -14,7 +14,7 @@ dashedName: store-multiple-values-in-one-variable-using-javascript-arrays 以左方括號開始定義一個數組,以右方括號結束,裏面每個元素之間用逗號隔開,例如: ```js -var sandwich = ["peanut butter", "jelly", "bread"] +const sandwich = ["peanut butter", "jelly", "bread"]; ``` # --instructions-- @@ -53,11 +53,11 @@ assert(typeof myArray[1] !== 'undefined' && typeof myArray[1] == 'number'); ```js // Only change code below this line -var myArray = []; +const myArray = []; ``` # --solutions-- ```js -var myArray = ["The Answer", 42]; +const myArray = ["The Answer", 42]; ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/subtract-one-number-from-another-with-javascript.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/subtract-one-number-from-another-with-javascript.md index 21f07ef062..bf07792029 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/subtract-one-number-from-another-with-javascript.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/subtract-one-number-from-another-with-javascript.md @@ -16,7 +16,7 @@ JavaScript 中使用 `-` 來做減法運算。 **示例** ```js -myVar = 12 - 6; +const myVar = 12 - 6; ``` 現在,變量 `myVar` 的值爲 `6`。 @@ -49,11 +49,11 @@ assert(/difference=45-33;?/.test(__helpers.removeWhiteSpace(code))); ## --seed-contents-- ```js -var difference = 45 - 0; +const difference = 45 - 0; ``` # --solutions-- ```js -var difference = 45 - 33; +const difference = 45 - 33; ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties.md index 30d0d64397..33d21dcdec 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties.md @@ -13,10 +13,11 @@ dashedName: testing-objects-for-properties **示例** ```js -var myObj = { +const myObj = { top: "hat", bottom: "pants" }; + myObj.hasOwnProperty("top"); myObj.hasOwnProperty("middle"); ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/understand-string-immutability.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/understand-string-immutability.md index fa573f673e..bb5ae04a5f 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/understand-string-immutability.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/understand-string-immutability.md @@ -14,14 +14,14 @@ dashedName: understand-string-immutability 例如,下面的代碼: ```js -var myStr = "Bob"; +let myStr = "Bob"; myStr[0] = "J"; ``` 是不會把變量 `myStr` 的值改變成 `Job` 的,因爲變量 `myStr` 是不可變的。 注意,這*並不*意味着 `myStr` 永遠不能被改變,只是字符串字面量 string literal 的各個字符不能被改變。 改變 `myStr` 的唯一方法是重新給它賦一個值,例如: ```js -var myStr = "Bob"; +let myStr = "Bob"; myStr = "Job"; ``` @@ -55,7 +55,7 @@ assert(/myStr = "Jello World"/.test(code)); ```js // Setup -var myStr = "Jello World"; +let myStr = "Jello World"; // Only change code below this line myStr[0] = "H"; // Change this line @@ -65,6 +65,6 @@ myStr[0] = "H"; // Change this line # --solutions-- ```js -var myStr = "Jello World"; +let myStr = "Jello World"; myStr = "Hello World"; ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-boolean-values.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-boolean-values.md index ef14a2c5e6..1576a1570d 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-boolean-values.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-boolean-values.md @@ -43,7 +43,6 @@ welcomeToBooleans(); ```js function welcomeToBooleans() { - // Only change code below this line return false; // Change this line diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-undefined-value-returned-from-a-function.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-undefined-value-returned-from-a-function.md index 269618c331..994779472a 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-undefined-value-returned-from-a-function.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-undefined-value-returned-from-a-function.md @@ -14,10 +14,12 @@ dashedName: understanding-undefined-value-returned-from-a-function **示例** ```js -var sum = 0; +let sum = 0; + function addSum(num) { sum = sum + num; } + addSum(3); ``` @@ -61,7 +63,7 @@ assert( ```js // Setup -var sum = 0; +let sum = 0; function addThree() { sum = sum + 3; @@ -79,7 +81,7 @@ addFive(); # --solutions-- ```js -var sum = 0; +let sum = 0; function addThree() { sum = sum + 3; diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/updating-object-properties.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/updating-object-properties.md index f16bd068ac..93c13e9e31 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/updating-object-properties.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/updating-object-properties.md @@ -14,7 +14,7 @@ dashedName: updating-object-properties 舉個例子,讓我們看看 `ourDog`: ```js -var ourDog = { +const ourDog = { "name": "Camper", "legs": 4, "tails": 1, @@ -54,7 +54,7 @@ assert(/"name": "Coder"/.test(code)); ```js // Setup -var myDog = { +const myDog = { "name": "Coder", "legs": 4, "tails": 1, @@ -62,12 +62,13 @@ var myDog = { }; // Only change code below this line + ``` # --solutions-- ```js -var myDog = { +const myDog = { "name": "Coder", "legs": 4, "tails": 1, diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-nth-character-in-a-string.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-nth-character-in-a-string.md index 3c0dc49284..b48a3627a5 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-nth-character-in-a-string.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-nth-character-in-a-string.md @@ -16,8 +16,8 @@ dashedName: use-bracket-notation-to-find-the-nth-character-in-a-string 例如: ```js -var firstName = "Ada"; -var secondLetterOfFirstName = firstName[1]; +const firstName = "Ada"; +const secondLetterOfFirstName = firstName[1]; ``` `secondLetterOfFirstName` 值應該爲字符串 `d`。 @@ -54,15 +54,15 @@ assert(code.match(/thirdLetterOfLastName\s*?=\s*?lastName\[.*?\]/)); ```js // Setup -var lastName = "Lovelace"; +const lastName = "Lovelace"; // Only change code below this line -var thirdLetterOfLastName = lastName; // Change this line +const thirdLetterOfLastName = lastName; // Change this line ``` # --solutions-- ```js -var lastName = "Lovelace"; -var thirdLetterOfLastName = lastName[2]; +const lastName = "Lovelace"; +const thirdLetterOfLastName = lastName[2]; ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/use-recursion-to-create-a-range-of-numbers.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/use-recursion-to-create-a-range-of-numbers.md index 3f90aeba41..5cc0098b52 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/use-recursion-to-create-a-range-of-numbers.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/use-recursion-to-create-a-range-of-numbers.md @@ -73,7 +73,7 @@ function rangeOfNumbers(startNum, endNum) { if (endNum - startNum === 0) { return [startNum]; } else { - var numbers = rangeOfNumbers(startNum, endNum - 1); + const numbers = rangeOfNumbers(startNum, endNum - 1); numbers.push(endNum); return numbers; } diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function-with-a-radix.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function-with-a-radix.md index 609ac68da9..c88f18ce8c 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function-with-a-radix.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function-with-a-radix.md @@ -20,7 +20,7 @@ parseInt(string, radix); 這是一個示例: ```js -var a = parseInt("11", 2); +const a = parseInt("11", 2); ``` 變量 radix 表示 `11` 是在二進制系統中。 這個示例將字符串 `11` 轉換爲整數 `3`。 diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function.md index 67934c4d25..43c13f31a2 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function.md @@ -12,7 +12,7 @@ dashedName: use-the-parseint-function `parseInt()` 函數解析一個字符串返回一個整數。 下面是一個示例: ```js -var a = parseInt("007"); +const a = parseInt("007"); ``` 上述函數將字符串 `007` 轉換爲整數 `7`。 如果字符串中的第一個字符不能轉換爲數字,則返回 `NaN`。 diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/using-objects-for-lookups.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/using-objects-for-lookups.md index 0e12a75981..009bbea997 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/using-objects-for-lookups.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/using-objects-for-lookups.md @@ -14,7 +14,7 @@ dashedName: using-objects-for-lookups 這是簡單的反向字母表: ```js -var alpha = { +const alpha = { 1:"Z", 2:"Y", 3:"X", @@ -24,10 +24,11 @@ var alpha = { 25:"B", 26:"A" }; + alpha[2]; alpha[24]; -var value = 2; +const value = 2; alpha[value]; ``` @@ -102,7 +103,7 @@ assert( ```js // Setup function phoneticLookup(val) { - var result = ""; + let result = ""; // Only change code below this line switch(val) { @@ -136,9 +137,9 @@ phoneticLookup("charlie"); ```js function phoneticLookup(val) { - var result = ""; + let result = ""; - var lookup = { + const lookup = { alpha: "Adams", bravo: "Boston", charlie: "Chicago", diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/word-blanks.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/word-blanks.md index 533e82a3dd..23a1655c38 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/word-blanks.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/basic-javascript/word-blanks.md @@ -16,7 +16,7 @@ dashedName: word-blanks 思考一下這句話 - It was really **\_\_\_\_**, and we **\_\_\_\_** ourselves **\_\_\_\_**。 這句話有三個缺失的部分 - 形容詞、動詞和副詞,選擇合適單詞填入完成它。 然後將完成的句子賦值給變量,如下所示: ```js -var sentence = "It was really " + "hot" + ", and we " + "laughed" + " ourselves " + "silly" + "."; +const sentence = "It was really " + "hot" + ", and we " + "laughed" + " ourselves " + "silly" + "."; ``` # --instructions-- @@ -84,24 +84,24 @@ const removeAssignments = str => str ## --seed-contents-- ```js -var myNoun = "dog"; -var myAdjective = "big"; -var myVerb = "ran"; -var myAdverb = "quickly"; +const myNoun = "dog"; +const myAdjective = "big"; +const myVerb = "ran"; +const myAdverb = "quickly"; // Only change code below this line -var wordBlanks = ""; // Change this line +const wordBlanks = ""; // Change this line // Only change code above this line ``` # --solutions-- ```js -var myNoun = "dog"; -var myAdjective = "big"; -var myVerb = "ran"; -var myAdverb = "quickly"; +const myNoun = "dog"; +const myAdjective = "big"; +const myVerb = "ran"; +const myAdverb = "quickly"; -var wordBlanks = "Once there was a " + myNoun + " which was very " + myAdjective + ". "; +let wordBlanks = "Once there was a " + myNoun + " which was very " + myAdjective + ". "; wordBlanks += "It " + myVerb + " " + myAdverb + " around the yard."; ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/add-elements-to-the-end-of-an-array-using-concat-instead-of-push.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/add-elements-to-the-end-of-an-array-using-concat-instead-of-push.md index ed76e10d95..3383a8029e 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/add-elements-to-the-end-of-an-array-using-concat-instead-of-push.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/add-elements-to-the-end-of-an-array-using-concat-instead-of-push.md @@ -13,7 +13,7 @@ dashedName: add-elements-to-the-end-of-an-array-using-concat-instead-of-push 上一個挑戰介紹了 `concat` 方法,這是一種在不改變原始數組的前提下,將數組組合成新數組的方法。 將 `concat` 方法與 `push` 方法做比較。 `push` 將元素添加到調用它的數組的末尾,這樣會改變該數組。 舉個例子: ```js -var arr = [1, 2, 3]; +const arr = [1, 2, 3]; arr.push([4, 5, 6]); ``` @@ -71,8 +71,9 @@ function nonMutatingPush(original, newItem) { // Only change code above this line } -var first = [1, 2, 3]; -var second = [4, 5]; + +const first = [1, 2, 3]; +const second = [4, 5]; nonMutatingPush(first, second); ``` @@ -82,7 +83,6 @@ nonMutatingPush(first, second); function nonMutatingPush(original, newItem) { return original.concat(newItem); } -var first = [1, 2, 3]; -var second = [4, 5]; -nonMutatingPush(first, second); +const first = [1, 2, 3]; +const second = [4, 5]; ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs.md index bb8fd38831..ff01baf793 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs.md @@ -77,7 +77,6 @@ function urlSlug(title) { # --solutions-- ```js -// Only change code below this line function urlSlug(title) { return title.trim().split(/\s+/).join("-").toLowerCase(); } diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/avoid-mutations-and-side-effects-using-functional-programming.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/avoid-mutations-and-side-effects-using-functional-programming.md index 3f67e299b9..da3c0c94be 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/avoid-mutations-and-side-effects-using-functional-programming.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/avoid-mutations-and-side-effects-using-functional-programming.md @@ -57,9 +57,9 @@ assert(__newValue === 5); ```js // The global variable -var fixedValue = 4; +let fixedValue = 4; -function incrementer () { +function incrementer() { // Only change code below this line @@ -70,7 +70,7 @@ function incrementer () { # --solutions-- ```js -var fixedValue = 4 +let fixedValue = 4 function incrementer() { return fixedValue + 1 diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/combine-an-array-into-a-string-using-the-join-method.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/combine-an-array-into-a-string-using-the-join-method.md index f82e007c38..b2f4eda2d7 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/combine-an-array-into-a-string-using-the-join-method.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/combine-an-array-into-a-string-using-the-join-method.md @@ -13,8 +13,8 @@ dashedName: combine-an-array-into-a-string-using-the-join-method 舉個例子: ```js -var arr = ["Hello", "World"]; -var str = arr.join(" "); +const arr = ["Hello", "World"]; +const str = arr.join(" "); ``` `str` 的值應該是字符串 `Hello World`。 @@ -76,6 +76,7 @@ function sentensify(str) { // Only change code above this line } + sentensify("May-the-force-be-with-you"); ``` @@ -83,8 +84,6 @@ sentensify("May-the-force-be-with-you"); ```js function sentensify(str) { - // Only change code below this line return str.split(/\W/).join(' '); - // Only change code above this line } ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/combine-two-arrays-using-the-concat-method.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/combine-two-arrays-using-the-concat-method.md index 92a0001506..c82569f3d6 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/combine-two-arrays-using-the-concat-method.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/combine-two-arrays-using-the-concat-method.md @@ -60,8 +60,9 @@ function nonMutatingConcat(original, attach) { // Only change code above this line } -var first = [1, 2, 3]; -var second = [4, 5]; + +const first = [1, 2, 3]; +const second = [4, 5]; nonMutatingConcat(first, second); ``` @@ -69,11 +70,8 @@ nonMutatingConcat(first, second); ```js function nonMutatingConcat(original, attach) { - // Only change code below this line return original.concat(attach); - // Only change code above this line } -var first = [1, 2, 3]; -var second = [4, 5]; -nonMutatingConcat(first, second); +const first = [1, 2, 3]; +const second = [4, 5]; ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype.md index 426f31fe7e..7fc976d251 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype.md @@ -38,17 +38,17 @@ assert(!code.match(/\.?[\s\S]*?map/g)); ```js // The global variable -var s = [23, 65, 98, 5]; +const s = [23, 65, 98, 5]; Array.prototype.myMap = function(callback) { - var newArray = []; + const newArray = []; // Only change code below this line // Only change code above this line return newArray; }; -var new_s = s.myMap(function(item) { +const new_s = s.myMap(function(item) { return item * 2; }); ``` @@ -56,20 +56,17 @@ var new_s = s.myMap(function(item) { # --solutions-- ```js -// the global Array -var s = [23, 65, 98, 5]; +const s = [23, 65, 98, 5]; Array.prototype.myMap = function(callback) { - var newArray = []; - // Only change code below this line - for (var elem of this) { + const newArray = []; + for (const elem of this) { newArray.push(callback(elem)); } - // Only change code above this line return newArray; }; -var new_s = s.myMap(function(item) { +const new_s = s.myMap(function(item) { return item * 2; }); ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/implement-the-filter-method-on-a-prototype.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/implement-the-filter-method-on-a-prototype.md index 1e565f7af0..0f1123713d 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/implement-the-filter-method-on-a-prototype.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/implement-the-filter-method-on-a-prototype.md @@ -34,16 +34,16 @@ assert(!code.match(/\.?[\s\S]*?filter/g)); ```js // The global variable -var s = [23, 65, 98, 5]; +const s = [23, 65, 98, 5]; Array.prototype.myFilter = function(callback) { // Only change code below this line - var newArray = []; + const newArray = []; // Only change code above this line return newArray; }; -var new_s = s.myFilter(function(item) { +const new_s = s.myFilter(function(item) { return item % 2 === 1; }); ``` @@ -51,20 +51,17 @@ var new_s = s.myFilter(function(item) { # --solutions-- ```js -// the global Array -var s = [23, 65, 98, 5]; +const s = [23, 65, 98, 5]; Array.prototype.myFilter = function(callback) { - var newArray = []; - // Only change code below this line + const newArray = []; for (let i = 0; i < this.length; i++) { if (callback(this[i])) newArray.push(this[i]); } - // Only change code above this line return newArray; }; -var new_s = s.myFilter(function(item) { +const new_s = s.myFilter(function(item) { return item % 2 === 1; }); ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/introduction-to-currying-and-partial-application.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/introduction-to-currying-and-partial-application.md index 26f1ee6652..21c948e08e 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/introduction-to-currying-and-partial-application.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/introduction-to-currying-and-partial-application.md @@ -35,7 +35,7 @@ curried(1)(2) 柯里化在不能一次爲函數提供所有參數情況下很有用。 因爲它可以將每個函數的調用保存到一個變量中,該變量將保存返回的函數引用,該引用在下一個參數可用時接受該參數。 下面是使用柯里化函數的例子: ```js -var funcForY = curried(1); +const funcForY = curried(1); console.log(funcForY(2)); // 3 ``` @@ -45,7 +45,8 @@ console.log(funcForY(2)); // 3 function impartial(x, y, z) { return x + y + z; } -var partialFn = impartial.bind(this, 1, 2); + +const partialFn = impartial.bind(this, 1, 2); partialFn(10); // 13 ``` @@ -90,6 +91,7 @@ function add(x) { // Only change code above this line } + add(10)(20)(30); ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/pass-arguments-to-avoid-external-dependence-in-a-function.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/pass-arguments-to-avoid-external-dependence-in-a-function.md index 6364e9d889..e04f7f830b 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/pass-arguments-to-avoid-external-dependence-in-a-function.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/pass-arguments-to-avoid-external-dependence-in-a-function.md @@ -53,10 +53,10 @@ assert(__newValue === 5); ```js // The global variable -var fixedValue = 4; +let fixedValue = 4; // Only change code below this line -function incrementer () { +function incrementer() { // Only change code above this line @@ -66,15 +66,9 @@ function incrementer () { # --solutions-- ```js -// The global variable -var fixedValue = 4; +let fixedValue = 4; -// Only change code below this line -function incrementer (fixedValue) { +function incrementer(fixedValue) { return fixedValue + 1; - - // Only change code above this line } - - ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/remove-elements-from-an-array-using-slice-instead-of-splice.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/remove-elements-from-an-array-using-slice-instead-of-splice.md index b739782b24..021e6b4b21 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/remove-elements-from-an-array-using-slice-instead-of-splice.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/remove-elements-from-an-array-using-slice-instead-of-splice.md @@ -11,7 +11,7 @@ dashedName: remove-elements-from-an-array-using-slice-instead-of-splice 使用數組時經常遇到要刪除一些元素並保留數組剩餘部分的情況。 爲此,JavaScript 提供了 `splice` 方法,它接收兩個參數:從哪裏開始刪除項目的索引,和要刪除的項目數。 如果沒有提供第二個參數,默認情況下是移除一直到結尾的所有元素。 但 `splice` 方法會改變調用它的原始數組。 舉個例子: ```js -var cities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"]; +const cities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"]; cities.splice(3, 1); ``` @@ -69,7 +69,8 @@ function nonMutatingSplice(cities) { // Only change code above this line } -var inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"]; + +const inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"]; nonMutatingSplice(inputCities); ``` @@ -77,10 +78,7 @@ nonMutatingSplice(inputCities); ```js function nonMutatingSplice(cities) { - // Only change code below this line return cities.slice(0,3); - // Only change code above this line } -var inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"]; -nonMutatingSplice(inputCities); +const inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"]; ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/return-a-sorted-array-without-changing-the-original-array.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/return-a-sorted-array-without-changing-the-original-array.md index d8aed83b75..f4da66801d 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/return-a-sorted-array-without-changing-the-original-array.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/return-a-sorted-array-without-changing-the-original-array.md @@ -68,24 +68,23 @@ assert(JSON.stringify(nonMutatingSort([140000, 104, 99])) === ## --seed-contents-- ```js -var globalArray = [5, 6, 3, 2, 9]; +const globalArray = [5, 6, 3, 2, 9]; + function nonMutatingSort(arr) { // Only change code below this line // Only change code above this line } + nonMutatingSort(globalArray); ``` # --solutions-- ```js -var globalArray = [5, 6, 3, 2, 9]; +const globalArray = [5, 6, 3, 2, 9]; function nonMutatingSort(arr) { - // Only change code below this line return [].concat(arr).sort((a,b) => a-b); - // Only change code above this line } -nonMutatingSort(globalArray); ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/return-part-of-an-array-using-the-slice-method.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/return-part-of-an-array-using-the-slice-method.md index 4f2bc17be2..e096a3d94a 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/return-part-of-an-array-using-the-slice-method.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/return-part-of-an-array-using-the-slice-method.md @@ -13,8 +13,8 @@ dashedName: return-part-of-an-array-using-the-slice-method 舉個例子: ```js -var arr = ["Cat", "Dog", "Tiger", "Zebra"]; -var newArray = arr.slice(1, 3); +const arr = ["Cat", "Dog", "Tiger", "Zebra"]; +const newArray = arr.slice(1, 3); ``` `newArray` 值爲 `["Dog", "Tiger"]` @@ -78,7 +78,8 @@ function sliceArray(anim, beginSlice, endSlice) { // Only change code above this line } -var inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"]; + +const inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"]; sliceArray(inputAnim, 1, 3); ``` @@ -86,10 +87,7 @@ sliceArray(inputAnim, 1, 3); ```js function sliceArray(anim, beginSlice, endSlice) { - // Only change code below this line - return anim.slice(beginSlice, endSlice) - // Only change code above this line + return anim.slice(beginSlice, endSlice); } -var inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"]; -sliceArray(inputAnim, 1, 3); +const inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"]; ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/sort-an-array-alphabetically-using-the-sort-method.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/sort-an-array-alphabetically-using-the-sort-method.md index 81fe51f009..cf6eedde99 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/sort-an-array-alphabetically-using-the-sort-method.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/sort-an-array-alphabetically-using-the-sort-method.md @@ -18,6 +18,7 @@ function ascendingOrder(arr) { return a - b; }); } + ascendingOrder([1, 5, 2, 3, 4]); ``` @@ -29,6 +30,7 @@ function reverseAlpha(arr) { return a === b ? 0 : a < b ? 1 : -1; }); } + reverseAlpha(['l', 'h', 'z', 'b', 's']); ``` @@ -86,6 +88,7 @@ function alphabeticalOrder(arr) { return arr // Only change code above this line } + alphabeticalOrder(["a", "d", "c", "a", "z", "g"]); ``` @@ -93,9 +96,6 @@ alphabeticalOrder(["a", "d", "c", "a", "z", "g"]); ```js function alphabeticalOrder(arr) { - // Only change code below this line return arr.sort(); - // Only change code above this line } -alphabeticalOrder(["a", "d", "c", "a", "z", "g"]); ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/split-a-string-into-an-array-using-the-split-method.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/split-a-string-into-an-array-using-the-split-method.md index f7fd1cfc07..1aba206b00 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/split-a-string-into-an-array-using-the-split-method.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/split-a-string-into-an-array-using-the-split-method.md @@ -13,11 +13,11 @@ dashedName: split-a-string-into-an-array-using-the-split-method 下面是兩個用空格分隔一個字符串的例子,另一個是用數字的正則表達式分隔: ```js -var str = "Hello World"; -var bySpace = str.split(" "); +const str = "Hello World"; +const bySpace = str.split(" "); -var otherString = "How9are7you2today"; -var byDigits = otherString.split(/\d/); +const otherString = "How9are7you2today"; +const byDigits = otherString.split(/\d/); ``` `bySpace` 將有值 `["Hello", "World"]`,`byDigits` 將有值 `["How", "are", "you", "today"]`。 @@ -74,6 +74,7 @@ function splitify(str) { // Only change code above this line } + splitify("Hello World,I-am code"); ``` @@ -81,8 +82,6 @@ splitify("Hello World,I-am code"); ```js function splitify(str) { - // Only change code below this line return str.split(/\W/); - // Only change code above this line } ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/understand-the-hazards-of-using-imperative-code.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/understand-the-hazards-of-using-imperative-code.md index 86fdcb5998..f84d095601 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/understand-the-hazards-of-using-imperative-code.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/understand-the-hazards-of-using-imperative-code.md @@ -59,29 +59,29 @@ assert.deepEqual(finalTabs.tabs, [ ```js // tabs is an array of titles of each site open within the window -var Window = function(tabs) { +const Window = function(tabs) { this.tabs = tabs; // We keep a record of the array inside the object }; // When you join two windows into one window -Window.prototype.join = function (otherWindow) { +Window.prototype.join = function(otherWindow) { this.tabs = this.tabs.concat(otherWindow.tabs); return this; }; // When you open a new tab at the end -Window.prototype.tabOpen = function (tab) { +Window.prototype.tabOpen = function(tab) { this.tabs.push('new tab'); // Let's open a new tab for now return this; }; // When you close a tab -Window.prototype.tabClose = function (index) { +Window.prototype.tabClose = function(index) { // Only change code below this line - var tabsBeforeIndex = this.tabs.splice(0, index); // Get the tabs before the tab - var tabsAfterIndex = this.tabs.splice(index + 1); // Get the tabs after the tab + const tabsBeforeIndex = this.tabs.splice(0, index); // Get the tabs before the tab + const tabsAfterIndex = this.tabs.splice(index + 1); // Get the tabs after the tab this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // Join them together @@ -91,12 +91,12 @@ Window.prototype.tabClose = function (index) { }; // Let's create three browser windows -var workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); // Your mailbox, drive, and other work sites -var socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); // Social sites -var videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); // Entertainment sites +const workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); // Your mailbox, drive, and other work sites +const socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); // Social sites +const videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); // Entertainment sites // Now perform the tab opening, closing, and other operations -var finalTabs = socialWindow +const finalTabs = socialWindow .tabOpen() // Open a new tab for cat memes .join(videoWindow.tabClose(2)) // Close third tab in video window, and join .join(workWindow.tabClose(1).tabOpen()); @@ -106,40 +106,34 @@ console.log(finalTabs.tabs); # --solutions-- ```js -// tabs is an array of titles of each site open within the window -var Window = function(tabs) { - this.tabs = tabs; // We keep a record of the array inside the object +const Window = function(tabs) { + this.tabs = tabs; }; -// When you join two windows into one window -Window.prototype.join = function (otherWindow) { +Window.prototype.join = function(otherWindow) { this.tabs = this.tabs.concat(otherWindow.tabs); return this; }; -// When you open a new tab at the end -Window.prototype.tabOpen = function (tab) { - this.tabs.push('new tab'); // Let's open a new tab for now +Window.prototype.tabOpen = function(tab) { + this.tabs.push('new tab'); return this; }; -// When you close a tab -Window.prototype.tabClose = function (index) { - var tabsBeforeIndex = this.tabs.slice(0, index); // Get the tabs before the tab - var tabsAfterIndex = this.tabs.slice(index + 1); // Get the tabs after the tab +Window.prototype.tabClose = function(index) { + const tabsBeforeIndex = this.tabs.slice(0, index); + const tabsAfterIndex = this.tabs.slice(index + 1); - this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // Join them together + this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); return this; }; -// Let's create three browser windows -var workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); // Your mailbox, drive, and other work sites -var socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); // Social sites -var videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); // Entertainment sites +const workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); +const socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); +const videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); -// Now perform the tab opening, closing, and other operations -var finalTabs = socialWindow - .tabOpen() // Open a new tab for cat memes - .join(videoWindow.tabClose(2)) // Close third tab in video window, and join +const finalTabs = socialWindow + .tabOpen() + .join(videoWindow.tabClose(2)) .join(workWindow.tabClose(1).tabOpen()); ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria.md index 1cf1fad926..8de8e231b8 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria.md @@ -13,7 +13,8 @@ dashedName: use-the-every-method-to-check-that-every-element-in-an-array-meets-a 舉個例子,下面的代碼檢測數組 `numbers` 的所有元素是否都小於 10: ```js -var numbers = [1, 5, 8, 0, 10, 11]; +const numbers = [1, 5, 8, 0, 10, 11]; + numbers.every(function(currentValue) { return currentValue < 10; }); @@ -62,6 +63,7 @@ function checkPositive(arr) { // Only change code above this line } + checkPositive([1, 2, 3, -4, 5]); ``` @@ -69,9 +71,6 @@ checkPositive([1, 2, 3, -4, 5]); ```js function checkPositive(arr) { - // Only change code below this line return arr.every(num => num > 0); - // Only change code above this line } -checkPositive([1, 2, 3, -4, 5]); ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/use-the-reduce-method-to-analyze-data.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/use-the-reduce-method-to-analyze-data.md index eda4082cfb..c0a6bb9b8b 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/use-the-reduce-method-to-analyze-data.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/use-the-reduce-method-to-analyze-data.md @@ -93,7 +93,7 @@ assert(getRating(watchList.filter((_, i) => i < 1 || i > 2)) === 8.55); ```js // The global variable -var watchList = [ +const watchList = [ { "Title": "Inception", "Year": "2010", @@ -206,22 +206,22 @@ var watchList = [ } ]; -function getRating(watchList){ +function getRating(watchList) { // Only change code below this line - var averageRating; + let averageRating; // Only change code above this line return averageRating; } + console.log(getRating(watchList)); ``` # --solutions-- ```js -// The global variable -var watchList = [ +const watchList = [ { "Title": "Inception", "Year": "2010", @@ -334,8 +334,8 @@ var watchList = [ } ]; -function getRating(watchList){ - var averageRating; +function getRating(watchList) { + let averageRating; const rating = watchList .filter(obj => obj.Director === "Christopher Nolan") .map(obj => Number(obj.imdbRating)); diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/use-the-some-method-to-check-that-any-elements-in-an-array-meet-a-criteria.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/use-the-some-method-to-check-that-any-elements-in-an-array-meet-a-criteria.md index 47ab582cfb..ed2c5c9b4d 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/use-the-some-method-to-check-that-any-elements-in-an-array-meet-a-criteria.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/functional-programming/use-the-some-method-to-check-that-any-elements-in-an-array-meet-a-criteria.md @@ -13,7 +13,8 @@ dashedName: use-the-some-method-to-check-that-any-elements-in-an-array-meet-a-cr 舉個例子,下面的代碼檢測數組`numbers`中是否有元素小於 10: ```js -var numbers = [10, 50, 8, 220, 110, 11]; +const numbers = [10, 50, 8, 220, 110, 11]; + numbers.some(function(currentValue) { return currentValue < 10; }); @@ -62,6 +63,7 @@ function checkPositive(arr) { // Only change code above this line } + checkPositive([1, 2, 3, -4, 5]); ``` @@ -69,9 +71,6 @@ checkPositive([1, 2, 3, -4, 5]); ```js function checkPositive(arr) { - // Only change code below this line return arr.some(elem => elem > 0); - // Only change code above this line } -checkPositive([1, 2, 3, -4, 5]); ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays.md index 24c0a00232..7e65e01cab 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays.md @@ -157,7 +157,7 @@ assert(diffArray([1, 'calf', 3, 'piglet'], [7, 'filly']).length === 6); ```js function diffArray(arr1, arr2) { - var newArr = []; + const newArr = []; return newArr; } @@ -168,13 +168,12 @@ diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]); ```js function diffArray(arr1, arr2) { - var newArr = []; - var h1 = Object.create(null); + const newArr = []; + const h1 = Object.create(null); arr1.forEach(function(e) { h1[e] = e; }); - - var h2 = Object.create(null); + const h2 = Object.create(null); arr2.forEach(function(e) { h2[e] = e; }); diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/make-a-person.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/make-a-person.md index 6110cd3116..08d60e17b9 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/make-a-person.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/make-a-person.md @@ -148,7 +148,7 @@ if(bob){ ## --seed-contents-- ```js -var Person = function(firstAndLast) { +const Person = function(firstAndLast) { // Only change code below this line // Complete the method below and implement the others similarly this.getFullName = function() { @@ -157,16 +157,16 @@ var Person = function(firstAndLast) { return firstAndLast; }; -var bob = new Person('Bob Ross'); +const bob = new Person('Bob Ross'); bob.getFullName(); ``` # --solutions-- ```js -var Person = function(firstAndLast) { +const Person = function(firstAndLast) { - var firstName, lastName; + let firstName, lastName; function updateName(str) { firstName = str.split(" ")[0]; @@ -201,6 +201,6 @@ var Person = function(firstAndLast) { }; }; -var bob = new Person('Bob Ross'); +const bob = new Person('Bob Ross'); bob.getFullName(); ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/map-the-debris.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/map-the-debris.md index 47eca19915..821ecee1b1 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/map-the-debris.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/map-the-debris.md @@ -51,8 +51,8 @@ assert.deepEqual( ```js function orbitalPeriod(arr) { - var GM = 398600.4418; - var earthRadius = 6367.4447; + const GM = 398600.4418; + const earthRadius = 6367.4447; return arr; } @@ -63,9 +63,9 @@ orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]); ```js function orbitalPeriod(arr) { - var GM = 398600.4418; - var earthRadius = 6367.4447; - var TAU = 2 * Math.PI; + const GM = 398600.4418; + const earthRadius = 6367.4447; + const TAU = 2 * Math.PI; return arr.map(function(obj) { return { name: obj.name, @@ -73,6 +73,4 @@ function orbitalPeriod(arr) { }; }); } - -orbitalPeriod([{name : "sputkin", avgAlt : 35873.5553}]); ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple.md index 62fc10e71e..4dae74b41f 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple.md @@ -61,7 +61,6 @@ function smallestCommons(arr) { return arr; } - smallestCommons([1,5]); ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou.md index 8eef2dc2a1..5d956b6180 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou.md @@ -103,7 +103,7 @@ assert.deepEqual( ```js function whatIsInAName(collection, source) { - var arr = []; + const arr = []; // Only change code below this line @@ -118,8 +118,8 @@ whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: ```js function whatIsInAName(collection, source) { - var arr = []; - var keys = Object.keys(source); + const arr = []; + const keys = Object.keys(source); collection.forEach(function(e) { if(keys.every(function(key) {return e[key] === source[key];})) { arr.push(e); diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/caesars-cipher.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/caesars-cipher.md index 0348981cd0..95ec7c7777 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/caesars-cipher.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/caesars-cipher.md @@ -51,7 +51,6 @@ assert( ```js function rot13(str) { - return str; } diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/cash-register.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/cash-register.md index ae714a7516..2bf9d2d76c 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/cash-register.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/cash-register.md @@ -186,7 +186,7 @@ assert.deepEqual( ```js function checkCashRegister(price, cash, cid) { - var change; + let change; return change; } @@ -196,54 +196,57 @@ checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], [ # --solutions-- ```js -var denom = [ - { name: 'ONE HUNDRED', val: 100}, - { name: 'TWENTY', val: 20}, - { name: 'TEN', val: 10}, - { name: 'FIVE', val: 5}, - { name: 'ONE', val: 1}, - { name: 'QUARTER', val: 0.25}, - { name: 'DIME', val: 0.1}, - { name: 'NICKEL', val: 0.05}, - { name: 'PENNY', val: 0.01} +const denom = [ + { name: "ONE HUNDRED", val: 100 }, + { name: "TWENTY", val: 20 }, + { name: "TEN", val: 10 }, + { name: "FIVE", val: 5 }, + { name: "ONE", val: 1 }, + { name: "QUARTER", val: 0.25 }, + { name: "DIME", val: 0.1 }, + { name: "NICKEL", val: 0.05 }, + { name: "PENNY", val: 0.01 }, ]; function checkCashRegister(price, cash, cid) { - var output = {status: null, change: []}; - var change = cash - price; - var register = cid.reduce(function(acc, curr) { - acc.total += curr[1]; - acc[curr[0]] = curr[1]; - return acc; - }, {total: 0}); - if(register.total === change) { - output.status = 'CLOSED'; - output.change = cid; - return output; - } - if(register.total < change) { - output.status = 'INSUFFICIENT_FUNDS'; - return output; - } - var change_arr = denom.reduce(function(acc, curr) { - var value = 0; - while(register[curr.name] > 0 && change >= curr.val) { - change -= curr.val; - register[curr.name] -= curr.val; - value += curr.val; - change = Math.round(change * 100) / 100; - } - if(value > 0) { - acc.push([ curr.name, value ]); - } - return acc; - }, []); - if(change_arr.length < 1 || change > 0) { - output.status = 'INSUFFICIENT_FUNDS'; - return output; - } - output.status = 'OPEN'; - output.change = change_arr; - return output; + const output = { status: null, change: [] }; + let change = cash - price; + const register = cid.reduce( + function (acc, curr) { + acc.total += curr[1]; + acc[curr[0]] = curr[1]; + return acc; + }, + { total: 0 } + ); + if (register.total === change) { + output.status = "CLOSED"; + output.change = cid; + return output; + } + if (register.total < change) { + output.status = "INSUFFICIENT_FUNDS"; + return output; + } + const change_arr = denom.reduce(function (acc, curr) { + let value = 0; + while (register[curr.name] > 0 && change >= curr.val) { + change -= curr.val; + register[curr.name] -= curr.val; + value += curr.val; + change = Math.round(change * 100) / 100; + } + if (value > 0) { + acc.push([curr.name, value]); + } + return acc; + }, []); + if (change_arr.length < 1 || change > 0) { + output.status = "INSUFFICIENT_FUNDS"; + return output; + } + output.status = "OPEN"; + output.change = change_arr; + return output; } ``` diff --git a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/palindrome-checker.md b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/palindrome-checker.md index 75fbd433a3..df93db6b18 100644 --- a/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/palindrome-checker.md +++ b/curriculum/challenges/chinese-traditional/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/palindrome-checker.md @@ -107,8 +107,6 @@ function palindrome(str) { return true; } - - palindrome("eye"); ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/access-array-data-with-indexes.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/access-array-data-with-indexes.md index ff44d0b7de..49d0771b12 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/access-array-data-with-indexes.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/access-array-data-with-indexes.md @@ -18,9 +18,9 @@ dashedName: access-array-data-with-indexes **示例** ```js -var array = [50,60,70]; +const array = [50, 60, 70]; array[0]; -var data = array[1]; +const data = array[1]; ``` 现在 `array[0]` 的值是 `50`, `data` 的值为 `60`. @@ -76,7 +76,7 @@ if(typeof myArray !== "undefined" && typeof myData !== "undefined"){(function(y, ## --seed-contents-- ```js -var myArray = [50,60,70]; +const myArray = [50, 60, 70]; ``` @@ -84,6 +84,6 @@ var myArray = [50,60,70]; # --solutions-- ```js -var myArray = [50,60,70]; -var myData = myArray[0]; +const myArray = [50, 60, 70]; +const myData = myArray[0]; ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/access-multi-dimensional-arrays-with-indexes.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/access-multi-dimensional-arrays-with-indexes.md index 4c81c928bb..f59a45b575 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/access-multi-dimensional-arrays-with-indexes.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/access-multi-dimensional-arrays-with-indexes.md @@ -14,12 +14,13 @@ dashedName: access-multi-dimensional-arrays-with-indexes **例如:** ```js -var arr = [ - [1,2,3], - [4,5,6], - [7,8,9], - [[10,11,12], 13, 14] +const arr = [ + [1, 2, 3], + [4, 5, 6], + [7, 8, 9], + [[10, 11, 12], 13, 14] ]; + arr[3]; arr[3][0]; arr[3][0][1]; @@ -58,14 +59,19 @@ if(typeof myArray !== "undefined"){(function(){return "myData: " + myData + " my ## --seed-contents-- ```js -var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]]; +const myArray = [ + [1, 2, 3], + [4, 5, 6], + [7, 8, 9], + [[10, 11, 12], 13, 14], +]; -var myData = myArray[0][0]; +const myData = myArray[0][0]; ``` # --solutions-- ```js -var myArray = [[1,2,3],[4,5,6], [7,8,9], [[10,11,12], 13, 14]]; -var myData = myArray[2][1]; +const myArray = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [[10, 11, 12], 13, 14]]; +const myData = myArray[2][1]; ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-arrays.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-arrays.md index 5bc88691fa..d1fd1a4a5e 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-arrays.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-arrays.md @@ -14,7 +14,7 @@ dashedName: accessing-nested-arrays 下面是访问嵌套数组的例子: ```js -var ourPets = [ +const ourPets = [ { animalType: "cat", names: [ @@ -32,6 +32,7 @@ var ourPets = [ ] } ]; + ourPets[0].names[1]; ourPets[1].names[0]; ``` @@ -72,7 +73,7 @@ assert(/=\s*myPlants\[1\].list\[1\]/.test(code)); ## --seed-contents-- ```js -var myPlants = [ +const myPlants = [ { type: "flowers", list: [ @@ -91,13 +92,13 @@ var myPlants = [ } ]; -var secondTree = ""; +const secondTree = ""; ``` # --solutions-- ```js -var myPlants = [ +const myPlants = [ { type: "flowers", list: [ @@ -116,5 +117,5 @@ var myPlants = [ } ]; -var secondTree = myPlants[1].list[1]; +const secondTree = myPlants[1].list[1]; ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-objects.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-objects.md index e790e3eabd..b8ef650adf 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-objects.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-objects.md @@ -14,7 +14,7 @@ dashedName: accessing-nested-objects 这是一个嵌套对象: ```js -var ourStorage = { +const ourStorage = { "desk": { "drawer": "stapler" }, @@ -26,6 +26,7 @@ var ourStorage = { "bottom drawer": "soda" } }; + ourStorage.cabinet["top drawer"].folder2; ourStorage.desk.drawer; ``` @@ -66,7 +67,7 @@ assert(/=\s*myStorage\.car\.inside\[\s*("|')glove box\1\s*\]/g.test(code)); ## --seed-contents-- ```js -var myStorage = { +const myStorage = { "car": { "inside": { "glove box": "maps", @@ -78,13 +79,13 @@ var myStorage = { } }; -var gloveBoxContents = undefined; +const gloveBoxContents = undefined; ``` # --solutions-- ```js -var myStorage = { +const myStorage = { "car":{ "inside":{ "glove box":"maps", @@ -95,5 +96,5 @@ var myStorage = { } } }; -var gloveBoxContents = myStorage.car.inside["glove box"]; +const gloveBoxContents = myStorage.car.inside["glove box"]; ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-bracket-notation.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-bracket-notation.md index db05692570..043f2e84b2 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-bracket-notation.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-bracket-notation.md @@ -16,11 +16,12 @@ dashedName: accessing-object-properties-with-bracket-notation 这是一个使用方括号表示法读取对象属性的例子: ```js -var myObj = { +const myObj = { "Space Name": "Kirk", "More Space": "Spock", "NoSpace": "USS Enterprise" }; + myObj["Space Name"]; myObj['More Space']; myObj["NoSpace"]; @@ -78,26 +79,25 @@ assert(code.match(/testObj\s*?\[('|")[^'"]+\1\]/g).length > 1); ```js // Setup -var testObj = { +const testObj = { "an entree": "hamburger", "my side": "veggies", "the drink": "water" }; // Only change code below this line - -var entreeValue = testObj; // Change this line -var drinkValue = testObj; // Change this line +const entreeValue = testObj; // Change this line +const drinkValue = testObj; // Change this line ``` # --solutions-- ```js -var testObj = { +const testObj = { "an entree": "hamburger", "my side": "veggies", "the drink": "water" }; -var entreeValue = testObj["an entree"]; -var drinkValue = testObj['the drink']; +const entreeValue = testObj["an entree"]; +const drinkValue = testObj['the drink']; ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-dot-notation.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-dot-notation.md index d5663a178b..f422d74a7e 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-dot-notation.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-dot-notation.md @@ -16,15 +16,17 @@ dashedName: accessing-object-properties-with-dot-notation 这里是一个用点符号(`.`)读取对象属性的示例: ```js -var myObj = { +const myObj = { prop1: "val1", prop2: "val2" }; -var prop1val = myObj.prop1; -var prop2val = myObj.prop2; + +const prop1val = myObj.prop1; +const prop2val = myObj.prop2; ``` `prop1val` 的值将为字符串 `val1`,并且`prop2val` 的值将为字符串 `val2`。 + # --instructions-- 使用点号读取 `testObj` 的属性值。 将变量 `hatValue` 的值设置为该对象的 `hat` 属性的值,并将变量 `shirtValue` 的值设置为该对象的 `shirt` 属性的值。 @@ -73,27 +75,26 @@ assert(code.match(/testObj\.\w+/g).length > 1); ```js // Setup -var testObj = { +const testObj = { "hat": "ballcap", "shirt": "jersey", "shoes": "cleats" }; // Only change code below this line - -var hatValue = testObj; // Change this line -var shirtValue = testObj; // Change this line +const hatValue = testObj; // Change this line +const shirtValue = testObj; // Change this line ``` # --solutions-- ```js -var testObj = { +const testObj = { "hat": "ballcap", "shirt": "jersey", "shoes": "cleats" }; -var hatValue = testObj.hat; -var shirtValue = testObj.shirt; +const hatValue = testObj.hat; +const shirtValue = testObj.shirt; ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-variables.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-variables.md index 728d5170ac..229bb20962 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-variables.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-variables.md @@ -14,11 +14,14 @@ dashedName: accessing-object-properties-with-variables 以下是一个使用变量来访问属性的例子: ```js -var dogs = { - Fido: "Mutt", Hunter: "Doberman", Snoopie: "Beagle" +const dogs = { + Fido: "Mutt", + Hunter: "Doberman", + Snoopie: "Beagle" }; -var myDog = "Hunter"; -var myBreed = dogs[myDog]; + +const myDog = "Hunter"; +const myBreed = dogs[myDog]; console.log(myBreed); ``` @@ -27,14 +30,16 @@ console.log(myBreed); 使用这一概念的另一种情况是:属性的名字是在程序运行期间动态收集得到的。如下所示: ```js -var someObj = { +const someObj = { propName: "John" }; + function propPrefix(str) { - var s = "prop"; + const s = "prop"; return s + str; } -var someProp = propPrefix("Name"); + +const someProp = propPrefix("Name"); console.log(someObj[someProp]); ``` @@ -96,26 +101,25 @@ if(typeof player !== "undefined"){(function(v){return v;})(player);} ```js // Setup -var testObj = { +const testObj = { 12: "Namath", 16: "Montana", 19: "Unitas" }; // Only change code below this line - -var playerNumber; // Change this line -var player = testObj; // Change this line +const playerNumber = 42; // Change this line +const player = testObj; // Change this line ``` # --solutions-- ```js -var testObj = { +const testObj = { 12: "Namath", 16: "Montana", 19: "Unitas" }; -var playerNumber = 16; -var player = testObj[playerNumber]; +const playerNumber = 16; +const player = testObj[playerNumber]; ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/add-new-properties-to-a-javascript-object.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/add-new-properties-to-a-javascript-object.md index 8657efc29d..1cb9728b5d 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/add-new-properties-to-a-javascript-object.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/add-new-properties-to-a-javascript-object.md @@ -28,7 +28,7 @@ ourDog["bark"] = "bow-wow"; 例如: ```js -var ourDog = { +const ourDog = { "name": "Camper", "legs": 4, "tails": 1, @@ -67,7 +67,7 @@ assert(!/bark[^\n]:/.test(code)); ## --seed-contents-- ```js -var myDog = { +const myDog = { "name": "Happy Coder", "legs": 4, "tails": 1, @@ -80,7 +80,7 @@ var myDog = { # --solutions-- ```js -var myDog = { +const myDog = { "name": "Happy Coder", "legs": 4, "tails": 1, diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/add-two-numbers-with-javascript.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/add-two-numbers-with-javascript.md index af90b54023..b8e5d7b0b3 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/add-two-numbers-with-javascript.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/add-two-numbers-with-javascript.md @@ -18,7 +18,7 @@ JavaScript 中,我们通过符号 `+` 来进行加法运算。 **代码示例:** ```js -myVar = 5 + 10; +const myVar = 5 + 10; ``` 现在,变量 `myVar` 的值为 `15`。 @@ -52,11 +52,11 @@ assert(/\+/.test(code)); ## --seed-contents-- ```js -var sum = 10 + 0; +const sum = 10 + 0; ``` # --solutions-- ```js -var sum = 10 + 10; +const sum = 10 + 10; ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/adding-a-default-option-in-switch-statements.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/adding-a-default-option-in-switch-statements.md index 98dba35fbd..565dd14f8a 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/adding-a-default-option-in-switch-statements.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/adding-a-default-option-in-switch-statements.md @@ -92,7 +92,7 @@ assert(code.match(/break/g).length > 2); ```js function switchOfStuff(val) { - var answer = ""; + let answer = ""; // Only change code below this line @@ -108,7 +108,7 @@ switchOfStuff(1); ```js function switchOfStuff(val) { - var answer = ""; + let answer = ""; switch(val) { case "a": diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/appending-variables-to-strings.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/appending-variables-to-strings.md index 0795af9b46..9d668d14f8 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/appending-variables-to-strings.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/appending-variables-to-strings.md @@ -14,8 +14,8 @@ dashedName: appending-variables-to-strings 示例: ```js -var anAdjective = "awesome!"; -var ourStr = "freeCodeCamp is "; +const anAdjective = "awesome!"; +let ourStr = "freeCodeCamp is "; ourStr += anAdjective; ``` @@ -64,15 +64,14 @@ assert(code.match(/myStr\s*\+=\s*someAdjective\s*/).length > 0); ```js // Change code below this line - -var someAdjective; -var myStr = "Learning to code is "; +const someAdjective = ""; +let myStr = "Learning to code is "; ``` # --solutions-- ```js -var someAdjective = "neat"; -var myStr = "Learning to code is "; +const someAdjective = "neat"; +let myStr = "Learning to code is "; myStr += someAdjective; ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/build-javascript-objects.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/build-javascript-objects.md index f918c4e796..0924328150 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/build-javascript-objects.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/build-javascript-objects.md @@ -18,7 +18,7 @@ dashedName: build-javascript-objects 这里是一个猫对象的样本: ```js -var cat = { +const cat = { "name": "Whiskers", "legs": 4, "tails": 1, @@ -29,7 +29,7 @@ var cat = { 在此示例中,所有属性都存储为字符串,例如 `name`、`legs` 和 `tails`。 然而,你也可以使用数字作为属性。 你甚至可以省略单字字符串属性中的引号,如下所示: ```js -var anotherObject = { +const anotherObject = { make: "Ford", 5: "five", "model": "focus" @@ -139,18 +139,18 @@ assert( ## --seed-contents-- ```js -var myDog = { -// Only change code below this line +const myDog = { + // Only change code below this line -// Only change code above this line + // Only change code above this line }; ``` # --solutions-- ```js -var myDog = { +const myDog = { "name": "Camper", "legs": 4, "tails": 1, diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-equality-operator.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-equality-operator.md index 8e15f96ca2..2d3e0f6c31 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-equality-operator.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-equality-operator.md @@ -16,7 +16,7 @@ dashedName: comparison-with-the-equality-operator ```js function equalityTest(myVal) { if (myVal == 10) { - return "Equal"; + return "Equal"; } return "Not Equal"; } diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-addition.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-addition.md index ba6834c0a0..fcf6734669 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-addition.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-addition.md @@ -20,7 +20,7 @@ myVar = myVar + 5; 其中一种就是 `+=` 运算符。 ```js -var myVar = 1; +let myVar = 1; myVar += 5; console.log(myVar); ``` @@ -61,9 +61,9 @@ assert(code.match(/\+=/g).length === 3); ```js assert( - /var a = 3;/.test(code) && - /var b = 17;/.test(code) && - /var c = 12;/.test(code) + /let a = 3;/.test(code) && + /let b = 17;/.test(code) && + /let c = 12;/.test(code) ); ``` @@ -78,9 +78,9 @@ assert( ## --seed-contents-- ```js -var a = 3; -var b = 17; -var c = 12; +let a = 3; +let b = 17; +let c = 12; // Only change code below this line a = a + 12; @@ -91,9 +91,9 @@ c = c + 7; # --solutions-- ```js -var a = 3; -var b = 17; -var c = 12; +let a = 3; +let b = 17; +let c = 12; a += 12; b += 9; diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-division.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-division.md index c84fb70b71..4d79833dcd 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-division.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-division.md @@ -55,9 +55,9 @@ assert(code.match(/\/=/g).length === 3); ```js assert( - /var a = 48;/.test(code) && - /var b = 108;/.test(code) && - /var c = 33;/.test(code) + /let a = 48;/.test(code) && + /let b = 108;/.test(code) && + /let c = 33;/.test(code) ); ``` @@ -72,9 +72,9 @@ assert( ## --seed-contents-- ```js -var a = 48; -var b = 108; -var c = 33; +let a = 48; +let b = 108; +let c = 33; // Only change code below this line a = a / 12; @@ -85,9 +85,9 @@ c = c / 11; # --solutions-- ```js -var a = 48; -var b = 108; -var c = 33; +let a = 48; +let b = 108; +let c = 33; a /= 12; b /= 4; diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-multiplication.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-multiplication.md index 38415e0189..96165f198e 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-multiplication.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-multiplication.md @@ -55,9 +55,9 @@ assert(code.match(/\*=/g).length === 3); ```js assert( - /var a = 5;/.test(code) && - /var b = 12;/.test(code) && - /var c = 4\.6;/.test(code) + /let a = 5;/.test(code) && + /let b = 12;/.test(code) && + /let c = 4\.6;/.test(code) ); ``` @@ -72,9 +72,9 @@ assert( ## --seed-contents-- ```js -var a = 5; -var b = 12; -var c = 4.6; +let a = 5; +let b = 12; +let c = 4.6; // Only change code below this line a = a * 5; @@ -85,9 +85,9 @@ c = c * 10; # --solutions-- ```js -var a = 5; -var b = 12; -var c = 4.6; +let a = 5; +let b = 12; +let c = 4.6; a *= 5; b *= 3; diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-subtraction.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-subtraction.md index b80f278e2f..79ab231e71 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-subtraction.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-subtraction.md @@ -55,7 +55,7 @@ assert(code.match(/-=/g).length === 3); ```js assert( - /var a = 11;/.test(code) && /var b = 9;/.test(code) && /var c = 3;/.test(code) + /let a = 11;/.test(code) && /let b = 9;/.test(code) && /let c = 3;/.test(code) ); ``` @@ -70,9 +70,9 @@ assert( ## --seed-contents-- ```js -var a = 11; -var b = 9; -var c = 3; +let a = 11; +let b = 9; +let c = 3; // Only change code below this line a = a - 6; @@ -83,9 +83,9 @@ c = c - 1; # --solutions-- ```js -var a = 11; -var b = 9; -var c = 3; +let a = 11; +let b = 9; +let c = 3; a -= 6; b -= 15; diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-the-plus-equals-operator.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-the-plus-equals-operator.md index c5bdd608da..72e538fae1 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-the-plus-equals-operator.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-the-plus-equals-operator.md @@ -16,7 +16,7 @@ dashedName: concatenating-strings-with-the-plus-equals-operator 例如: ```js -var ourStr = "I come first. "; +let ourStr = "I come first. "; ourStr += "I come second."; ``` @@ -57,14 +57,12 @@ assert(code.match(/myStr\s*\+=\s*(["']).*\1/g)); ## --seed-contents-- ```js -// Only change code below this line - -var myStr; +let myStr; ``` # --solutions-- ```js -var myStr = "This is the first sentence. "; +let myStr = "This is the first sentence. "; myStr += "This is the second sentence."; ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/constructing-strings-with-variables.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/constructing-strings-with-variables.md index 9c637cd5f3..1376c03470 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/constructing-strings-with-variables.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/constructing-strings-with-variables.md @@ -14,8 +14,8 @@ dashedName: constructing-strings-with-variables 例如: ```js -var ourName = "freeCodeCamp"; -var ourStr = "Hello, our name is " + ourName + ", how are you?"; +const ourName = "freeCodeCamp"; +const ourStr = "Hello, our name is " + ourName + ", how are you?"; ``` `ourStr` 值为 `Hello, our name is freeCodeCamp, how are you?` @@ -63,13 +63,13 @@ assert(code.match(/["']\s*\+\s*myName\s*\+\s*["']/g).length > 0); ```js // Only change code below this line -var myName; -var myStr; +const myName = ""; +const myStr = ""; ``` # --solutions-- ```js -var myName = "Bob"; -var myStr = "My name is " + myName + " and I am well!"; +const myName = "Bob"; +const myStr = "My name is " + myName + " and I am well!"; ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/counting-cards.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/counting-cards.md index 73674c06cf..2b10dc4500 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/counting-cards.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/counting-cards.md @@ -159,7 +159,7 @@ assert( ## --seed-contents-- ```js -var count = 0; +let count = 0; function cc(card) { // Only change code below this line @@ -175,7 +175,7 @@ cc(2); cc(3); cc(7); cc('K'); cc('A'); # --solutions-- ```js -var count = 0; +let count = 0; function cc(card) { switch(card) { case 2: diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/create-decimal-numbers-with-javascript.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/create-decimal-numbers-with-javascript.md index 147dbfea17..f4a2fd37a7 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/create-decimal-numbers-with-javascript.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/create-decimal-numbers-with-javascript.md @@ -42,13 +42,14 @@ assert(myDecimal % 1 != 0); ## --seed-contents-- ```js -var ourDecimal = 5.7; +const ourDecimal = 5.7; // Only change code below this line + ``` # --solutions-- ```js -var myDecimal = 9.9; +const myDecimal = 9.9; ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/decrement-a-number-with-javascript.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/decrement-a-number-with-javascript.md index 8d431c91cc..6bb66dfee2 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/decrement-a-number-with-javascript.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/decrement-a-number-with-javascript.md @@ -39,7 +39,7 @@ assert(myVar === 10); ```js assert( - /var\s*myVar\s*=\s*11;\s*\/*.*\s*([-]{2}\s*myVar|myVar\s*[-]{2});/.test(code) + /let\s*myVar\s*=\s*11;\s*\/*.*\s*([-]{2}\s*myVar|myVar\s*[-]{2});/.test(code) ); ``` @@ -52,7 +52,7 @@ assert(/[-]{2}\s*myVar|myVar\s*[-]{2}/.test(code)); 不应修改注释上方的代码。 ```js -assert(/var myVar = 11;/.test(code)); +assert(/let myVar = 11;/.test(code)); ``` # --seed-- @@ -66,7 +66,7 @@ assert(/var myVar = 11;/.test(code)); ## --seed-contents-- ```js -var myVar = 11; +let myVar = 11; // Only change code below this line myVar = myVar - 1; @@ -75,6 +75,6 @@ myVar = myVar - 1; # --solutions-- ```js -var myVar = 11; +let myVar = 11; myVar--; ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/delete-properties-from-a-javascript-object.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/delete-properties-from-a-javascript-object.md index ca4daac292..097db448dc 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/delete-properties-from-a-javascript-object.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/delete-properties-from-a-javascript-object.md @@ -18,7 +18,7 @@ delete ourDog.bark; 例如: ```js -var ourDog = { +const ourDog = { "name": "Camper", "legs": 4, "tails": 1, @@ -70,7 +70,7 @@ assert(code.match(/"tails": 1/g).length > 0); ```js // Setup -var myDog = { +const myDog = { "name": "Happy Coder", "legs": 4, "tails": 1, @@ -79,12 +79,13 @@ var myDog = { }; // Only change code below this line + ``` # --solutions-- ```js -var myDog = { +const myDog = { "name": "Happy Coder", "legs": 4, "tails": 1, diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-decimal-by-another-with-javascript.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-decimal-by-another-with-javascript.md index ded89b1d47..f52d89019e 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-decimal-by-another-with-javascript.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-decimal-by-another-with-javascript.md @@ -46,11 +46,11 @@ assert(code.match(/quotient/g).length === 1); ## --seed-contents-- ```js -var quotient = 0.0 / 2.0; // Change this line +const quotient = 0.0 / 2.0; // Change this line ``` # --solutions-- ```js -var quotient = 4.4 / 2.0; +const quotient = 4.4 / 2.0; ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-number-by-another-with-javascript.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-number-by-another-with-javascript.md index ac7f518811..b2700333de 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-number-by-another-with-javascript.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-number-by-another-with-javascript.md @@ -16,7 +16,7 @@ JavaScript 中使用 `/` 符号做除法运算。 **示例** ```js -myVar = 16 / 2; +const myVar = 16 / 2; ``` 现在,变量 `myVar` 的值为 `8`。 @@ -49,11 +49,11 @@ assert(/\d+\s*\/\s*\d+/.test(code)); ## --seed-contents-- ```js -var quotient = 66 / 0; +const quotient = 66 / 0; ``` # --solutions-- ```js -var quotient = 66 / 33; +const quotient = 66 / 33; ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/escape-sequences-in-strings.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/escape-sequences-in-strings.md index 5bfba8d62a..0a19489a0b 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/escape-sequences-in-strings.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/escape-sequences-in-strings.md @@ -89,11 +89,11 @@ console.log('myStr:\n' + myStr);}})(); ## --seed-contents-- ```js -var myStr; // Change this line +const myStr = ""; // Change this line ``` # --solutions-- ```js -var myStr = "FirstLine\n\t\\SecondLine\nThirdLine"; +const myStr = "FirstLine\n\t\\SecondLine\nThirdLine"; ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/escaping-literal-quotes-in-strings.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/escaping-literal-quotes-in-strings.md index a7791d0a9a..12d0718e33 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/escaping-literal-quotes-in-strings.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/escaping-literal-quotes-in-strings.md @@ -14,7 +14,7 @@ dashedName: escaping-literal-quotes-in-strings 在 JavaScript 中,可以通过在引号前面使用反斜杠(`\`)来转义引号。 ```js -var sampleStr = "Alan said, \"Peter is learning JavaScript\"."; +const sampleStr = "Alan said, \"Peter is learning JavaScript\"."; ``` 有了转义符号,JavaScript 就知道这个单引号或双引号并不是字符串的结尾,而是字符串内的字符。 所以,上面的字符串打印到控制台的结果为: @@ -62,11 +62,11 @@ assert(/I am a "double quoted" string inside "double quotes(\."|"\.)$/.test(mySt ## --seed-contents-- ```js -var myStr = ""; // Change this line +const myStr = ""; // Change this line ``` # --solutions-- ```js -var myStr = "I am a \"double quoted\" string inside \"double quotes\"."; +const myStr = "I am a \"double quoted\" string inside \"double quotes\"."; ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/finding-a-remainder-in-javascript.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/finding-a-remainder-in-javascript.md index 4d7a9b7e34..53da52ae6f 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/finding-a-remainder-in-javascript.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/finding-a-remainder-in-javascript.md @@ -31,7 +31,7 @@ dashedName: finding-a-remainder-in-javascript 变量 `remainder` 应该被初始化。 ```js -assert(/var\s+?remainder/.test(code)); +assert(/(const|let|var)\s+?remainder/.test(code)); ``` `remainder` 的值应该等于 `2`。 @@ -57,13 +57,11 @@ assert(/\s+?remainder\s*?=\s*?.*%.*;?/.test(code)); ## --seed-contents-- ```js -// Only change code below this line - -var remainder; +const remainder = 0; ``` # --solutions-- ```js -var remainder = 11 % 3; +const remainder = 11 % 3; ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/global-vs.-local-scope-in-functions.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/global-vs.-local-scope-in-functions.md index c25271e30e..01af4403ed 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/global-vs.-local-scope-in-functions.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/global-vs.-local-scope-in-functions.md @@ -14,9 +14,10 @@ dashedName: global-vs--local-scope-in-functions 下面为例: ```js -var someVar = "Hat"; +const someVar = "Hat"; + function myFun() { - var someVar = "Head"; + const someVar = "Head"; return someVar; } ``` @@ -53,13 +54,11 @@ assert(/return outerWear/.test(code)); ```js // Setup -var outerWear = "T-Shirt"; +const outerWear = "T-Shirt"; function myOutfit() { // Only change code below this line - - // Only change code above this line return outerWear; } @@ -70,9 +69,9 @@ myOutfit(); # --solutions-- ```js -var outerWear = "T-Shirt"; +const outerWear = "T-Shirt"; function myOutfit() { - var outerWear = "sweater"; + const outerWear = "sweater"; return outerWear; } ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/golf-code.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/golf-code.md index a0a37a2ad4..ad741ccb52 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/golf-code.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/golf-code.md @@ -90,7 +90,8 @@ assert(golfScore(5, 9) === 'Go Home!'); ## --seed-contents-- ```js -var names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"]; +const names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"]; + function golfScore(par, strokes) { // Only change code below this line diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/increment-a-number-with-javascript.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/increment-a-number-with-javascript.md index 6dd41ca406..0012e0526a 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/increment-a-number-with-javascript.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/increment-a-number-with-javascript.md @@ -39,7 +39,7 @@ assert(myVar === 88); ```js assert( - /var\s*myVar\s*=\s*87;\s*\/*.*\s*([+]{2}\s*myVar|myVar\s*[+]{2});/.test(code) + /let\s*myVar\s*=\s*87;\s*\/*.*\s*([+]{2}\s*myVar|myVar\s*[+]{2});/.test(code) ); ``` @@ -52,7 +52,7 @@ assert(/[+]{2}\s*myVar|myVar\s*[+]{2}/.test(code)); 不应该修改注释上面的代码。 ```js -assert(/var myVar = 87;/.test(code)); +assert(/let myVar = 87;/.test(code)); ``` # --seed-- @@ -66,7 +66,7 @@ assert(/var myVar = 87;/.test(code)); ## --seed-contents-- ```js -var myVar = 87; +let myVar = 87; // Only change code below this line myVar = myVar + 1; @@ -75,6 +75,6 @@ myVar = myVar + 1; # --solutions-- ```js -var myVar = 87; +let myVar = 87; myVar++; ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/introducing-else-statements.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/introducing-else-statements.md index 3d2d90e45c..db610a9cff 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/introducing-else-statements.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/introducing-else-statements.md @@ -64,7 +64,7 @@ assert(testElse(10) === 'Bigger than 5'); 不要修改相应注释的上面或下面的代码。 ```js -assert(/var result = "";/.test(code) && /return result;/.test(code)); +assert(/let result = "";/.test(code) && /return result;/.test(code)); ``` # --seed-- @@ -73,7 +73,7 @@ assert(/var result = "";/.test(code) && /return result;/.test(code)); ```js function testElse(val) { - var result = ""; + let result = ""; // Only change code below this line if (val > 5) { @@ -95,7 +95,7 @@ testElse(4); ```js function testElse(val) { - var result = ""; + let result = ""; if(val > 5) { result = "Bigger than 5"; } else { diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-through-an-array-with-a-for-loop.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-through-an-array-with-a-for-loop.md index 335f7fcdf3..f01f2b48ea 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-through-an-array-with-a-for-loop.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-through-an-array-with-a-for-loop.md @@ -12,8 +12,9 @@ dashedName: iterate-through-an-array-with-a-for-loop JavaScript 中的一个常见任务是遍历数组的内容。 一种方法是使用 `for` 循环。 下面的代码将输出数组 `arr` 的每个元素到控制台: ```js -var arr = [10, 9, 8, 7, 6]; -for (var i = 0; i < arr.length; i++) { +const arr = [10, 9, 8, 7, 6]; + +for (let i = 0; i < arr.length; i++) { console.log(arr[i]); } ``` @@ -62,18 +63,19 @@ assert(!__helpers.removeWhiteSpace(code).match(/total[=+-]0*[1-9]+/gm)); ```js // Setup -var myArr = [ 2, 3, 4, 5, 6]; +const myArr = [2, 3, 4, 5, 6]; // Only change code below this line + ``` # --solutions-- ```js -var myArr = [ 2, 3, 4, 5, 6]; -var total = 0; +const myArr = [2, 3, 4, 5, 6]; +let total = 0; -for (var i = 0; i < myArr.length; i++) { +for (let i = 0; i < myArr.length; i++) { total += myArr[i]; } ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-do...while-loops.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-do...while-loops.md index 725a66d715..338de20047 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-do...while-loops.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-do...while-loops.md @@ -12,8 +12,9 @@ dashedName: iterate-with-javascript-do---while-loops 下一种循环叫作 `do...while` 循环。 它被称为 `do...while` 循环,是因为不论什么情况,它都会首先 `do`(运行)循环里的第一部分代码,然后 `while`(当)规定的条件被评估为 `true`(真)的时候,它会继续运行循环。 ```js -var ourArray = []; -var i = 0; +const ourArray = []; +let i = 0; + do { ourArray.push(i); i++; @@ -23,8 +24,9 @@ do { 上面的示例行为类似于其他类型的循环,由此产生的数组将看起来像 `[0, 1, 2, 3, 4]`。 然而,`do...while` 不同于其他循环的地方,是第一次循环检查失败时的行为。 让我们看看代码中的区别:这里是一个常规的 `while` 循环,只要 `i < 5`,就会在循环中运行代码: ```js -var ourArray = []; -var i = 5; +const ourArray = []; +let i = 5; + while (i < 5) { ourArray.push(i); i++; @@ -34,8 +36,9 @@ while (i < 5) { 这个例子中,定义了一个空数组 `ourArray` 以及一个值为 5 的 `i` 。 当执行 `while` 循环时,因为 `i` 不小于 5,所以循环条件为 `false`,循环内的代码将不会执行。 `ourArray` 最终没有添加任何内容,因此示例中的所有代码执行完时,ourArray 仍然是`[]`。 现在,看一下 `do...while` 循环。 ```js -var ourArray = []; -var i = 5; +const ourArray = []; +let i = 5; + do { ourArray.push(i); i++; @@ -80,8 +83,8 @@ if(typeof myArray !== "undefined"){(function(){return myArray;})();} ```js // Setup -var myArray = []; -var i = 10; +const myArray = []; +let i = 10; // Only change code below this line while (i < 5) { @@ -93,8 +96,8 @@ while (i < 5) { # --solutions-- ```js -var myArray = []; -var i = 10; +const myArray = []; +let i = 10; do { myArray.push(i); i++; diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/local-scope-and-functions.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/local-scope-and-functions.md index 60caa1a3e7..2c950d2134 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/local-scope-and-functions.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/local-scope-and-functions.md @@ -15,9 +15,10 @@ dashedName: local-scope-and-functions ```js function myTest() { - var loc = "foo"; + const loc = "foo"; console.log(loc); } + myTest(); console.log(loc); ``` @@ -38,6 +39,7 @@ console.log(loc); function declared() { myVar; } + assert.throws(declared, ReferenceError); ``` @@ -57,7 +59,6 @@ assert( ```js function myLocalScope() { - // Only change code below this line console.log('inside myLocalScope', myVar); @@ -73,9 +74,8 @@ console.log('outside myLocalScope', myVar); ```js function myLocalScope() { - // Only change code below this line - var myVar; + let myVar; console.log('inside myLocalScope', myVar); } myLocalScope(); diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-push.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-push.md index 340f78cebb..4e95ec67e7 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-push.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-push.md @@ -16,10 +16,10 @@ dashedName: manipulate-arrays-with-push 示例: ```js -var arr1 = [1,2,3]; +const arr1 = [1, 2, 3]; arr1.push(4); -var arr2 = ["Stimpson", "J", "cat"]; +const arr2 = ["Stimpson", "J", "cat"]; arr2.push(["happy", "joy"]); ``` @@ -64,14 +64,15 @@ assert( ```js // Setup -var myArray = [["John", 23], ["cat", 2]]; +const myArray = [["John", 23], ["cat", 2]]; // Only change code below this line + ``` # --solutions-- ```js -var myArray = [["John", 23], ["cat", 2]]; +const myArray = [["John", 23], ["cat", 2]]; myArray.push(["dog",3]); ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/manipulating-complex-objects.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/manipulating-complex-objects.md index 64f2075f39..d2145515b9 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/manipulating-complex-objects.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/manipulating-complex-objects.md @@ -14,7 +14,7 @@ dashedName: manipulating-complex-objects 这是一个复杂数据结构的示例: ```js -var ourMusic = [ +const ourMusic = [ { "artist": "Daft Punk", "title": "Homework", @@ -135,7 +135,7 @@ myMusic.forEach(object => { ## --seed-contents-- ```js -var myMusic = [ +const myMusic = [ { "artist": "Billy Joel", "title": "Piano Man", @@ -153,7 +153,7 @@ var myMusic = [ # --solutions-- ```js -var myMusic = [ +const myMusic = [ { "artist": "Billy Joel", "title": "Piano Man", diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/multiple-identical-options-in-switch-statements.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/multiple-identical-options-in-switch-statements.md index 0c0b63f9c1..dfe62e3d65 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/multiple-identical-options-in-switch-statements.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/multiple-identical-options-in-switch-statements.md @@ -12,7 +12,7 @@ dashedName: multiple-identical-options-in-switch-statements 如果你忘了给 `switch` 的每一条 `case` 添加 `break`,那么后续的 `case` 会一直执行,直到遇见 `break` 为止。 如果你想为 `switch` 中的多个不同的输入设置相同的结果,可以这样写: ```js -var result = ""; +let result = ""; switch(val) { case 1: case 2: @@ -109,7 +109,7 @@ assert(code.match(/case/g).length === 9); ```js function sequentialSizes(val) { - var answer = ""; + let answer = ""; // Only change code below this line @@ -125,7 +125,7 @@ sequentialSizes(1); ```js function sequentialSizes(val) { - var answer = ""; + let answer = ""; switch(val) { case 1: diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-decimals-with-javascript.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-decimals-with-javascript.md index 31e2ba9e96..a1f6eb7d95 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-decimals-with-javascript.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-decimals-with-javascript.md @@ -42,11 +42,11 @@ assert(/\*/.test(code)); ## --seed-contents-- ```js -var product = 2.0 * 0.0; +const product = 2.0 * 0.0; ``` # --solutions-- ```js -var product = 2.0 * 2.5; +const product = 2.0 * 2.5; ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-numbers-with-javascript.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-numbers-with-javascript.md index 458a8b9294..eff8e13226 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-numbers-with-javascript.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-numbers-with-javascript.md @@ -16,7 +16,7 @@ JavaScript 使用 `*` 符号表示两数相乘。 **示例** ```js -myVar = 13 * 13; +const myVar = 13 * 13; ``` 现在,变量 `myVar` 的值为 `169`。 @@ -50,11 +50,11 @@ assert(/\*/.test(code)); ## --seed-contents-- ```js -var product = 8 * 0; +const product = 8 * 0; ``` # --solutions-- ```js -var product = 8 * 10; +const product = 8 * 10; ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/nest-one-array-within-another-array.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/nest-one-array-within-another-array.md index ac3f1b0fb7..89d74fdd30 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/nest-one-array-within-another-array.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/nest-one-array-within-another-array.md @@ -12,7 +12,7 @@ dashedName: nest-one-array-within-another-array 您也可以在其他数组中嵌套数组,如: ```js -[["Bulls", 23], ["White Sox", 45]] +const teams = [["Bulls", 23], ["White Sox", 45]]; ``` 这也叫做多维数组(multi-dimensional array)。 @@ -41,11 +41,11 @@ if(typeof myArray !== "undefined"){(function(){return myArray;})();} ```js // Only change code below this line -var myArray = []; +const myArray = []; ``` # --solutions-- ```js -var myArray = [[1,2,3]]; +const myArray = [[1, 2, 3]]; ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/profile-lookup.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/profile-lookup.md index 98521e0599..d1018d60eb 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/profile-lookup.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/profile-lookup.md @@ -68,34 +68,33 @@ assert(lookUpProfile('Akira', 'address') === 'No such property'); ```js // Setup -var contacts = [ - { - "firstName": "Akira", - "lastName": "Laine", - "number": "0543236543", - "likes": ["Pizza", "Coding", "Brownie Points"] - }, - { - "firstName": "Harry", - "lastName": "Potter", - "number": "0994372684", - "likes": ["Hogwarts", "Magic", "Hagrid"] - }, - { - "firstName": "Sherlock", - "lastName": "Holmes", - "number": "0487345643", - "likes": ["Intriguing Cases", "Violin"] - }, - { - "firstName": "Kristian", - "lastName": "Vos", - "number": "unknown", - "likes": ["JavaScript", "Gaming", "Foxes"] - } +const contacts = [ + { + firstName: "Akira", + lastName: "Laine", + number: "0543236543", + likes: ["Pizza", "Coding", "Brownie Points"], + }, + { + firstName: "Harry", + lastName: "Potter", + number: "0994372684", + likes: ["Hogwarts", "Magic", "Hagrid"], + }, + { + firstName: "Sherlock", + lastName: "Holmes", + number: "0487345643", + likes: ["Intriguing Cases", "Violin"], + }, + { + firstName: "Kristian", + lastName: "Vos", + number: "unknown", + likes: ["JavaScript", "Gaming", "Foxes"], + }, ]; - function lookUpProfile(name, prop) { // Only change code below this line @@ -108,44 +107,38 @@ lookUpProfile("Akira", "likes"); # --solutions-- ```js -var contacts = [ - { - "firstName": "Akira", - "lastName": "Laine", - "number": "0543236543", - "likes": ["Pizza", "Coding", "Brownie Points"] - }, - { - "firstName": "Harry", - "lastName": "Potter", - "number": "0994372684", - "likes": ["Hogwarts", "Magic", "Hagrid"] - }, - { - "firstName": "Sherlock", - "lastName": "Holmes", - "number": "0487345643", - "likes": ["Intriguing Cases", "Violin"] - }, - { - "firstName": "Kristian", - "lastName": "Vos", - "number": "unknown", - "likes": ["JavaScript", "Gaming", "Foxes"] - }, +const contacts = [ + { + firstName: "Akira", + lastName: "Laine", + number: "0543236543", + likes: ["Pizza", "Coding", "Brownie Points"], + }, + { + firstName: "Harry", + lastName: "Potter", + number: "0994372684", + likes: ["Hogwarts", "Magic", "Hagrid"], + }, + { + firstName: "Sherlock", + lastName: "Holmes", + number: "0487345643", + likes: ["Intriguing Cases", "Violin"], + }, + { + firstName: "Kristian", + lastName: "Vos", + number: "unknown", + likes: ["JavaScript", "Gaming", "Foxes"], + }, ]; - - -//Write your function in between these comments -function lookUpProfile(name, prop){ - for(var i in contacts){ - if(contacts[i].firstName === name) { - return contacts[i][prop] || "No such property"; - } +function lookUpProfile(name, prop) { + for (let i in contacts) { + if (contacts[i].firstName === name) { + return contacts[i][prop] || "No such property"; } - return "No such contact"; + } + return "No such contact"; } -//Write your function in between these comments - -lookUpProfile("Akira", "likes"); ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/quoting-strings-with-single-quotes.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/quoting-strings-with-single-quotes.md index 8d70d9c8bd..255b74213c 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/quoting-strings-with-single-quotes.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/quoting-strings-with-single-quotes.md @@ -12,21 +12,21 @@ dashedName: quoting-strings-with-single-quotes JavaScript 中的字符串可以使用开始和结束都是同类型的单引号或双引号表示。 与其他一些编程语言不同的是,单引号和双引号的功能在 JavaScript 中是相同的。 ```js -doubleQuoteStr = "This is a string"; -singleQuoteStr = 'This is also a string'; +const doubleQuoteStr = "This is a string"; +const singleQuoteStr = 'This is also a string'; ``` 当你需要在一个字符串中使用多个引号的时候,你可以使用单引号包裹双引号或者相反。 常见的场景比如在字符串中包含对话的句子需要用引号包裹。 另外比如在一个包含有 `` 标签的字符串中,标签的属性值需要用引号包裹。 ```js -conversation = 'Finn exclaims to Jake, "Algebraic!"'; +const conversation = 'Finn exclaims to Jake, "Algebraic!"'; ``` 然而,如果你需要在其中使用外面的引号,这就成为一个问题。 记住,一个字符串在开头和结尾处有相同的引号。 要知道,字符串在开头和结尾都有相同的引号,如果在中间使用了相同的引号,字符串会提前中止并抛出错误。 ```js -goodStr = 'Jake asks Finn, "Hey, let\'s go on an adventure?"'; -badStr = 'Finn responds, "Let's go!"'; +const goodStr = 'Jake asks Finn, "Hey, let\'s go on an adventure?"'; +const badStr = 'Finn responds, "Let's go!"'; ``` 在这里 `badStr` 会产生一个错误。 @@ -71,11 +71,11 @@ assert(code.match(/"/g).length === 4 && code.match(/'/g).length === 2); ## --seed-contents-- ```js -var myStr = "Link"; +const myStr = "Link"; ``` # --solutions-- ```js -var myStr = 'Link'; +const myStr = 'Link'; ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/record-collection.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/record-collection.md index fc3d65d36d..053a7cbc6d 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/record-collection.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/record-collection.md @@ -115,7 +115,7 @@ const _recordCollection = { ```js // Setup -var recordCollection = { +const recordCollection = { 2548: { albumTitle: 'Slippery When Wet', artist: 'Bon Jovi', @@ -146,7 +146,7 @@ updateRecords(recordCollection, 5439, 'artist', 'ABBA'); # --solutions-- ```js -var recordCollection = { +const recordCollection = { 2548: { albumTitle: 'Slippery When Wet', artist: 'Bon Jovi', diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/replace-loops-using-recursion.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/replace-loops-using-recursion.md index c390f0231c..141e5c2000 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/replace-loops-using-recursion.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/replace-loops-using-recursion.md @@ -14,9 +14,9 @@ dashedName: replace-loops-using-recursion ```js function multiply(arr, n) { - var product = 1; - for (var i = 0; i < n; i++) { - product *= arr[i]; + let product = 1; + for (let i = 0; i < n; i++) { + product *= arr[i]; } return product; } diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/replacing-if-else-chains-with-switch.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/replacing-if-else-chains-with-switch.md index 0325d50b49..0416c6010b 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/replacing-if-else-chains-with-switch.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/replacing-if-else-chains-with-switch.md @@ -108,7 +108,7 @@ assert(chainToSwitch(156) === ''); ```js function chainToSwitch(val) { - var answer = ""; + let answer = ""; // Only change code below this line if (val === "bob") { @@ -134,7 +134,7 @@ chainToSwitch(7); ```js function chainToSwitch(val) { - var answer = ""; + let answer = ""; switch(val) { case "bob": diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/return-a-value-from-a-function-with-return.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/return-a-value-from-a-function-with-return.md index fc2cec504e..244198e630 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/return-a-value-from-a-function-with-return.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/return-a-value-from-a-function-with-return.md @@ -17,7 +17,8 @@ dashedName: return-a-value-from-a-function-with-return function plusThree(num) { return num + 3; } -var answer = plusThree(5); + +const answer = plusThree(5); ``` `answer` 的值为 `8`。 diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/selecting-from-many-options-with-switch-statements.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/selecting-from-many-options-with-switch-statements.md index 3120995b0b..8d191929e4 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/selecting-from-many-options-with-switch-statements.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/selecting-from-many-options-with-switch-statements.md @@ -78,7 +78,7 @@ assert(code.match(/break/g).length > 2); ```js function caseInSwitch(val) { - var answer = ""; + let answer = ""; // Only change code below this line @@ -94,7 +94,7 @@ caseInSwitch(1); ```js function caseInSwitch(val) { - var answer = ""; + let answer = ""; switch(val) { case 1: diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/shopping-list.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/shopping-list.md index 986e2352d7..62071ef62c 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/shopping-list.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/shopping-list.md @@ -81,13 +81,13 @@ var hasNumber = false; ## --seed-contents-- ```js -var myList = []; +const myList = []; ``` # --solutions-- ```js -var myList = [ +const myList = [ ["Candy", 10], ["Potatoes", 12], ["Eggs", 12], diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/stand-in-line.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/stand-in-line.md index 545ee62d5e..09cd58c72c 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/stand-in-line.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/stand-in-line.md @@ -93,12 +93,10 @@ function nextInLine(arr, item) { return item; // Only change code above this line - - } // Setup -var testArr = [1,2,3,4,5]; +const testArr = [1, 2, 3, 4, 5]; // Display code console.log("Before: " + JSON.stringify(testArr)); @@ -109,7 +107,7 @@ console.log("After: " + JSON.stringify(testArr)); # --solutions-- ```js -var testArr = [ 1,2,3,4,5]; +const testArr = [1, 2, 3, 4, 5]; function nextInLine(arr, item) { arr.push(item); diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/store-multiple-values-in-one-variable-using-javascript-arrays.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/store-multiple-values-in-one-variable-using-javascript-arrays.md index 3dd333bf1d..8f724a12de 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/store-multiple-values-in-one-variable-using-javascript-arrays.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/store-multiple-values-in-one-variable-using-javascript-arrays.md @@ -14,7 +14,7 @@ dashedName: store-multiple-values-in-one-variable-using-javascript-arrays 以左方括号开始定义一个数组,以右方括号结束,里面每个元素之间用逗号隔开,例如: ```js -var sandwich = ["peanut butter", "jelly", "bread"] +const sandwich = ["peanut butter", "jelly", "bread"]; ``` # --instructions-- @@ -53,11 +53,11 @@ assert(typeof myArray[1] !== 'undefined' && typeof myArray[1] == 'number'); ```js // Only change code below this line -var myArray = []; +const myArray = []; ``` # --solutions-- ```js -var myArray = ["The Answer", 42]; +const myArray = ["The Answer", 42]; ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/subtract-one-number-from-another-with-javascript.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/subtract-one-number-from-another-with-javascript.md index ad7eaf40ac..930fba699e 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/subtract-one-number-from-another-with-javascript.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/subtract-one-number-from-another-with-javascript.md @@ -16,7 +16,7 @@ JavaScript 中使用 `-` 来做减法运算。 **示例** ```js -myVar = 12 - 6; +const myVar = 12 - 6; ``` 现在,变量 `myVar` 的值为 `6`。 @@ -49,11 +49,11 @@ assert(/difference=45-33;?/.test(__helpers.removeWhiteSpace(code))); ## --seed-contents-- ```js -var difference = 45 - 0; +const difference = 45 - 0; ``` # --solutions-- ```js -var difference = 45 - 33; +const difference = 45 - 33; ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties.md index 509163d747..9399256427 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties.md @@ -13,10 +13,11 @@ dashedName: testing-objects-for-properties **示例** ```js -var myObj = { +const myObj = { top: "hat", bottom: "pants" }; + myObj.hasOwnProperty("top"); myObj.hasOwnProperty("middle"); ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/understand-string-immutability.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/understand-string-immutability.md index c33001dd50..9693664fd1 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/understand-string-immutability.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/understand-string-immutability.md @@ -14,14 +14,14 @@ dashedName: understand-string-immutability 例如,下面的代码: ```js -var myStr = "Bob"; +let myStr = "Bob"; myStr[0] = "J"; ``` 是不会把变量 `myStr` 的值改变成 `Job` 的,因为变量 `myStr` 是不可变的。 注意,这*并不*意味着 `myStr` 永远不能被改变,只是字符串字面量 string literal 的各个字符不能被改变。 改变 `myStr` 的唯一方法是重新给它赋一个值,例如: ```js -var myStr = "Bob"; +let myStr = "Bob"; myStr = "Job"; ``` @@ -55,7 +55,7 @@ assert(/myStr = "Jello World"/.test(code)); ```js // Setup -var myStr = "Jello World"; +let myStr = "Jello World"; // Only change code below this line myStr[0] = "H"; // Change this line @@ -65,6 +65,6 @@ myStr[0] = "H"; // Change this line # --solutions-- ```js -var myStr = "Jello World"; +let myStr = "Jello World"; myStr = "Hello World"; ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-boolean-values.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-boolean-values.md index 30fd5ce531..10207efa5c 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-boolean-values.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-boolean-values.md @@ -43,7 +43,6 @@ welcomeToBooleans(); ```js function welcomeToBooleans() { - // Only change code below this line return false; // Change this line diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-undefined-value-returned-from-a-function.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-undefined-value-returned-from-a-function.md index 550efd9bab..9438d612dc 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-undefined-value-returned-from-a-function.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-undefined-value-returned-from-a-function.md @@ -14,10 +14,12 @@ dashedName: understanding-undefined-value-returned-from-a-function **示例** ```js -var sum = 0; +let sum = 0; + function addSum(num) { sum = sum + num; } + addSum(3); ``` @@ -61,7 +63,7 @@ assert( ```js // Setup -var sum = 0; +let sum = 0; function addThree() { sum = sum + 3; @@ -79,7 +81,7 @@ addFive(); # --solutions-- ```js -var sum = 0; +let sum = 0; function addThree() { sum = sum + 3; diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/updating-object-properties.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/updating-object-properties.md index 10d9d6b255..696dadb913 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/updating-object-properties.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/updating-object-properties.md @@ -14,7 +14,7 @@ dashedName: updating-object-properties 举个例子,让我们看看 `ourDog`: ```js -var ourDog = { +const ourDog = { "name": "Camper", "legs": 4, "tails": 1, @@ -54,7 +54,7 @@ assert(/"name": "Coder"/.test(code)); ```js // Setup -var myDog = { +const myDog = { "name": "Coder", "legs": 4, "tails": 1, @@ -62,12 +62,13 @@ var myDog = { }; // Only change code below this line + ``` # --solutions-- ```js -var myDog = { +const myDog = { "name": "Coder", "legs": 4, "tails": 1, diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-nth-character-in-a-string.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-nth-character-in-a-string.md index d5e2158e63..f707560920 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-nth-character-in-a-string.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-nth-character-in-a-string.md @@ -16,8 +16,8 @@ dashedName: use-bracket-notation-to-find-the-nth-character-in-a-string 例如: ```js -var firstName = "Ada"; -var secondLetterOfFirstName = firstName[1]; +const firstName = "Ada"; +const secondLetterOfFirstName = firstName[1]; ``` `secondLetterOfFirstName` 值应该为字符串 `d`。 @@ -54,15 +54,15 @@ assert(code.match(/thirdLetterOfLastName\s*?=\s*?lastName\[.*?\]/)); ```js // Setup -var lastName = "Lovelace"; +const lastName = "Lovelace"; // Only change code below this line -var thirdLetterOfLastName = lastName; // Change this line +const thirdLetterOfLastName = lastName; // Change this line ``` # --solutions-- ```js -var lastName = "Lovelace"; -var thirdLetterOfLastName = lastName[2]; +const lastName = "Lovelace"; +const thirdLetterOfLastName = lastName[2]; ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/use-recursion-to-create-a-range-of-numbers.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/use-recursion-to-create-a-range-of-numbers.md index 0afaced617..751c0bb752 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/use-recursion-to-create-a-range-of-numbers.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/use-recursion-to-create-a-range-of-numbers.md @@ -73,7 +73,7 @@ function rangeOfNumbers(startNum, endNum) { if (endNum - startNum === 0) { return [startNum]; } else { - var numbers = rangeOfNumbers(startNum, endNum - 1); + const numbers = rangeOfNumbers(startNum, endNum - 1); numbers.push(endNum); return numbers; } diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function-with-a-radix.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function-with-a-radix.md index 01b23f4bd4..d270f9f2a9 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function-with-a-radix.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function-with-a-radix.md @@ -20,7 +20,7 @@ parseInt(string, radix); 这是一个示例: ```js -var a = parseInt("11", 2); +const a = parseInt("11", 2); ``` 变量 radix 表示 `11` 是在二进制系统中。 这个示例将字符串 `11` 转换为整数 `3`。 diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function.md index 26135ebac7..76acb0ca61 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function.md @@ -12,7 +12,7 @@ dashedName: use-the-parseint-function `parseInt()` 函数解析一个字符串返回一个整数。 下面是一个示例: ```js -var a = parseInt("007"); +const a = parseInt("007"); ``` 上述函数将字符串 `007` 转换为整数 `7`。 如果字符串中的第一个字符不能转换为数字,则返回 `NaN`。 diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/using-objects-for-lookups.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/using-objects-for-lookups.md index 16dc56565c..fa7e32d9c2 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/using-objects-for-lookups.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/using-objects-for-lookups.md @@ -14,7 +14,7 @@ dashedName: using-objects-for-lookups 这是简单的反向字母表: ```js -var alpha = { +const alpha = { 1:"Z", 2:"Y", 3:"X", @@ -24,10 +24,11 @@ var alpha = { 25:"B", 26:"A" }; + alpha[2]; alpha[24]; -var value = 2; +const value = 2; alpha[value]; ``` @@ -102,7 +103,7 @@ assert( ```js // Setup function phoneticLookup(val) { - var result = ""; + let result = ""; // Only change code below this line switch(val) { @@ -136,9 +137,9 @@ phoneticLookup("charlie"); ```js function phoneticLookup(val) { - var result = ""; + let result = ""; - var lookup = { + const lookup = { alpha: "Adams", bravo: "Boston", charlie: "Chicago", diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/word-blanks.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/word-blanks.md index 9551e57fda..db8d853878 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/word-blanks.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/basic-javascript/word-blanks.md @@ -16,7 +16,7 @@ dashedName: word-blanks 思考一下这句话 - It was really **\_\_\_\_**, and we **\_\_\_\_** ourselves **\_\_\_\_**。 这句话有三个缺失的部分 - 形容词、动词和副词,选择合适单词填入完成它。 然后将完成的句子赋值给变量,如下所示: ```js -var sentence = "It was really " + "hot" + ", and we " + "laughed" + " ourselves " + "silly" + "."; +const sentence = "It was really " + "hot" + ", and we " + "laughed" + " ourselves " + "silly" + "."; ``` # --instructions-- @@ -84,24 +84,24 @@ const removeAssignments = str => str ## --seed-contents-- ```js -var myNoun = "dog"; -var myAdjective = "big"; -var myVerb = "ran"; -var myAdverb = "quickly"; +const myNoun = "dog"; +const myAdjective = "big"; +const myVerb = "ran"; +const myAdverb = "quickly"; // Only change code below this line -var wordBlanks = ""; // Change this line +const wordBlanks = ""; // Change this line // Only change code above this line ``` # --solutions-- ```js -var myNoun = "dog"; -var myAdjective = "big"; -var myVerb = "ran"; -var myAdverb = "quickly"; +const myNoun = "dog"; +const myAdjective = "big"; +const myVerb = "ran"; +const myAdverb = "quickly"; -var wordBlanks = "Once there was a " + myNoun + " which was very " + myAdjective + ". "; +let wordBlanks = "Once there was a " + myNoun + " which was very " + myAdjective + ". "; wordBlanks += "It " + myVerb + " " + myAdverb + " around the yard."; ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/add-elements-to-the-end-of-an-array-using-concat-instead-of-push.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/add-elements-to-the-end-of-an-array-using-concat-instead-of-push.md index 06308ab6f2..a8fa46301d 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/add-elements-to-the-end-of-an-array-using-concat-instead-of-push.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/add-elements-to-the-end-of-an-array-using-concat-instead-of-push.md @@ -13,7 +13,7 @@ dashedName: add-elements-to-the-end-of-an-array-using-concat-instead-of-push 上一个挑战介绍了 `concat` 方法,这是一种在不改变原始数组的前提下,将数组组合成新数组的方法。 将 `concat` 方法与 `push` 方法做比较。 `push` 将元素添加到调用它的数组的末尾,这样会改变该数组。 举个例子: ```js -var arr = [1, 2, 3]; +const arr = [1, 2, 3]; arr.push([4, 5, 6]); ``` @@ -71,8 +71,9 @@ function nonMutatingPush(original, newItem) { // Only change code above this line } -var first = [1, 2, 3]; -var second = [4, 5]; + +const first = [1, 2, 3]; +const second = [4, 5]; nonMutatingPush(first, second); ``` @@ -82,7 +83,6 @@ nonMutatingPush(first, second); function nonMutatingPush(original, newItem) { return original.concat(newItem); } -var first = [1, 2, 3]; -var second = [4, 5]; -nonMutatingPush(first, second); +const first = [1, 2, 3]; +const second = [4, 5]; ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs.md index 70e6b984cb..c6580bbf5f 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs.md @@ -77,7 +77,6 @@ function urlSlug(title) { # --solutions-- ```js -// Only change code below this line function urlSlug(title) { return title.trim().split(/\s+/).join("-").toLowerCase(); } diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/avoid-mutations-and-side-effects-using-functional-programming.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/avoid-mutations-and-side-effects-using-functional-programming.md index deeeb4d8ea..33c39a49de 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/avoid-mutations-and-side-effects-using-functional-programming.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/avoid-mutations-and-side-effects-using-functional-programming.md @@ -57,9 +57,9 @@ assert(__newValue === 5); ```js // The global variable -var fixedValue = 4; +let fixedValue = 4; -function incrementer () { +function incrementer() { // Only change code below this line @@ -70,7 +70,7 @@ function incrementer () { # --solutions-- ```js -var fixedValue = 4 +let fixedValue = 4 function incrementer() { return fixedValue + 1 diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/combine-an-array-into-a-string-using-the-join-method.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/combine-an-array-into-a-string-using-the-join-method.md index 7ae48edd2e..06500eb5fa 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/combine-an-array-into-a-string-using-the-join-method.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/combine-an-array-into-a-string-using-the-join-method.md @@ -13,8 +13,8 @@ dashedName: combine-an-array-into-a-string-using-the-join-method 举个例子: ```js -var arr = ["Hello", "World"]; -var str = arr.join(" "); +const arr = ["Hello", "World"]; +const str = arr.join(" "); ``` `str` 的值应该是字符串 `Hello World`。 @@ -76,6 +76,7 @@ function sentensify(str) { // Only change code above this line } + sentensify("May-the-force-be-with-you"); ``` @@ -83,8 +84,6 @@ sentensify("May-the-force-be-with-you"); ```js function sentensify(str) { - // Only change code below this line return str.split(/\W/).join(' '); - // Only change code above this line } ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/combine-two-arrays-using-the-concat-method.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/combine-two-arrays-using-the-concat-method.md index 6e6e462765..9c3f6b58ac 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/combine-two-arrays-using-the-concat-method.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/combine-two-arrays-using-the-concat-method.md @@ -60,8 +60,9 @@ function nonMutatingConcat(original, attach) { // Only change code above this line } -var first = [1, 2, 3]; -var second = [4, 5]; + +const first = [1, 2, 3]; +const second = [4, 5]; nonMutatingConcat(first, second); ``` @@ -69,11 +70,8 @@ nonMutatingConcat(first, second); ```js function nonMutatingConcat(original, attach) { - // Only change code below this line return original.concat(attach); - // Only change code above this line } -var first = [1, 2, 3]; -var second = [4, 5]; -nonMutatingConcat(first, second); +const first = [1, 2, 3]; +const second = [4, 5]; ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype.md index 03bc973991..8d8c7d8eb1 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype.md @@ -38,17 +38,17 @@ assert(!code.match(/\.?[\s\S]*?map/g)); ```js // The global variable -var s = [23, 65, 98, 5]; +const s = [23, 65, 98, 5]; Array.prototype.myMap = function(callback) { - var newArray = []; + const newArray = []; // Only change code below this line // Only change code above this line return newArray; }; -var new_s = s.myMap(function(item) { +const new_s = s.myMap(function(item) { return item * 2; }); ``` @@ -56,20 +56,17 @@ var new_s = s.myMap(function(item) { # --solutions-- ```js -// the global Array -var s = [23, 65, 98, 5]; +const s = [23, 65, 98, 5]; Array.prototype.myMap = function(callback) { - var newArray = []; - // Only change code below this line - for (var elem of this) { + const newArray = []; + for (const elem of this) { newArray.push(callback(elem)); } - // Only change code above this line return newArray; }; -var new_s = s.myMap(function(item) { +const new_s = s.myMap(function(item) { return item * 2; }); ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/implement-the-filter-method-on-a-prototype.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/implement-the-filter-method-on-a-prototype.md index 08c03f10d0..c778c60319 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/implement-the-filter-method-on-a-prototype.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/implement-the-filter-method-on-a-prototype.md @@ -34,16 +34,16 @@ assert(!code.match(/\.?[\s\S]*?filter/g)); ```js // The global variable -var s = [23, 65, 98, 5]; +const s = [23, 65, 98, 5]; Array.prototype.myFilter = function(callback) { // Only change code below this line - var newArray = []; + const newArray = []; // Only change code above this line return newArray; }; -var new_s = s.myFilter(function(item) { +const new_s = s.myFilter(function(item) { return item % 2 === 1; }); ``` @@ -51,20 +51,17 @@ var new_s = s.myFilter(function(item) { # --solutions-- ```js -// the global Array -var s = [23, 65, 98, 5]; +const s = [23, 65, 98, 5]; Array.prototype.myFilter = function(callback) { - var newArray = []; - // Only change code below this line + const newArray = []; for (let i = 0; i < this.length; i++) { if (callback(this[i])) newArray.push(this[i]); } - // Only change code above this line return newArray; }; -var new_s = s.myFilter(function(item) { +const new_s = s.myFilter(function(item) { return item % 2 === 1; }); ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/introduction-to-currying-and-partial-application.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/introduction-to-currying-and-partial-application.md index 4cdb47a553..66fbedf415 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/introduction-to-currying-and-partial-application.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/introduction-to-currying-and-partial-application.md @@ -35,7 +35,7 @@ curried(1)(2) 柯里化在不能一次为函数提供所有参数情况下很有用。 因为它可以将每个函数的调用保存到一个变量中,该变量将保存返回的函数引用,该引用在下一个参数可用时接受该参数。 下面是使用柯里化函数的例子: ```js -var funcForY = curried(1); +const funcForY = curried(1); console.log(funcForY(2)); // 3 ``` @@ -45,7 +45,8 @@ console.log(funcForY(2)); // 3 function impartial(x, y, z) { return x + y + z; } -var partialFn = impartial.bind(this, 1, 2); + +const partialFn = impartial.bind(this, 1, 2); partialFn(10); // 13 ``` @@ -90,6 +91,7 @@ function add(x) { // Only change code above this line } + add(10)(20)(30); ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/pass-arguments-to-avoid-external-dependence-in-a-function.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/pass-arguments-to-avoid-external-dependence-in-a-function.md index 0b02fd625d..8b4de73416 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/pass-arguments-to-avoid-external-dependence-in-a-function.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/pass-arguments-to-avoid-external-dependence-in-a-function.md @@ -53,10 +53,10 @@ assert(__newValue === 5); ```js // The global variable -var fixedValue = 4; +let fixedValue = 4; // Only change code below this line -function incrementer () { +function incrementer() { // Only change code above this line @@ -66,15 +66,9 @@ function incrementer () { # --solutions-- ```js -// The global variable -var fixedValue = 4; +let fixedValue = 4; -// Only change code below this line -function incrementer (fixedValue) { +function incrementer(fixedValue) { return fixedValue + 1; - - // Only change code above this line } - - ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/remove-elements-from-an-array-using-slice-instead-of-splice.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/remove-elements-from-an-array-using-slice-instead-of-splice.md index 9da5369aee..722b234907 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/remove-elements-from-an-array-using-slice-instead-of-splice.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/remove-elements-from-an-array-using-slice-instead-of-splice.md @@ -11,7 +11,7 @@ dashedName: remove-elements-from-an-array-using-slice-instead-of-splice 使用数组时经常遇到要删除一些元素并保留数组剩余部分的情况。 为此,JavaScript 提供了 `splice` 方法,它接收两个参数:从哪里开始删除项目的索引,和要删除的项目数。 如果没有提供第二个参数,默认情况下是移除一直到结尾的所有元素。 但 `splice` 方法会改变调用它的原始数组。 举个例子: ```js -var cities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"]; +const cities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"]; cities.splice(3, 1); ``` @@ -69,7 +69,8 @@ function nonMutatingSplice(cities) { // Only change code above this line } -var inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"]; + +const inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"]; nonMutatingSplice(inputCities); ``` @@ -77,10 +78,7 @@ nonMutatingSplice(inputCities); ```js function nonMutatingSplice(cities) { - // Only change code below this line return cities.slice(0,3); - // Only change code above this line } -var inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"]; -nonMutatingSplice(inputCities); +const inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"]; ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/return-a-sorted-array-without-changing-the-original-array.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/return-a-sorted-array-without-changing-the-original-array.md index db2bbd2632..f453120227 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/return-a-sorted-array-without-changing-the-original-array.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/return-a-sorted-array-without-changing-the-original-array.md @@ -68,24 +68,23 @@ assert(JSON.stringify(nonMutatingSort([140000, 104, 99])) === ## --seed-contents-- ```js -var globalArray = [5, 6, 3, 2, 9]; +const globalArray = [5, 6, 3, 2, 9]; + function nonMutatingSort(arr) { // Only change code below this line // Only change code above this line } + nonMutatingSort(globalArray); ``` # --solutions-- ```js -var globalArray = [5, 6, 3, 2, 9]; +const globalArray = [5, 6, 3, 2, 9]; function nonMutatingSort(arr) { - // Only change code below this line return [].concat(arr).sort((a,b) => a-b); - // Only change code above this line } -nonMutatingSort(globalArray); ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/return-part-of-an-array-using-the-slice-method.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/return-part-of-an-array-using-the-slice-method.md index bce119c079..f8b1e266ab 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/return-part-of-an-array-using-the-slice-method.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/return-part-of-an-array-using-the-slice-method.md @@ -13,8 +13,8 @@ dashedName: return-part-of-an-array-using-the-slice-method 举个例子: ```js -var arr = ["Cat", "Dog", "Tiger", "Zebra"]; -var newArray = arr.slice(1, 3); +const arr = ["Cat", "Dog", "Tiger", "Zebra"]; +const newArray = arr.slice(1, 3); ``` `newArray` 值为 `["Dog", "Tiger"]` @@ -78,7 +78,8 @@ function sliceArray(anim, beginSlice, endSlice) { // Only change code above this line } -var inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"]; + +const inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"]; sliceArray(inputAnim, 1, 3); ``` @@ -86,10 +87,7 @@ sliceArray(inputAnim, 1, 3); ```js function sliceArray(anim, beginSlice, endSlice) { - // Only change code below this line - return anim.slice(beginSlice, endSlice) - // Only change code above this line + return anim.slice(beginSlice, endSlice); } -var inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"]; -sliceArray(inputAnim, 1, 3); +const inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"]; ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/sort-an-array-alphabetically-using-the-sort-method.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/sort-an-array-alphabetically-using-the-sort-method.md index 5f350cdf75..519880bd8f 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/sort-an-array-alphabetically-using-the-sort-method.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/sort-an-array-alphabetically-using-the-sort-method.md @@ -18,6 +18,7 @@ function ascendingOrder(arr) { return a - b; }); } + ascendingOrder([1, 5, 2, 3, 4]); ``` @@ -29,6 +30,7 @@ function reverseAlpha(arr) { return a === b ? 0 : a < b ? 1 : -1; }); } + reverseAlpha(['l', 'h', 'z', 'b', 's']); ``` @@ -86,6 +88,7 @@ function alphabeticalOrder(arr) { return arr // Only change code above this line } + alphabeticalOrder(["a", "d", "c", "a", "z", "g"]); ``` @@ -93,9 +96,6 @@ alphabeticalOrder(["a", "d", "c", "a", "z", "g"]); ```js function alphabeticalOrder(arr) { - // Only change code below this line return arr.sort(); - // Only change code above this line } -alphabeticalOrder(["a", "d", "c", "a", "z", "g"]); ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/split-a-string-into-an-array-using-the-split-method.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/split-a-string-into-an-array-using-the-split-method.md index f8721591ae..c4cf7eb3e4 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/split-a-string-into-an-array-using-the-split-method.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/split-a-string-into-an-array-using-the-split-method.md @@ -13,11 +13,11 @@ dashedName: split-a-string-into-an-array-using-the-split-method 下面是两个用空格分隔一个字符串的例子,另一个是用数字的正则表达式分隔: ```js -var str = "Hello World"; -var bySpace = str.split(" "); +const str = "Hello World"; +const bySpace = str.split(" "); -var otherString = "How9are7you2today"; -var byDigits = otherString.split(/\d/); +const otherString = "How9are7you2today"; +const byDigits = otherString.split(/\d/); ``` `bySpace` 将有值 `["Hello", "World"]`,`byDigits` 将有值 `["How", "are", "you", "today"]`。 @@ -74,6 +74,7 @@ function splitify(str) { // Only change code above this line } + splitify("Hello World,I-am code"); ``` @@ -81,8 +82,6 @@ splitify("Hello World,I-am code"); ```js function splitify(str) { - // Only change code below this line return str.split(/\W/); - // Only change code above this line } ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/understand-the-hazards-of-using-imperative-code.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/understand-the-hazards-of-using-imperative-code.md index f2793fa149..4638766ff0 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/understand-the-hazards-of-using-imperative-code.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/understand-the-hazards-of-using-imperative-code.md @@ -59,29 +59,29 @@ assert.deepEqual(finalTabs.tabs, [ ```js // tabs is an array of titles of each site open within the window -var Window = function(tabs) { +const Window = function(tabs) { this.tabs = tabs; // We keep a record of the array inside the object }; // When you join two windows into one window -Window.prototype.join = function (otherWindow) { +Window.prototype.join = function(otherWindow) { this.tabs = this.tabs.concat(otherWindow.tabs); return this; }; // When you open a new tab at the end -Window.prototype.tabOpen = function (tab) { +Window.prototype.tabOpen = function(tab) { this.tabs.push('new tab'); // Let's open a new tab for now return this; }; // When you close a tab -Window.prototype.tabClose = function (index) { +Window.prototype.tabClose = function(index) { // Only change code below this line - var tabsBeforeIndex = this.tabs.splice(0, index); // Get the tabs before the tab - var tabsAfterIndex = this.tabs.splice(index + 1); // Get the tabs after the tab + const tabsBeforeIndex = this.tabs.splice(0, index); // Get the tabs before the tab + const tabsAfterIndex = this.tabs.splice(index + 1); // Get the tabs after the tab this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // Join them together @@ -91,12 +91,12 @@ Window.prototype.tabClose = function (index) { }; // Let's create three browser windows -var workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); // Your mailbox, drive, and other work sites -var socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); // Social sites -var videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); // Entertainment sites +const workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); // Your mailbox, drive, and other work sites +const socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); // Social sites +const videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); // Entertainment sites // Now perform the tab opening, closing, and other operations -var finalTabs = socialWindow +const finalTabs = socialWindow .tabOpen() // Open a new tab for cat memes .join(videoWindow.tabClose(2)) // Close third tab in video window, and join .join(workWindow.tabClose(1).tabOpen()); @@ -106,40 +106,34 @@ console.log(finalTabs.tabs); # --solutions-- ```js -// tabs is an array of titles of each site open within the window -var Window = function(tabs) { - this.tabs = tabs; // We keep a record of the array inside the object +const Window = function(tabs) { + this.tabs = tabs; }; -// When you join two windows into one window -Window.prototype.join = function (otherWindow) { +Window.prototype.join = function(otherWindow) { this.tabs = this.tabs.concat(otherWindow.tabs); return this; }; -// When you open a new tab at the end -Window.prototype.tabOpen = function (tab) { - this.tabs.push('new tab'); // Let's open a new tab for now +Window.prototype.tabOpen = function(tab) { + this.tabs.push('new tab'); return this; }; -// When you close a tab -Window.prototype.tabClose = function (index) { - var tabsBeforeIndex = this.tabs.slice(0, index); // Get the tabs before the tab - var tabsAfterIndex = this.tabs.slice(index + 1); // Get the tabs after the tab +Window.prototype.tabClose = function(index) { + const tabsBeforeIndex = this.tabs.slice(0, index); + const tabsAfterIndex = this.tabs.slice(index + 1); - this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // Join them together + this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); return this; }; -// Let's create three browser windows -var workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); // Your mailbox, drive, and other work sites -var socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); // Social sites -var videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); // Entertainment sites +const workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); +const socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); +const videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); -// Now perform the tab opening, closing, and other operations -var finalTabs = socialWindow - .tabOpen() // Open a new tab for cat memes - .join(videoWindow.tabClose(2)) // Close third tab in video window, and join +const finalTabs = socialWindow + .tabOpen() + .join(videoWindow.tabClose(2)) .join(workWindow.tabClose(1).tabOpen()); ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria.md index dd7cd22c7b..381c708eda 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria.md @@ -13,7 +13,8 @@ dashedName: use-the-every-method-to-check-that-every-element-in-an-array-meets-a 举个例子,下面的代码检测数组 `numbers` 的所有元素是否都小于 10: ```js -var numbers = [1, 5, 8, 0, 10, 11]; +const numbers = [1, 5, 8, 0, 10, 11]; + numbers.every(function(currentValue) { return currentValue < 10; }); @@ -62,6 +63,7 @@ function checkPositive(arr) { // Only change code above this line } + checkPositive([1, 2, 3, -4, 5]); ``` @@ -69,9 +71,6 @@ checkPositive([1, 2, 3, -4, 5]); ```js function checkPositive(arr) { - // Only change code below this line return arr.every(num => num > 0); - // Only change code above this line } -checkPositive([1, 2, 3, -4, 5]); ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/use-the-reduce-method-to-analyze-data.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/use-the-reduce-method-to-analyze-data.md index 9574b36545..e347548086 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/use-the-reduce-method-to-analyze-data.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/use-the-reduce-method-to-analyze-data.md @@ -93,7 +93,7 @@ assert(getRating(watchList.filter((_, i) => i < 1 || i > 2)) === 8.55); ```js // The global variable -var watchList = [ +const watchList = [ { "Title": "Inception", "Year": "2010", @@ -206,22 +206,22 @@ var watchList = [ } ]; -function getRating(watchList){ +function getRating(watchList) { // Only change code below this line - var averageRating; + let averageRating; // Only change code above this line return averageRating; } + console.log(getRating(watchList)); ``` # --solutions-- ```js -// The global variable -var watchList = [ +const watchList = [ { "Title": "Inception", "Year": "2010", @@ -334,8 +334,8 @@ var watchList = [ } ]; -function getRating(watchList){ - var averageRating; +function getRating(watchList) { + let averageRating; const rating = watchList .filter(obj => obj.Director === "Christopher Nolan") .map(obj => Number(obj.imdbRating)); diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/use-the-some-method-to-check-that-any-elements-in-an-array-meet-a-criteria.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/use-the-some-method-to-check-that-any-elements-in-an-array-meet-a-criteria.md index 3a631b5671..9ddde647ca 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/use-the-some-method-to-check-that-any-elements-in-an-array-meet-a-criteria.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/functional-programming/use-the-some-method-to-check-that-any-elements-in-an-array-meet-a-criteria.md @@ -13,7 +13,8 @@ dashedName: use-the-some-method-to-check-that-any-elements-in-an-array-meet-a-cr 举个例子,下面的代码检测数组`numbers`中是否有元素小于 10: ```js -var numbers = [10, 50, 8, 220, 110, 11]; +const numbers = [10, 50, 8, 220, 110, 11]; + numbers.some(function(currentValue) { return currentValue < 10; }); @@ -62,6 +63,7 @@ function checkPositive(arr) { // Only change code above this line } + checkPositive([1, 2, 3, -4, 5]); ``` @@ -69,9 +71,6 @@ checkPositive([1, 2, 3, -4, 5]); ```js function checkPositive(arr) { - // Only change code below this line return arr.some(elem => elem > 0); - // Only change code above this line } -checkPositive([1, 2, 3, -4, 5]); ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays.md index 7e437f8c06..d8231ba7e6 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays.md @@ -157,7 +157,7 @@ assert(diffArray([1, 'calf', 3, 'piglet'], [7, 'filly']).length === 6); ```js function diffArray(arr1, arr2) { - var newArr = []; + const newArr = []; return newArr; } @@ -168,13 +168,12 @@ diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]); ```js function diffArray(arr1, arr2) { - var newArr = []; - var h1 = Object.create(null); + const newArr = []; + const h1 = Object.create(null); arr1.forEach(function(e) { h1[e] = e; }); - - var h2 = Object.create(null); + const h2 = Object.create(null); arr2.forEach(function(e) { h2[e] = e; }); diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/make-a-person.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/make-a-person.md index ca33f0cd92..2a4bc27f54 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/make-a-person.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/make-a-person.md @@ -148,7 +148,7 @@ if(bob){ ## --seed-contents-- ```js -var Person = function(firstAndLast) { +const Person = function(firstAndLast) { // Only change code below this line // Complete the method below and implement the others similarly this.getFullName = function() { @@ -157,16 +157,16 @@ var Person = function(firstAndLast) { return firstAndLast; }; -var bob = new Person('Bob Ross'); +const bob = new Person('Bob Ross'); bob.getFullName(); ``` # --solutions-- ```js -var Person = function(firstAndLast) { +const Person = function(firstAndLast) { - var firstName, lastName; + let firstName, lastName; function updateName(str) { firstName = str.split(" ")[0]; @@ -201,6 +201,6 @@ var Person = function(firstAndLast) { }; }; -var bob = new Person('Bob Ross'); +const bob = new Person('Bob Ross'); bob.getFullName(); ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/map-the-debris.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/map-the-debris.md index 472c9388ee..d53ca443db 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/map-the-debris.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/map-the-debris.md @@ -51,8 +51,8 @@ assert.deepEqual( ```js function orbitalPeriod(arr) { - var GM = 398600.4418; - var earthRadius = 6367.4447; + const GM = 398600.4418; + const earthRadius = 6367.4447; return arr; } @@ -63,9 +63,9 @@ orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]); ```js function orbitalPeriod(arr) { - var GM = 398600.4418; - var earthRadius = 6367.4447; - var TAU = 2 * Math.PI; + const GM = 398600.4418; + const earthRadius = 6367.4447; + const TAU = 2 * Math.PI; return arr.map(function(obj) { return { name: obj.name, @@ -73,6 +73,4 @@ function orbitalPeriod(arr) { }; }); } - -orbitalPeriod([{name : "sputkin", avgAlt : 35873.5553}]); ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple.md index 2c8092ea41..ff30a4a4e3 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple.md @@ -61,7 +61,6 @@ function smallestCommons(arr) { return arr; } - smallestCommons([1,5]); ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou.md index f972afdc1e..40a6ba7a5a 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou.md @@ -103,7 +103,7 @@ assert.deepEqual( ```js function whatIsInAName(collection, source) { - var arr = []; + const arr = []; // Only change code below this line @@ -118,8 +118,8 @@ whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: ```js function whatIsInAName(collection, source) { - var arr = []; - var keys = Object.keys(source); + const arr = []; + const keys = Object.keys(source); collection.forEach(function(e) { if(keys.every(function(key) {return e[key] === source[key];})) { arr.push(e); diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/caesars-cipher.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/caesars-cipher.md index 2b7edcaa94..67429f511e 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/caesars-cipher.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/caesars-cipher.md @@ -51,7 +51,6 @@ assert( ```js function rot13(str) { - return str; } diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/cash-register.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/cash-register.md index f89918bebd..a81e80a968 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/cash-register.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/cash-register.md @@ -186,7 +186,7 @@ assert.deepEqual( ```js function checkCashRegister(price, cash, cid) { - var change; + let change; return change; } @@ -196,54 +196,57 @@ checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], [ # --solutions-- ```js -var denom = [ - { name: 'ONE HUNDRED', val: 100}, - { name: 'TWENTY', val: 20}, - { name: 'TEN', val: 10}, - { name: 'FIVE', val: 5}, - { name: 'ONE', val: 1}, - { name: 'QUARTER', val: 0.25}, - { name: 'DIME', val: 0.1}, - { name: 'NICKEL', val: 0.05}, - { name: 'PENNY', val: 0.01} +const denom = [ + { name: "ONE HUNDRED", val: 100 }, + { name: "TWENTY", val: 20 }, + { name: "TEN", val: 10 }, + { name: "FIVE", val: 5 }, + { name: "ONE", val: 1 }, + { name: "QUARTER", val: 0.25 }, + { name: "DIME", val: 0.1 }, + { name: "NICKEL", val: 0.05 }, + { name: "PENNY", val: 0.01 }, ]; function checkCashRegister(price, cash, cid) { - var output = {status: null, change: []}; - var change = cash - price; - var register = cid.reduce(function(acc, curr) { - acc.total += curr[1]; - acc[curr[0]] = curr[1]; - return acc; - }, {total: 0}); - if(register.total === change) { - output.status = 'CLOSED'; - output.change = cid; - return output; - } - if(register.total < change) { - output.status = 'INSUFFICIENT_FUNDS'; - return output; - } - var change_arr = denom.reduce(function(acc, curr) { - var value = 0; - while(register[curr.name] > 0 && change >= curr.val) { - change -= curr.val; - register[curr.name] -= curr.val; - value += curr.val; - change = Math.round(change * 100) / 100; - } - if(value > 0) { - acc.push([ curr.name, value ]); - } - return acc; - }, []); - if(change_arr.length < 1 || change > 0) { - output.status = 'INSUFFICIENT_FUNDS'; - return output; - } - output.status = 'OPEN'; - output.change = change_arr; - return output; + const output = { status: null, change: [] }; + let change = cash - price; + const register = cid.reduce( + function (acc, curr) { + acc.total += curr[1]; + acc[curr[0]] = curr[1]; + return acc; + }, + { total: 0 } + ); + if (register.total === change) { + output.status = "CLOSED"; + output.change = cid; + return output; + } + if (register.total < change) { + output.status = "INSUFFICIENT_FUNDS"; + return output; + } + const change_arr = denom.reduce(function (acc, curr) { + let value = 0; + while (register[curr.name] > 0 && change >= curr.val) { + change -= curr.val; + register[curr.name] -= curr.val; + value += curr.val; + change = Math.round(change * 100) / 100; + } + if (value > 0) { + acc.push([curr.name, value]); + } + return acc; + }, []); + if (change_arr.length < 1 || change > 0) { + output.status = "INSUFFICIENT_FUNDS"; + return output; + } + output.status = "OPEN"; + output.change = change_arr; + return output; } ``` diff --git a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/palindrome-checker.md b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/palindrome-checker.md index 5443a90f4b..969f98023c 100644 --- a/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/palindrome-checker.md +++ b/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/palindrome-checker.md @@ -107,8 +107,6 @@ function palindrome(str) { return true; } - - palindrome("eye"); ``` diff --git a/curriculum/challenges/espanol/01-responsive-web-design/applied-accessibility/use-headings-to-show-hierarchical-relationships-of-content.md b/curriculum/challenges/espanol/01-responsive-web-design/applied-accessibility/use-headings-to-show-hierarchical-relationships-of-content.md index 0fde73a9eb..8c53f2cfb4 100644 --- a/curriculum/challenges/espanol/01-responsive-web-design/applied-accessibility/use-headings-to-show-hierarchical-relationships-of-content.md +++ b/curriculum/challenges/espanol/01-responsive-web-design/applied-accessibility/use-headings-to-show-hierarchical-relationships-of-content.md @@ -17,7 +17,7 @@ Si estuvieras escribiendo un documento con una introducción, un cuerpo y una co Los títulos con rango igual (o superior) comienzan nuevas secciones implícitas, los títulos con rango inferior comienzan subsecciones de la anterior. -Como ejemplo, una página con un elemento `h2` seguido de varias subsecciones marcadas con etiquetas `h4` confundirá a un lector de pantalla. Con seis opciones, es tentador usar una etiqueta porque se ve mejor en un navegador, pero puede usar CSS para editar el tamaño relativo. +Como un ejemplo, una página con un elemento `h2` seguido por varias subsecciones etiquetadas con elementos `h4` confundiría a un lector de pantalla. Con seis opciones, es tentador usar una etiqueta porque se ve mejor en un navegador, pero puede usar CSS para editar el tamaño relativo. Un punto final, cada página siempre debe tener un (y solo un) elemento `h1`, que es el tema principal de tu contenido. Este y los otros títulos son utilizados en parte por los motores de búsqueda para comprender el tema de la página. @@ -27,7 +27,7 @@ Camper Cat quiere una página en su sitio dedicada a convertirse en un ninja. Ay # --hints-- -Tu código debe tener 6 etiquetas `h3`. +Tu código debe tener 6 elementos `h3`. ```js assert($('h3').length === 6); @@ -39,7 +39,7 @@ Tu código debe tener 6 etiquetas de cierre `h3`. assert((code.match(/\/h3/g) || []).length === 6); ``` -Tu código no debe tener ninguna etiqueta `h5`. +Tu código no debe tener ningún elemento `h5`. ```js assert($('h5').length === 0); diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/access-array-data-with-indexes.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/access-array-data-with-indexes.md index 24ccd0b48c..96e7c2919b 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/access-array-data-with-indexes.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/access-array-data-with-indexes.md @@ -18,9 +18,9 @@ Los índices de los arreglos se escriben en la misma notación de corchetes que **Ejemplo** ```js -var array = [50,60,70]; +const array = [50, 60, 70]; array[0]; -var data = array[1]; +const data = array[1]; ``` `array[0]` ahora es `50` y `data` tiene el valor `60`. @@ -76,7 +76,7 @@ if(typeof myArray !== "undefined" && typeof myData !== "undefined"){(function(y, ## --seed-contents-- ```js -var myArray = [50,60,70]; +const myArray = [50, 60, 70]; ``` @@ -84,6 +84,6 @@ var myArray = [50,60,70]; # --solutions-- ```js -var myArray = [50,60,70]; -var myData = myArray[0]; +const myArray = [50, 60, 70]; +const myData = myArray[0]; ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/access-multi-dimensional-arrays-with-indexes.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/access-multi-dimensional-arrays-with-indexes.md index 80adef4699..ebbaf87236 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/access-multi-dimensional-arrays-with-indexes.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/access-multi-dimensional-arrays-with-indexes.md @@ -14,12 +14,13 @@ Se puede pensar que un arreglo multidimensional es como un *arreglo d **Ejemplo** ```js -var arr = [ - [1,2,3], - [4,5,6], - [7,8,9], - [[10,11,12], 13, 14] +const arr = [ + [1, 2, 3], + [4, 5, 6], + [7, 8, 9], + [[10, 11, 12], 13, 14] ]; + arr[3]; arr[3][0]; arr[3][0][1]; @@ -58,14 +59,19 @@ if(typeof myArray !== "undefined"){(function(){return "myData: " + myData + " my ## --seed-contents-- ```js -var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]]; +const myArray = [ + [1, 2, 3], + [4, 5, 6], + [7, 8, 9], + [[10, 11, 12], 13, 14], +]; -var myData = myArray[0][0]; +const myData = myArray[0][0]; ``` # --solutions-- ```js -var myArray = [[1,2,3],[4,5,6], [7,8,9], [[10,11,12], 13, 14]]; -var myData = myArray[2][1]; +const myArray = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [[10, 11, 12], 13, 14]]; +const myData = myArray[2][1]; ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-arrays.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-arrays.md index 6cebd810d2..df2e59d88f 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-arrays.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-arrays.md @@ -14,7 +14,7 @@ Como hemos visto en ejemplos anteriores, los objetos pueden contener tanto objet En el siguiente ejemplo, vemos cómo se accede a un arreglo anidado: ```js -var ourPets = [ +const ourPets = [ { animalType: "cat", names: [ @@ -32,6 +32,7 @@ var ourPets = [ ] } ]; + ourPets[0].names[1]; ourPets[1].names[0]; ``` @@ -72,7 +73,7 @@ assert(/=\s*myPlants\[1\].list\[1\]/.test(code)); ## --seed-contents-- ```js -var myPlants = [ +const myPlants = [ { type: "flowers", list: [ @@ -91,13 +92,13 @@ var myPlants = [ } ]; -var secondTree = ""; +const secondTree = ""; ``` # --solutions-- ```js -var myPlants = [ +const myPlants = [ { type: "flowers", list: [ @@ -116,5 +117,5 @@ var myPlants = [ } ]; -var secondTree = myPlants[1].list[1]; +const secondTree = myPlants[1].list[1]; ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-objects.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-objects.md index 3b0275ecfd..60c7312d98 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-objects.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-objects.md @@ -14,7 +14,7 @@ Se puede acceder a las sub propiedades de objetos encadenando la notación de pu Aquí hay un objeto anidado: ```js -var ourStorage = { +const ourStorage = { "desk": { "drawer": "stapler" }, @@ -26,6 +26,7 @@ var ourStorage = { "bottom drawer": "soda" } }; + ourStorage.cabinet["top drawer"].folder2; ourStorage.desk.drawer; ``` @@ -66,7 +67,7 @@ assert(/=\s*myStorage\.car\.inside\[\s*("|')glove box\1\s*\]/g.test(code)); ## --seed-contents-- ```js -var myStorage = { +const myStorage = { "car": { "inside": { "glove box": "maps", @@ -78,13 +79,13 @@ var myStorage = { } }; -var gloveBoxContents = undefined; +const gloveBoxContents = undefined; ``` # --solutions-- ```js -var myStorage = { +const myStorage = { "car":{ "inside":{ "glove box":"maps", @@ -95,5 +96,5 @@ var myStorage = { } } }; -var gloveBoxContents = myStorage.car.inside["glove box"]; +const gloveBoxContents = myStorage.car.inside["glove box"]; ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-bracket-notation.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-bracket-notation.md index f9b76e7b9a..c81d4c88a3 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-bracket-notation.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-bracket-notation.md @@ -16,11 +16,12 @@ Sin embargo, también puedes utilizar la notación de corchetes en las propiedad Aquí hay un ejemplo de cómo usar la notación de corchetes para leer la propiedad de un objeto: ```js -var myObj = { +const myObj = { "Space Name": "Kirk", "More Space": "Spock", "NoSpace": "USS Enterprise" }; + myObj["Space Name"]; myObj['More Space']; myObj["NoSpace"]; @@ -78,26 +79,25 @@ assert(code.match(/testObj\s*?\[('|")[^'"]+\1\]/g).length > 1); ```js // Setup -var testObj = { +const testObj = { "an entree": "hamburger", "my side": "veggies", "the drink": "water" }; // Only change code below this line - -var entreeValue = testObj; // Change this line -var drinkValue = testObj; // Change this line +const entreeValue = testObj; // Change this line +const drinkValue = testObj; // Change this line ``` # --solutions-- ```js -var testObj = { +const testObj = { "an entree": "hamburger", "my side": "veggies", "the drink": "water" }; -var entreeValue = testObj["an entree"]; -var drinkValue = testObj['the drink']; +const entreeValue = testObj["an entree"]; +const drinkValue = testObj['the drink']; ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-dot-notation.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-dot-notation.md index b76860c6fa..d6d9b3800b 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-dot-notation.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-dot-notation.md @@ -16,15 +16,17 @@ La notación de puntos es lo que se usa cuando conoces el nombre de la propiedad Aquí hay un ejemplo de cómo usar la notación de puntos (`.`) para leer la propiedad de un objeto: ```js -var myObj = { +const myObj = { prop1: "val1", prop2: "val2" }; -var prop1val = myObj.prop1; -var prop2val = myObj.prop2; + +const prop1val = myObj.prop1; +const prop2val = myObj.prop2; ``` `prop1val` tendrá una cadena con valor `val1` y `prop2val` tendrá una cadena con valor `val2`. + # --instructions-- Lee los valores de las propiedades de `testObj` utilizando la notación de puntos. Asigna la variable `hatValue` igual a la propiedad `hat` del objeto y asigna la variable `shirtValue` igual a la propiedad `shirt` del objeto. @@ -73,27 +75,26 @@ assert(code.match(/testObj\.\w+/g).length > 1); ```js // Setup -var testObj = { +const testObj = { "hat": "ballcap", "shirt": "jersey", "shoes": "cleats" }; // Only change code below this line - -var hatValue = testObj; // Change this line -var shirtValue = testObj; // Change this line +const hatValue = testObj; // Change this line +const shirtValue = testObj; // Change this line ``` # --solutions-- ```js -var testObj = { +const testObj = { "hat": "ballcap", "shirt": "jersey", "shoes": "cleats" }; -var hatValue = testObj.hat; -var shirtValue = testObj.shirt; +const hatValue = testObj.hat; +const shirtValue = testObj.shirt; ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-variables.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-variables.md index 543720a884..03419b6109 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-variables.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-variables.md @@ -14,11 +14,14 @@ Otro uso de la notación de corchetes en objetos es acceder a una propiedad que Aquí hay un ejemplo del uso de una variable para acceder a una propiedad: ```js -var dogs = { - Fido: "Mutt", Hunter: "Doberman", Snoopie: "Beagle" +const dogs = { + Fido: "Mutt", + Hunter: "Doberman", + Snoopie: "Beagle" }; -var myDog = "Hunter"; -var myBreed = dogs[myDog]; + +const myDog = "Hunter"; +const myBreed = dogs[myDog]; console.log(myBreed); ``` @@ -27,14 +30,16 @@ La cadena `Doberman` se mostrará en la consola. Otra forma de usar este concepto es cuando el nombre de la propiedad se recoge dinámicamente durante la ejecución del programa, de la siguiente manera: ```js -var someObj = { +const someObj = { propName: "John" }; + function propPrefix(str) { - var s = "prop"; + const s = "prop"; return s + str; } -var someProp = propPrefix("Name"); + +const someProp = propPrefix("Name"); console.log(someObj[someProp]); ``` @@ -96,26 +101,25 @@ if(typeof player !== "undefined"){(function(v){return v;})(player);} ```js // Setup -var testObj = { +const testObj = { 12: "Namath", 16: "Montana", 19: "Unitas" }; // Only change code below this line - -var playerNumber; // Change this line -var player = testObj; // Change this line +const playerNumber = 42; // Change this line +const player = testObj; // Change this line ``` # --solutions-- ```js -var testObj = { +const testObj = { 12: "Namath", 16: "Montana", 19: "Unitas" }; -var playerNumber = 16; -var player = testObj[playerNumber]; +const playerNumber = 16; +const player = testObj[playerNumber]; ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/add-new-properties-to-a-javascript-object.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/add-new-properties-to-a-javascript-object.md index afe37c98cd..2ca9f4d2e5 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/add-new-properties-to-a-javascript-object.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/add-new-properties-to-a-javascript-object.md @@ -28,7 +28,7 @@ Ahora cuando evaluemos `ourDog.bark`, obtendremos su ladrido, `bow-wow`. Por ejemplo: ```js -var ourDog = { +const ourDog = { "name": "Camper", "legs": 4, "tails": 1, @@ -67,7 +67,7 @@ assert(!/bark[^\n]:/.test(code)); ## --seed-contents-- ```js -var myDog = { +const myDog = { "name": "Happy Coder", "legs": 4, "tails": 1, @@ -80,7 +80,7 @@ var myDog = { # --solutions-- ```js -var myDog = { +const myDog = { "name": "Happy Coder", "legs": 4, "tails": 1, diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/add-two-numbers-with-javascript.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/add-two-numbers-with-javascript.md index 1673f7abbf..4248229929 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/add-two-numbers-with-javascript.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/add-two-numbers-with-javascript.md @@ -18,7 +18,7 @@ JavaScript utiliza el símbolo `+` como un operador de adición cuando se coloca **Ejemplo:** ```js -myVar = 5 + 10; +const myVar = 5 + 10; ``` `myVar` ahora tiene el valor `15`. @@ -52,11 +52,11 @@ assert(/\+/.test(code)); ## --seed-contents-- ```js -var sum = 10 + 0; +const sum = 10 + 0; ``` # --solutions-- ```js -var sum = 10 + 10; +const sum = 10 + 10; ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/adding-a-default-option-in-switch-statements.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/adding-a-default-option-in-switch-statements.md index dd791bb2e2..385ce1e84c 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/adding-a-default-option-in-switch-statements.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/adding-a-default-option-in-switch-statements.md @@ -92,7 +92,7 @@ assert(code.match(/break/g).length > 2); ```js function switchOfStuff(val) { - var answer = ""; + let answer = ""; // Only change code below this line @@ -108,7 +108,7 @@ switchOfStuff(1); ```js function switchOfStuff(val) { - var answer = ""; + let answer = ""; switch(val) { case "a": diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/appending-variables-to-strings.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/appending-variables-to-strings.md index b235bc75de..de755d7e0a 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/appending-variables-to-strings.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/appending-variables-to-strings.md @@ -14,8 +14,8 @@ Al igual que podemos construir una cadena sobre múltiples líneas a partir de l Ejemplo: ```js -var anAdjective = "awesome!"; -var ourStr = "freeCodeCamp is "; +const anAdjective = "awesome!"; +let ourStr = "freeCodeCamp is "; ourStr += anAdjective; ``` @@ -64,15 +64,14 @@ assert(code.match(/myStr\s*\+=\s*someAdjective\s*/).length > 0); ```js // Change code below this line - -var someAdjective; -var myStr = "Learning to code is "; +const someAdjective = ""; +let myStr = "Learning to code is "; ``` # --solutions-- ```js -var someAdjective = "neat"; -var myStr = "Learning to code is "; +const someAdjective = "neat"; +let myStr = "Learning to code is "; myStr += someAdjective; ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/build-javascript-objects.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/build-javascript-objects.md index 077f30206d..b2fe618f9e 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/build-javascript-objects.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/build-javascript-objects.md @@ -18,7 +18,7 @@ Los objetos son útiles para almacenar datos de forma estructurada y pueden repr Por ejemplo, aquí hay un objeto de gato: ```js -var cat = { +const cat = { "name": "Whiskers", "legs": 4, "tails": 1, @@ -29,7 +29,7 @@ var cat = { En este ejemplo, todas las propiedades se almacenan como cadenas, como `name`, `legs` y `tails`. Sin embargo, también puedes utilizar números como propiedades. Incluso puedes omitir las comillas para las propiedades de cadenas de una sola palabra, de la siguiente manera: ```js -var anotherObject = { +const anotherObject = { make: "Ford", 5: "five", "model": "focus" @@ -139,18 +139,18 @@ assert( ## --seed-contents-- ```js -var myDog = { -// Only change code below this line +const myDog = { + // Only change code below this line -// Only change code above this line + // Only change code above this line }; ``` # --solutions-- ```js -var myDog = { +const myDog = { "name": "Camper", "legs": 4, "tails": 1, diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-equality-operator.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-equality-operator.md index e162926ebe..b88c232d19 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-equality-operator.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-equality-operator.md @@ -16,7 +16,7 @@ El operador más básico es el de igualdad `==`. El operador de igualdad compara ```js function equalityTest(myVal) { if (myVal == 10) { - return "Equal"; + return "Equal"; } return "Not Equal"; } diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-addition.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-addition.md index 555340698a..da94c45a7c 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-addition.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-addition.md @@ -20,7 +20,7 @@ para sumar `5` a `myVar`. Dado que se trata de un patrón tan común, hay operad Uno de estos operadores es el operador `+=`. ```js -var myVar = 1; +let myVar = 1; myVar += 5; console.log(myVar); ``` @@ -61,9 +61,9 @@ No debes modificar el código por encima del comentario especificado. ```js assert( - /var a = 3;/.test(code) && - /var b = 17;/.test(code) && - /var c = 12;/.test(code) + /let a = 3;/.test(code) && + /let b = 17;/.test(code) && + /let c = 12;/.test(code) ); ``` @@ -78,9 +78,9 @@ assert( ## --seed-contents-- ```js -var a = 3; -var b = 17; -var c = 12; +let a = 3; +let b = 17; +let c = 12; // Only change code below this line a = a + 12; @@ -91,9 +91,9 @@ c = c + 7; # --solutions-- ```js -var a = 3; -var b = 17; -var c = 12; +let a = 3; +let b = 17; +let c = 12; a += 12; b += 9; diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-division.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-division.md index 1ab106d4a5..25757dc71a 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-division.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-division.md @@ -55,9 +55,9 @@ No debes modificar el código sobre el comentario especificado. ```js assert( - /var a = 48;/.test(code) && - /var b = 108;/.test(code) && - /var c = 33;/.test(code) + /let a = 48;/.test(code) && + /let b = 108;/.test(code) && + /let c = 33;/.test(code) ); ``` @@ -72,9 +72,9 @@ assert( ## --seed-contents-- ```js -var a = 48; -var b = 108; -var c = 33; +let a = 48; +let b = 108; +let c = 33; // Only change code below this line a = a / 12; @@ -85,9 +85,9 @@ c = c / 11; # --solutions-- ```js -var a = 48; -var b = 108; -var c = 33; +let a = 48; +let b = 108; +let c = 33; a /= 12; b /= 4; diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-multiplication.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-multiplication.md index 512e7f17f9..1a75a65e83 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-multiplication.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-multiplication.md @@ -55,9 +55,9 @@ No debes modificar el código sobre el comentario especificado. ```js assert( - /var a = 5;/.test(code) && - /var b = 12;/.test(code) && - /var c = 4\.6;/.test(code) + /let a = 5;/.test(code) && + /let b = 12;/.test(code) && + /let c = 4\.6;/.test(code) ); ``` @@ -72,9 +72,9 @@ assert( ## --seed-contents-- ```js -var a = 5; -var b = 12; -var c = 4.6; +let a = 5; +let b = 12; +let c = 4.6; // Only change code below this line a = a * 5; @@ -85,9 +85,9 @@ c = c * 10; # --solutions-- ```js -var a = 5; -var b = 12; -var c = 4.6; +let a = 5; +let b = 12; +let c = 4.6; a *= 5; b *= 3; diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-subtraction.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-subtraction.md index 99580fc9fc..38429d7c6a 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-subtraction.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-subtraction.md @@ -55,7 +55,7 @@ No debes modificar el código sobre el comentario especificado. ```js assert( - /var a = 11;/.test(code) && /var b = 9;/.test(code) && /var c = 3;/.test(code) + /let a = 11;/.test(code) && /let b = 9;/.test(code) && /let c = 3;/.test(code) ); ``` @@ -70,9 +70,9 @@ assert( ## --seed-contents-- ```js -var a = 11; -var b = 9; -var c = 3; +let a = 11; +let b = 9; +let c = 3; // Only change code below this line a = a - 6; @@ -83,9 +83,9 @@ c = c - 1; # --solutions-- ```js -var a = 11; -var b = 9; -var c = 3; +let a = 11; +let b = 9; +let c = 3; a -= 6; b -= 15; diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-the-plus-equals-operator.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-the-plus-equals-operator.md index 6c8d8afa40..71f31f0e0b 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-the-plus-equals-operator.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-the-plus-equals-operator.md @@ -16,7 +16,7 @@ También podemos utilizar el operador `+=` para concatenar una cadena Ejemplo: ```js -var ourStr = "I come first. "; +let ourStr = "I come first. "; ourStr += "I come second."; ``` @@ -57,14 +57,12 @@ assert(code.match(/myStr\s*\+=\s*(["']).*\1/g)); ## --seed-contents-- ```js -// Only change code below this line - -var myStr; +let myStr; ``` # --solutions-- ```js -var myStr = "This is the first sentence. "; +let myStr = "This is the first sentence. "; myStr += "This is the second sentence."; ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/constructing-strings-with-variables.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/constructing-strings-with-variables.md index f99326a40c..8b05260f2e 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/constructing-strings-with-variables.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/constructing-strings-with-variables.md @@ -14,8 +14,8 @@ A veces necesitarás construir una cadena, al estilo [Mad Libs](https://en.wikip Ejemplo: ```js -var ourName = "freeCodeCamp"; -var ourStr = "Hello, our name is " + ourName + ", how are you?"; +const ourName = "freeCodeCamp"; +const ourStr = "Hello, our name is " + ourName + ", how are you?"; ``` `ourStr` tendrá como valor la cadena `Hello, our name is freeCodeCamp, how are you?`. @@ -63,13 +63,13 @@ assert(code.match(/["']\s*\+\s*myName\s*\+\s*["']/g).length > 0); ```js // Only change code below this line -var myName; -var myStr; +const myName = ""; +const myStr = ""; ``` # --solutions-- ```js -var myName = "Bob"; -var myStr = "My name is " + myName + " and I am well!"; +const myName = "Bob"; +const myStr = "My name is " + myName + " and I am well!"; ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/counting-cards.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/counting-cards.md index 084a4b45b3..6cf3bf07c1 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/counting-cards.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/counting-cards.md @@ -159,7 +159,7 @@ assert( ## --seed-contents-- ```js -var count = 0; +let count = 0; function cc(card) { // Only change code below this line @@ -175,7 +175,7 @@ cc(2); cc(3); cc(7); cc('K'); cc('A'); # --solutions-- ```js -var count = 0; +let count = 0; function cc(card) { switch(card) { case 2: diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/create-decimal-numbers-with-javascript.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/create-decimal-numbers-with-javascript.md index fb6e160502..c548545829 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/create-decimal-numbers-with-javascript.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/create-decimal-numbers-with-javascript.md @@ -42,13 +42,14 @@ assert(myDecimal % 1 != 0); ## --seed-contents-- ```js -var ourDecimal = 5.7; +const ourDecimal = 5.7; // Only change code below this line + ``` # --solutions-- ```js -var myDecimal = 9.9; +const myDecimal = 9.9; ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/decrement-a-number-with-javascript.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/decrement-a-number-with-javascript.md index 68a2a9a651..ea3ec61d42 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/decrement-a-number-with-javascript.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/decrement-a-number-with-javascript.md @@ -39,7 +39,7 @@ assert(myVar === 10); ```js assert( - /var\s*myVar\s*=\s*11;\s*\/*.*\s*([-]{2}\s*myVar|myVar\s*[-]{2});/.test(code) + /let\s*myVar\s*=\s*11;\s*\/*.*\s*([-]{2}\s*myVar|myVar\s*[-]{2});/.test(code) ); ``` @@ -52,7 +52,7 @@ assert(/[-]{2}\s*myVar|myVar\s*[-]{2}/.test(code)); No debes cambiar el código por encima del comentario especificado. ```js -assert(/var myVar = 11;/.test(code)); +assert(/let myVar = 11;/.test(code)); ``` # --seed-- @@ -66,7 +66,7 @@ assert(/var myVar = 11;/.test(code)); ## --seed-contents-- ```js -var myVar = 11; +let myVar = 11; // Only change code below this line myVar = myVar - 1; @@ -75,6 +75,6 @@ myVar = myVar - 1; # --solutions-- ```js -var myVar = 11; +let myVar = 11; myVar--; ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/delete-properties-from-a-javascript-object.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/delete-properties-from-a-javascript-object.md index 4b06a101da..0c4f33bb91 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/delete-properties-from-a-javascript-object.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/delete-properties-from-a-javascript-object.md @@ -18,7 +18,7 @@ delete ourDog.bark; Ejemplo: ```js -var ourDog = { +const ourDog = { "name": "Camper", "legs": 4, "tails": 1, @@ -70,7 +70,7 @@ assert(code.match(/"tails": 1/g).length > 0); ```js // Setup -var myDog = { +const myDog = { "name": "Happy Coder", "legs": 4, "tails": 1, @@ -79,12 +79,13 @@ var myDog = { }; // Only change code below this line + ``` # --solutions-- ```js -var myDog = { +const myDog = { "name": "Happy Coder", "legs": 4, "tails": 1, diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-decimal-by-another-with-javascript.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-decimal-by-another-with-javascript.md index 084ee38e9f..f5460a9016 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-decimal-by-another-with-javascript.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-decimal-by-another-with-javascript.md @@ -46,11 +46,11 @@ assert(code.match(/quotient/g).length === 1); ## --seed-contents-- ```js -var quotient = 0.0 / 2.0; // Change this line +const quotient = 0.0 / 2.0; // Change this line ``` # --solutions-- ```js -var quotient = 4.4 / 2.0; +const quotient = 4.4 / 2.0; ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-number-by-another-with-javascript.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-number-by-another-with-javascript.md index dd54212715..b8cc296aca 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-number-by-another-with-javascript.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-number-by-another-with-javascript.md @@ -16,7 +16,7 @@ JavaScript utiliza el símbolo `/` para la división. **Ejemplo** ```js -myVar = 16 / 2; +const myVar = 16 / 2; ``` `myVar` ahora tiene el valor `8`. @@ -49,11 +49,11 @@ assert(/\d+\s*\/\s*\d+/.test(code)); ## --seed-contents-- ```js -var quotient = 66 / 0; +const quotient = 66 / 0; ``` # --solutions-- ```js -var quotient = 66 / 33; +const quotient = 66 / 33; ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/escape-sequences-in-strings.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/escape-sequences-in-strings.md index d56bf45c7b..30bf2a478e 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/escape-sequences-in-strings.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/escape-sequences-in-strings.md @@ -89,11 +89,11 @@ console.log('myStr:\n' + myStr);}})(); ## --seed-contents-- ```js -var myStr; // Change this line +const myStr = ""; // Change this line ``` # --solutions-- ```js -var myStr = "FirstLine\n\t\\SecondLine\nThirdLine"; +const myStr = "FirstLine\n\t\\SecondLine\nThirdLine"; ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/escaping-literal-quotes-in-strings.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/escaping-literal-quotes-in-strings.md index e3414cf46c..a4d96b8825 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/escaping-literal-quotes-in-strings.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/escaping-literal-quotes-in-strings.md @@ -14,7 +14,7 @@ Cuando estás definiendo una cadena debes comenzar y terminar con una comilla si En JavaScript, puedes escapar una comilla de considerarse un final de cadena colocando una barra invertida (`\`) delante de la comilla. ```js -var sampleStr = "Alan said, \"Peter is learning JavaScript\"."; +const sampleStr = "Alan said, \"Peter is learning JavaScript\"."; ``` Esto indica a JavaScript que la siguiente comilla no es el final de la cadena, sino que debería aparecer dentro de la cadena. Así que si imprimieras esto en la consola, obtendrías: @@ -62,11 +62,11 @@ assert(/I am a "double quoted" string inside "double quotes(\."|"\.)$/.test(mySt ## --seed-contents-- ```js -var myStr = ""; // Change this line +const myStr = ""; // Change this line ``` # --solutions-- ```js -var myStr = "I am a \"double quoted\" string inside \"double quotes\"."; +const myStr = "I am a \"double quoted\" string inside \"double quotes\"."; ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/finding-a-remainder-in-javascript.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/finding-a-remainder-in-javascript.md index 4b8339fc95..4a008eae72 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/finding-a-remainder-in-javascript.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/finding-a-remainder-in-javascript.md @@ -31,7 +31,7 @@ Establece `remainder` igual al resto de `11` dividido entre `3` usando el operad La variable `remainder` debe inicializarse ```js -assert(/var\s+?remainder/.test(code)); +assert(/(const|let|var)\s+?remainder/.test(code)); ``` El valor de `remainder` debe ser `2` @@ -57,13 +57,11 @@ assert(/\s+?remainder\s*?=\s*?.*%.*;?/.test(code)); ## --seed-contents-- ```js -// Only change code below this line - -var remainder; +const remainder = 0; ``` # --solutions-- ```js -var remainder = 11 % 3; +const remainder = 11 % 3; ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/global-vs.-local-scope-in-functions.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/global-vs.-local-scope-in-functions.md index 54f2e81ca4..8567f1098d 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/global-vs.-local-scope-in-functions.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/global-vs.-local-scope-in-functions.md @@ -14,9 +14,10 @@ Es posible tener variables locales y globales con el mismo En este ejemplo: ```js -var someVar = "Hat"; +const someVar = "Hat"; + function myFun() { - var someVar = "Head"; + const someVar = "Head"; return someVar; } ``` @@ -53,13 +54,11 @@ assert(/return outerWear/.test(code)); ```js // Setup -var outerWear = "T-Shirt"; +const outerWear = "T-Shirt"; function myOutfit() { // Only change code below this line - - // Only change code above this line return outerWear; } @@ -70,9 +69,9 @@ myOutfit(); # --solutions-- ```js -var outerWear = "T-Shirt"; +const outerWear = "T-Shirt"; function myOutfit() { - var outerWear = "sweater"; + const outerWear = "sweater"; return outerWear; } ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/golf-code.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/golf-code.md index 9b4d455f52..3005d9fe81 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/golf-code.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/golf-code.md @@ -90,7 +90,8 @@ assert(golfScore(5, 9) === 'Go Home!'); ## --seed-contents-- ```js -var names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"]; +const names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"]; + function golfScore(par, strokes) { // Only change code below this line diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/increment-a-number-with-javascript.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/increment-a-number-with-javascript.md index 0327dea07c..a0b31c5f34 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/increment-a-number-with-javascript.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/increment-a-number-with-javascript.md @@ -39,7 +39,7 @@ No debes utilizar el operador de asignación. ```js assert( - /var\s*myVar\s*=\s*87;\s*\/*.*\s*([+]{2}\s*myVar|myVar\s*[+]{2});/.test(code) + /let\s*myVar\s*=\s*87;\s*\/*.*\s*([+]{2}\s*myVar|myVar\s*[+]{2});/.test(code) ); ``` @@ -52,7 +52,7 @@ assert(/[+]{2}\s*myVar|myVar\s*[+]{2}/.test(code)); No debes cambiar el código por encima del comentario especificado. ```js -assert(/var myVar = 87;/.test(code)); +assert(/let myVar = 87;/.test(code)); ``` # --seed-- @@ -66,7 +66,7 @@ assert(/var myVar = 87;/.test(code)); ## --seed-contents-- ```js -var myVar = 87; +let myVar = 87; // Only change code below this line myVar = myVar + 1; @@ -75,6 +75,6 @@ myVar = myVar + 1; # --solutions-- ```js -var myVar = 87; +let myVar = 87; myVar++; ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/introducing-else-statements.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/introducing-else-statements.md index 44dc5c4988..700f84c2a7 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/introducing-else-statements.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/introducing-else-statements.md @@ -64,7 +64,7 @@ assert(testElse(10) === 'Bigger than 5'); No debes cambiar el código por encima o por debajo de los comentarios especificados. ```js -assert(/var result = "";/.test(code) && /return result;/.test(code)); +assert(/let result = "";/.test(code) && /return result;/.test(code)); ``` # --seed-- @@ -73,7 +73,7 @@ assert(/var result = "";/.test(code) && /return result;/.test(code)); ```js function testElse(val) { - var result = ""; + let result = ""; // Only change code below this line if (val > 5) { @@ -95,7 +95,7 @@ testElse(4); ```js function testElse(val) { - var result = ""; + let result = ""; if(val > 5) { result = "Bigger than 5"; } else { diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-through-an-array-with-a-for-loop.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-through-an-array-with-a-for-loop.md index 4e42c0d59e..0afa922388 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-through-an-array-with-a-for-loop.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-through-an-array-with-a-for-loop.md @@ -12,8 +12,9 @@ dashedName: iterate-through-an-array-with-a-for-loop Una tarea común en JavaScript es iterar a través del contenido de un arreglo. Una forma de hacerlo es con un bucle `for`. Este código mostrará cada elemento del arreglo `arr` en la consola: ```js -var arr = [10, 9, 8, 7, 6]; -for (var i = 0; i < arr.length; i++) { +const arr = [10, 9, 8, 7, 6]; + +for (let i = 0; i < arr.length; i++) { console.log(arr[i]); } ``` @@ -62,18 +63,19 @@ assert(!__helpers.removeWhiteSpace(code).match(/total[=+-]0*[1-9]+/gm)); ```js // Setup -var myArr = [ 2, 3, 4, 5, 6]; +const myArr = [2, 3, 4, 5, 6]; // Only change code below this line + ``` # --solutions-- ```js -var myArr = [ 2, 3, 4, 5, 6]; -var total = 0; +const myArr = [2, 3, 4, 5, 6]; +let total = 0; -for (var i = 0; i < myArr.length; i++) { +for (let i = 0; i < myArr.length; i++) { total += myArr[i]; } ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-do...while-loops.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-do...while-loops.md index 1d3bb74e58..ec75b75adb 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-do...while-loops.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-do...while-loops.md @@ -12,8 +12,9 @@ dashedName: iterate-with-javascript-do---while-loops El siguiente tipo de bucle que aprenderás se llama bucle `do...while`. Se llama bucle `do...while` porque primero hace (`do`) una pasada por el código dentro del bucle sin importar qué, y luego continua ejecutando el bucle mientras (`while`) la condición especificada sea verdadera (`true`). ```js -var ourArray = []; -var i = 0; +const ourArray = []; +let i = 0; + do { ourArray.push(i); i++; @@ -23,8 +24,9 @@ do { El ejemplo anterior se comporta de forma similar a otros tipos de bucles, siendo el arreglo resultante `[0, 1, 2, 3, 4]`. Sin embargo, lo que hace que el bucle `do...while` sea diferente a otros bucles es cómo se comporta cuando la condición falla en la primera verificación. Veamos esto en acción: Aquí puedes ver un bucle `while` que ejecutará el código una y otra vez siempre que `i < 5`: ```js -var ourArray = []; -var i = 5; +const ourArray = []; +let i = 5; + while (i < 5) { ourArray.push(i); i++; @@ -34,8 +36,9 @@ while (i < 5) { En este ejemplo, inicializamos el valor de `ourArray` a un arreglo vacío y el valor de `i` a 5. Cuando ejecutamos el bucle `while`, la condición se evalúa como `false` porque `i` no es inferior a 5, así que no ejecutamos el código dentro del bucle. El resultado es que `ourArray` terminará sin valores añadidos, y todavía se verá como `[]` una vez el código del ejemplo anterior haya terminado de ejecutarse. Ahora, dale un vistazo a un bucle `do...while`: ```js -var ourArray = []; -var i = 5; +const ourArray = []; +let i = 5; + do { ourArray.push(i); i++; @@ -80,8 +83,8 @@ if(typeof myArray !== "undefined"){(function(){return myArray;})();} ```js // Setup -var myArray = []; -var i = 10; +const myArray = []; +let i = 10; // Only change code below this line while (i < 5) { @@ -93,8 +96,8 @@ while (i < 5) { # --solutions-- ```js -var myArray = []; -var i = 10; +const myArray = []; +let i = 10; do { myArray.push(i); i++; diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/local-scope-and-functions.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/local-scope-and-functions.md index 1fef0ad88c..3a21aa3386 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/local-scope-and-functions.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/local-scope-and-functions.md @@ -15,9 +15,10 @@ Esta es una función `myTest` con una variable local llamada `loc`. ```js function myTest() { - var loc = "foo"; + const loc = "foo"; console.log(loc); } + myTest(); console.log(loc); ``` @@ -38,6 +39,7 @@ El código no debe contener una variable global `myVar`. function declared() { myVar; } + assert.throws(declared, ReferenceError); ``` @@ -57,7 +59,6 @@ assert( ```js function myLocalScope() { - // Only change code below this line console.log('inside myLocalScope', myVar); @@ -73,9 +74,8 @@ console.log('outside myLocalScope', myVar); ```js function myLocalScope() { - // Only change code below this line - var myVar; + let myVar; console.log('inside myLocalScope', myVar); } myLocalScope(); diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-push.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-push.md index 38378fca34..98211251ea 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-push.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-push.md @@ -16,10 +16,10 @@ Una forma fácil de añadir datos al final de un arreglo es a través de la func Ejemplos: ```js -var arr1 = [1,2,3]; +const arr1 = [1, 2, 3]; arr1.push(4); -var arr2 = ["Stimpson", "J", "cat"]; +const arr2 = ["Stimpson", "J", "cat"]; arr2.push(["happy", "joy"]); ``` @@ -64,14 +64,15 @@ assert( ```js // Setup -var myArray = [["John", 23], ["cat", 2]]; +const myArray = [["John", 23], ["cat", 2]]; // Only change code below this line + ``` # --solutions-- ```js -var myArray = [["John", 23], ["cat", 2]]; +const myArray = [["John", 23], ["cat", 2]]; myArray.push(["dog",3]); ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/manipulating-complex-objects.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/manipulating-complex-objects.md index 1316f3c02f..5404cd0fd0 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/manipulating-complex-objects.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/manipulating-complex-objects.md @@ -14,7 +14,7 @@ A veces, es posible que desees almacenar datos en una estructura de datos { ## --seed-contents-- ```js -var myMusic = [ +const myMusic = [ { "artist": "Billy Joel", "title": "Piano Man", @@ -153,7 +153,7 @@ var myMusic = [ # --solutions-- ```js -var myMusic = [ +const myMusic = [ { "artist": "Billy Joel", "title": "Piano Man", diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/multiple-identical-options-in-switch-statements.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/multiple-identical-options-in-switch-statements.md index 7b0be19c84..6c95d8050f 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/multiple-identical-options-in-switch-statements.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/multiple-identical-options-in-switch-statements.md @@ -12,7 +12,7 @@ dashedName: multiple-identical-options-in-switch-statements Si la sentencia `break` es omitida en un caso (`case`) de una sentencia `switch`, las siguientes sentencias `case` serán ejecutadas hasta encontrar un `break`. Si tienes múltiples entradas con la misma salida, puedes representarlas en una sentencia `switch` como esta: ```js -var result = ""; +let result = ""; switch(val) { case 1: case 2: @@ -109,7 +109,7 @@ assert(code.match(/case/g).length === 9); ```js function sequentialSizes(val) { - var answer = ""; + let answer = ""; // Only change code below this line @@ -125,7 +125,7 @@ sequentialSizes(1); ```js function sequentialSizes(val) { - var answer = ""; + let answer = ""; switch(val) { case 1: diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-decimals-with-javascript.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-decimals-with-javascript.md index 7345e4d5e5..6682d8f760 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-decimals-with-javascript.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-decimals-with-javascript.md @@ -42,11 +42,11 @@ assert(/\*/.test(code)); ## --seed-contents-- ```js -var product = 2.0 * 0.0; +const product = 2.0 * 0.0; ``` # --solutions-- ```js -var product = 2.0 * 2.5; +const product = 2.0 * 2.5; ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-numbers-with-javascript.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-numbers-with-javascript.md index 9365ddea99..7dae3ad752 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-numbers-with-javascript.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-numbers-with-javascript.md @@ -16,7 +16,7 @@ JavaScript utiliza el símbolo `*` para multiplicar dos números. **Ejemplo** ```js -myVar = 13 * 13; +const myVar = 13 * 13; ``` `myVar` ahora tendrá el valor `169`. @@ -50,11 +50,11 @@ assert(/\*/.test(code)); ## --seed-contents-- ```js -var product = 8 * 0; +const product = 8 * 0; ``` # --solutions-- ```js -var product = 8 * 10; +const product = 8 * 10; ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/nest-one-array-within-another-array.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/nest-one-array-within-another-array.md index d8af7d46f5..e026503ec3 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/nest-one-array-within-another-array.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/nest-one-array-within-another-array.md @@ -12,7 +12,7 @@ dashedName: nest-one-array-within-another-array También puedes anidar arreglos dentro de otros arreglos, como a continuación: ```js -[["Bulls", 23], ["White Sox", 45]] +const teams = [["Bulls", 23], ["White Sox", 45]]; ``` Esto también es conocido como arreglo multidimensional. @@ -41,11 +41,11 @@ if(typeof myArray !== "undefined"){(function(){return myArray;})();} ```js // Only change code below this line -var myArray = []; +const myArray = []; ``` # --solutions-- ```js -var myArray = [[1,2,3]]; +const myArray = [[1, 2, 3]]; ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/profile-lookup.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/profile-lookup.md index 7af20779f5..2bf87be028 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/profile-lookup.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/profile-lookup.md @@ -68,34 +68,33 @@ assert(lookUpProfile('Akira', 'address') === 'No such property'); ```js // Setup -var contacts = [ - { - "firstName": "Akira", - "lastName": "Laine", - "number": "0543236543", - "likes": ["Pizza", "Coding", "Brownie Points"] - }, - { - "firstName": "Harry", - "lastName": "Potter", - "number": "0994372684", - "likes": ["Hogwarts", "Magic", "Hagrid"] - }, - { - "firstName": "Sherlock", - "lastName": "Holmes", - "number": "0487345643", - "likes": ["Intriguing Cases", "Violin"] - }, - { - "firstName": "Kristian", - "lastName": "Vos", - "number": "unknown", - "likes": ["JavaScript", "Gaming", "Foxes"] - } +const contacts = [ + { + firstName: "Akira", + lastName: "Laine", + number: "0543236543", + likes: ["Pizza", "Coding", "Brownie Points"], + }, + { + firstName: "Harry", + lastName: "Potter", + number: "0994372684", + likes: ["Hogwarts", "Magic", "Hagrid"], + }, + { + firstName: "Sherlock", + lastName: "Holmes", + number: "0487345643", + likes: ["Intriguing Cases", "Violin"], + }, + { + firstName: "Kristian", + lastName: "Vos", + number: "unknown", + likes: ["JavaScript", "Gaming", "Foxes"], + }, ]; - function lookUpProfile(name, prop) { // Only change code below this line @@ -108,44 +107,38 @@ lookUpProfile("Akira", "likes"); # --solutions-- ```js -var contacts = [ - { - "firstName": "Akira", - "lastName": "Laine", - "number": "0543236543", - "likes": ["Pizza", "Coding", "Brownie Points"] - }, - { - "firstName": "Harry", - "lastName": "Potter", - "number": "0994372684", - "likes": ["Hogwarts", "Magic", "Hagrid"] - }, - { - "firstName": "Sherlock", - "lastName": "Holmes", - "number": "0487345643", - "likes": ["Intriguing Cases", "Violin"] - }, - { - "firstName": "Kristian", - "lastName": "Vos", - "number": "unknown", - "likes": ["JavaScript", "Gaming", "Foxes"] - }, +const contacts = [ + { + firstName: "Akira", + lastName: "Laine", + number: "0543236543", + likes: ["Pizza", "Coding", "Brownie Points"], + }, + { + firstName: "Harry", + lastName: "Potter", + number: "0994372684", + likes: ["Hogwarts", "Magic", "Hagrid"], + }, + { + firstName: "Sherlock", + lastName: "Holmes", + number: "0487345643", + likes: ["Intriguing Cases", "Violin"], + }, + { + firstName: "Kristian", + lastName: "Vos", + number: "unknown", + likes: ["JavaScript", "Gaming", "Foxes"], + }, ]; - - -//Write your function in between these comments -function lookUpProfile(name, prop){ - for(var i in contacts){ - if(contacts[i].firstName === name) { - return contacts[i][prop] || "No such property"; - } +function lookUpProfile(name, prop) { + for (let i in contacts) { + if (contacts[i].firstName === name) { + return contacts[i][prop] || "No such property"; } - return "No such contact"; + } + return "No such contact"; } -//Write your function in between these comments - -lookUpProfile("Akira", "likes"); ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/quoting-strings-with-single-quotes.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/quoting-strings-with-single-quotes.md index 02eb073a9b..5854d92ad4 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/quoting-strings-with-single-quotes.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/quoting-strings-with-single-quotes.md @@ -12,21 +12,21 @@ dashedName: quoting-strings-with-single-quotes Los valores de cadena en JavaScript pueden escribirse con comillas simples o dobles, siempre y cuando comiencen y terminen con el mismo tipo de comillas. A diferencia de otros lenguajes de programación, las comillas simples y dobles funcionan igual en JavaScript. ```js -doubleQuoteStr = "This is a string"; -singleQuoteStr = 'This is also a string'; +const doubleQuoteStr = "This is a string"; +const singleQuoteStr = 'This is also a string'; ``` La razón por la que puedes querer usar un tipo de comilla sobre otro es si quieres usar ambos en una cadena. Esto puede suceder si quieres guardar una conversación en una cadena y tener la conversación entre comillas. Otro uso sería guardar una etiqueta `` con varios atributos entre comillas, todo dentro de una cadena. ```js -conversation = 'Finn exclaims to Jake, "Algebraic!"'; +const conversation = 'Finn exclaims to Jake, "Algebraic!"'; ``` Sin embargo, esto se convierte en un problema cuando es necesario utilizar las comillas externas dentro de ella. Recuerda, una cadena tiene el mismo tipo de comillas al principio y al final. Pero si tienes esa misma comilla en algún lugar del medio, la cadena se detendrá antes de tiempo y arrojará un error. ```js -goodStr = 'Jake asks Finn, "Hey, let\'s go on an adventure?"'; -badStr = 'Finn responds, "Let's go!"'; +const goodStr = 'Jake asks Finn, "Hey, let\'s go on an adventure?"'; +const badStr = 'Finn responds, "Let's go!"'; ``` Aquí `badStr` arrojará un error. @@ -71,11 +71,11 @@ assert(code.match(/"/g).length === 4 && code.match(/'/g).length === 2); ## --seed-contents-- ```js -var myStr = "Link"; +const myStr = "Link"; ``` # --solutions-- ```js -var myStr = 'Link'; +const myStr = 'Link'; ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/record-collection.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/record-collection.md index 5849fa8fbe..74d1e180a1 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/record-collection.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/record-collection.md @@ -115,7 +115,7 @@ const _recordCollection = { ```js // Setup -var recordCollection = { +const recordCollection = { 2548: { albumTitle: 'Slippery When Wet', artist: 'Bon Jovi', @@ -146,7 +146,7 @@ updateRecords(recordCollection, 5439, 'artist', 'ABBA'); # --solutions-- ```js -var recordCollection = { +const recordCollection = { 2548: { albumTitle: 'Slippery When Wet', artist: 'Bon Jovi', diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/replace-loops-using-recursion.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/replace-loops-using-recursion.md index 8974b3fd8b..891a471e0c 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/replace-loops-using-recursion.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/replace-loops-using-recursion.md @@ -14,9 +14,9 @@ La recursión es el concepto que una función puede expresarse en términos de s ```js function multiply(arr, n) { - var product = 1; - for (var i = 0; i < n; i++) { - product *= arr[i]; + let product = 1; + for (let i = 0; i < n; i++) { + product *= arr[i]; } return product; } diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/replacing-if-else-chains-with-switch.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/replacing-if-else-chains-with-switch.md index 1962d9e774..93d1594bc9 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/replacing-if-else-chains-with-switch.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/replacing-if-else-chains-with-switch.md @@ -108,7 +108,7 @@ assert(chainToSwitch(156) === ''); ```js function chainToSwitch(val) { - var answer = ""; + let answer = ""; // Only change code below this line if (val === "bob") { @@ -134,7 +134,7 @@ chainToSwitch(7); ```js function chainToSwitch(val) { - var answer = ""; + let answer = ""; switch(val) { case "bob": diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/return-a-value-from-a-function-with-return.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/return-a-value-from-a-function-with-return.md index d1f04efc87..6a3519ada7 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/return-a-value-from-a-function-with-return.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/return-a-value-from-a-function-with-return.md @@ -17,7 +17,8 @@ Podemos pasar valores a una función con argumentos. Puedes utilizar function plusThree(num) { return num + 3; } -var answer = plusThree(5); + +const answer = plusThree(5); ``` `answer` tiene el valor `8`. diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/selecting-from-many-options-with-switch-statements.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/selecting-from-many-options-with-switch-statements.md index 3a543cb78f..50dbad3f08 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/selecting-from-many-options-with-switch-statements.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/selecting-from-many-options-with-switch-statements.md @@ -78,7 +78,7 @@ assert(code.match(/break/g).length > 2); ```js function caseInSwitch(val) { - var answer = ""; + let answer = ""; // Only change code below this line @@ -94,7 +94,7 @@ caseInSwitch(1); ```js function caseInSwitch(val) { - var answer = ""; + let answer = ""; switch(val) { case 1: diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/shopping-list.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/shopping-list.md index 5ad68ad924..b871e40ca0 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/shopping-list.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/shopping-list.md @@ -81,13 +81,13 @@ var hasNumber = false; ## --seed-contents-- ```js -var myList = []; +const myList = []; ``` # --solutions-- ```js -var myList = [ +const myList = [ ["Candy", 10], ["Potatoes", 12], ["Eggs", 12], diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/stand-in-line.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/stand-in-line.md index f9cd3b33ea..919821a26a 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/stand-in-line.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/stand-in-line.md @@ -93,12 +93,10 @@ function nextInLine(arr, item) { return item; // Only change code above this line - - } // Setup -var testArr = [1,2,3,4,5]; +const testArr = [1, 2, 3, 4, 5]; // Display code console.log("Before: " + JSON.stringify(testArr)); @@ -109,7 +107,7 @@ console.log("After: " + JSON.stringify(testArr)); # --solutions-- ```js -var testArr = [ 1,2,3,4,5]; +const testArr = [1, 2, 3, 4, 5]; function nextInLine(arr, item) { arr.push(item); diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/store-multiple-values-in-one-variable-using-javascript-arrays.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/store-multiple-values-in-one-variable-using-javascript-arrays.md index a0a41794b3..b44ecfdbd6 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/store-multiple-values-in-one-variable-using-javascript-arrays.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/store-multiple-values-in-one-variable-using-javascript-arrays.md @@ -14,7 +14,7 @@ Con las variables de arreglos (`array`) de JavaScript, podemos almacenar varios Inicias una declaración de arreglo con un corchete de apertura, lo terminas con un corchete de cierre, y pones una coma entre cada entrada, de esta forma: ```js -var sandwich = ["peanut butter", "jelly", "bread"] +const sandwich = ["peanut butter", "jelly", "bread"]; ``` # --instructions-- @@ -53,11 +53,11 @@ assert(typeof myArray[1] !== 'undefined' && typeof myArray[1] == 'number'); ```js // Only change code below this line -var myArray = []; +const myArray = []; ``` # --solutions-- ```js -var myArray = ["The Answer", 42]; +const myArray = ["The Answer", 42]; ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/subtract-one-number-from-another-with-javascript.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/subtract-one-number-from-another-with-javascript.md index bc9dbeea32..ee20d1e41b 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/subtract-one-number-from-another-with-javascript.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/subtract-one-number-from-another-with-javascript.md @@ -16,7 +16,7 @@ JavaScript utiliza el símbolo `-` para restar. **Ejemplo** ```js -myVar = 12 - 6; +const myVar = 12 - 6; ``` `myVar` tendrá el valor `6`. @@ -49,11 +49,11 @@ assert(/difference=45-33;?/.test(__helpers.removeWhiteSpace(code))); ## --seed-contents-- ```js -var difference = 45 - 0; +const difference = 45 - 0; ``` # --solutions-- ```js -var difference = 45 - 33; +const difference = 45 - 33; ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties.md index 49d3dd9a5d..43f63724a0 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties.md @@ -13,10 +13,11 @@ A veces es útil comprobar si existe o no la propiedad de un objeto dado. Podemo **Por ejemplo** ```js -var myObj = { +const myObj = { top: "hat", bottom: "pants" }; + myObj.hasOwnProperty("top"); myObj.hasOwnProperty("middle"); ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/understand-string-immutability.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/understand-string-immutability.md index a02754f7ce..f2df8c4d51 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/understand-string-immutability.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/understand-string-immutability.md @@ -14,14 +14,14 @@ En JavaScript, los valores de cadena (`String`) son inmutables, lo qu Por ejemplo, el siguiente código: ```js -var myStr = "Bob"; +let myStr = "Bob"; myStr[0] = "J"; ``` no puede cambiar el valor de `myStr` a `Job`, porque el contenido de `myStr` no puede ser alterado. Ten en cuenta que esto *no* significa que `myStr` no puede cambiarse, solo que los caracteres individuales de una cadena literal no pueden ser cambiados. La única forma de cambiar `myStr` sería asignarla con una nueva cadena, como esta: ```js -var myStr = "Bob"; +let myStr = "Bob"; myStr = "Job"; ``` @@ -55,7 +55,7 @@ assert(/myStr = "Jello World"/.test(code)); ```js // Setup -var myStr = "Jello World"; +let myStr = "Jello World"; // Only change code below this line myStr[0] = "H"; // Change this line @@ -65,6 +65,6 @@ myStr[0] = "H"; // Change this line # --solutions-- ```js -var myStr = "Jello World"; +let myStr = "Jello World"; myStr = "Hello World"; ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-boolean-values.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-boolean-values.md index 28f7f63820..9955a5dca9 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-boolean-values.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-boolean-values.md @@ -43,7 +43,6 @@ welcomeToBooleans(); ```js function welcomeToBooleans() { - // Only change code below this line return false; // Change this line diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-undefined-value-returned-from-a-function.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-undefined-value-returned-from-a-function.md index 38523e8d55..927b0d5dde 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-undefined-value-returned-from-a-function.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-undefined-value-returned-from-a-function.md @@ -14,10 +14,12 @@ Una función puede incluir la declaración de devolución (`return`) pero no tie **Ejemplo** ```js -var sum = 0; +let sum = 0; + function addSum(num) { sum = sum + num; } + addSum(3); ``` @@ -61,7 +63,7 @@ assert( ```js // Setup -var sum = 0; +let sum = 0; function addThree() { sum = sum + 3; @@ -79,7 +81,7 @@ addFive(); # --solutions-- ```js -var sum = 0; +let sum = 0; function addThree() { sum = sum + 3; diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/updating-object-properties.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/updating-object-properties.md index 2785ee3dbf..b72ddf979c 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/updating-object-properties.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/updating-object-properties.md @@ -14,7 +14,7 @@ Después de haber creado un objeto de JavaScript, puedes actualizar sus propieda Por ejemplo, veamos `ourDog`: ```js -var ourDog = { +const ourDog = { "name": "Camper", "legs": 4, "tails": 1, @@ -54,7 +54,7 @@ assert(/"name": "Coder"/.test(code)); ```js // Setup -var myDog = { +const myDog = { "name": "Coder", "legs": 4, "tails": 1, @@ -62,12 +62,13 @@ var myDog = { }; // Only change code below this line + ``` # --solutions-- ```js -var myDog = { +const myDog = { "name": "Coder", "legs": 4, "tails": 1, diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-nth-character-in-a-string.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-nth-character-in-a-string.md index 5218cfebd9..7e5ef9881d 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-nth-character-in-a-string.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-nth-character-in-a-string.md @@ -16,8 +16,8 @@ Recuerda que las computadoras empiezan a contar desde `0`, así que el primer ca Ejemplo: ```js -var firstName = "Ada"; -var secondLetterOfFirstName = firstName[1]; +const firstName = "Ada"; +const secondLetterOfFirstName = firstName[1]; ``` `secondLetterOfFirstName` tendrá una cadena con valor `d`. @@ -54,15 +54,15 @@ assert(code.match(/thirdLetterOfLastName\s*?=\s*?lastName\[.*?\]/)); ```js // Setup -var lastName = "Lovelace"; +const lastName = "Lovelace"; // Only change code below this line -var thirdLetterOfLastName = lastName; // Change this line +const thirdLetterOfLastName = lastName; // Change this line ``` # --solutions-- ```js -var lastName = "Lovelace"; -var thirdLetterOfLastName = lastName[2]; +const lastName = "Lovelace"; +const thirdLetterOfLastName = lastName[2]; ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/use-recursion-to-create-a-range-of-numbers.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/use-recursion-to-create-a-range-of-numbers.md index 40a5b6290a..dc86e0fd78 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/use-recursion-to-create-a-range-of-numbers.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/use-recursion-to-create-a-range-of-numbers.md @@ -73,7 +73,7 @@ function rangeOfNumbers(startNum, endNum) { if (endNum - startNum === 0) { return [startNum]; } else { - var numbers = rangeOfNumbers(startNum, endNum - 1); + const numbers = rangeOfNumbers(startNum, endNum - 1); numbers.push(endNum); return numbers; } diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function-with-a-radix.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function-with-a-radix.md index aa0a75306c..d90574d1e9 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function-with-a-radix.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function-with-a-radix.md @@ -20,7 +20,7 @@ parseInt(string, radix); Y aquí hay un ejemplo: ```js -var a = parseInt("11", 2); +const a = parseInt("11", 2); ``` La variable radix indica que `11` está en el sistema binario, o base 2. Este ejemplo convierte la cadena `11` a un entero `3`. diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function.md index 4f1936b480..0af0548647 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function.md @@ -12,7 +12,7 @@ dashedName: use-the-parseint-function La función `parseInt()` analiza una cadena y devuelve un entero. A continuación, te presentamos un ejemplo: ```js -var a = parseInt("007"); +const a = parseInt("007"); ``` La función anterior convierte la cadena `007` al entero `7`. Si el primer carácter de la cadena no puede ser convertido en un número, entonces devuelve `NaN`. diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/using-objects-for-lookups.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/using-objects-for-lookups.md index b5b5de152b..406b150664 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/using-objects-for-lookups.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/using-objects-for-lookups.md @@ -14,7 +14,7 @@ Los objetos pueden ser considerados como un almacenamiento clave/valor, como un Aquí hay un ejemplo de una simple búsqueda de alfabeto inverso: ```js -var alpha = { +const alpha = { 1:"Z", 2:"Y", 3:"X", @@ -24,10 +24,11 @@ var alpha = { 25:"B", 26:"A" }; + alpha[2]; alpha[24]; -var value = 2; +const value = 2; alpha[value]; ``` @@ -102,7 +103,7 @@ assert( ```js // Setup function phoneticLookup(val) { - var result = ""; + let result = ""; // Only change code below this line switch(val) { @@ -136,9 +137,9 @@ phoneticLookup("charlie"); ```js function phoneticLookup(val) { - var result = ""; + let result = ""; - var lookup = { + const lookup = { alpha: "Adams", bravo: "Boston", charlie: "Chicago", diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/word-blanks.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/word-blanks.md index 6eae3b7f02..79b3ba8826 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/word-blanks.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/basic-javascript/word-blanks.md @@ -16,7 +16,7 @@ En un juego de "Mad Libs", se te proporcionan oraciones con algunas palabras fal Considera esta oración: It was really **\_\_\_\_**, and we **\_\_\_\_** ourselves **\_\_\_\_**. Esta oración tiene tres piezas faltantes: un adjetivo, un verbo y un adverbio, y podemos añadir palabras de nuestra elección para completarla. A continuación, podemos asignar la oración completa a una variable de la siguiente manera: ```js -var sentence = "It was really " + "hot" + ", and we " + "laughed" + " ourselves " + "silly" + "."; +const sentence = "It was really " + "hot" + ", and we " + "laughed" + " ourselves " + "silly" + "."; ``` # --instructions-- @@ -84,24 +84,24 @@ const removeAssignments = str => str ## --seed-contents-- ```js -var myNoun = "dog"; -var myAdjective = "big"; -var myVerb = "ran"; -var myAdverb = "quickly"; +const myNoun = "dog"; +const myAdjective = "big"; +const myVerb = "ran"; +const myAdverb = "quickly"; // Only change code below this line -var wordBlanks = ""; // Change this line +const wordBlanks = ""; // Change this line // Only change code above this line ``` # --solutions-- ```js -var myNoun = "dog"; -var myAdjective = "big"; -var myVerb = "ran"; -var myAdverb = "quickly"; +const myNoun = "dog"; +const myAdjective = "big"; +const myVerb = "ran"; +const myAdverb = "quickly"; -var wordBlanks = "Once there was a " + myNoun + " which was very " + myAdjective + ". "; +let wordBlanks = "Once there was a " + myNoun + " which was very " + myAdjective + ". "; wordBlanks += "It " + myVerb + " " + myAdverb + " around the yard."; ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/add-elements-to-the-end-of-an-array-using-concat-instead-of-push.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/add-elements-to-the-end-of-an-array-using-concat-instead-of-push.md index 2369749346..1310e07693 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/add-elements-to-the-end-of-an-array-using-concat-instead-of-push.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/add-elements-to-the-end-of-an-array-using-concat-instead-of-push.md @@ -13,7 +13,7 @@ La programación funcional consiste en crear y utilizar funciones no mutantes. El último desafío introdujo el método `concat` como una forma de combinar arreglos en uno nuevo sin mutar los arreglos originales. Compara `concat` con el método `push`. `push` añade un elemento al final del arreglo desde el que se llama, lo cual muta ese arreglo. Aquí hay un ejemplo: ```js -var arr = [1, 2, 3]; +const arr = [1, 2, 3]; arr.push([4, 5, 6]); ``` @@ -71,8 +71,9 @@ function nonMutatingPush(original, newItem) { // Only change code above this line } -var first = [1, 2, 3]; -var second = [4, 5]; + +const first = [1, 2, 3]; +const second = [4, 5]; nonMutatingPush(first, second); ``` @@ -82,7 +83,6 @@ nonMutatingPush(first, second); function nonMutatingPush(original, newItem) { return original.concat(newItem); } -var first = [1, 2, 3]; -var second = [4, 5]; -nonMutatingPush(first, second); +const first = [1, 2, 3]; +const second = [4, 5]; ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs.md index b2d3672f33..3afd2aaf53 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs.md @@ -77,7 +77,6 @@ function urlSlug(title) { # --solutions-- ```js -// Only change code below this line function urlSlug(title) { return title.trim().split(/\s+/).join("-").toLowerCase(); } diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/avoid-mutations-and-side-effects-using-functional-programming.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/avoid-mutations-and-side-effects-using-functional-programming.md index 69d19937cc..fd864b7935 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/avoid-mutations-and-side-effects-using-functional-programming.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/avoid-mutations-and-side-effects-using-functional-programming.md @@ -57,9 +57,9 @@ La función `incrementer` debe devolver un valor basado en el valor de la variab ```js // The global variable -var fixedValue = 4; +let fixedValue = 4; -function incrementer () { +function incrementer() { // Only change code below this line @@ -70,7 +70,7 @@ function incrementer () { # --solutions-- ```js -var fixedValue = 4 +let fixedValue = 4 function incrementer() { return fixedValue + 1 diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/combine-an-array-into-a-string-using-the-join-method.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/combine-an-array-into-a-string-using-the-join-method.md index 4212cdfa64..259cb36d58 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/combine-an-array-into-a-string-using-the-join-method.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/combine-an-array-into-a-string-using-the-join-method.md @@ -13,8 +13,8 @@ El método `join` se utiliza para unir los elementos de un arreglo creando una c Aquí hay un ejemplo: ```js -var arr = ["Hello", "World"]; -var str = arr.join(" "); +const arr = ["Hello", "World"]; +const str = arr.join(" "); ``` `str` tendrá una cadena con valor `Hello World`. @@ -76,6 +76,7 @@ function sentensify(str) { // Only change code above this line } + sentensify("May-the-force-be-with-you"); ``` @@ -83,8 +84,6 @@ sentensify("May-the-force-be-with-you"); ```js function sentensify(str) { - // Only change code below this line return str.split(/\W/).join(' '); - // Only change code above this line } ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/combine-two-arrays-using-the-concat-method.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/combine-two-arrays-using-the-concat-method.md index 5e37c124d5..093ca3c21b 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/combine-two-arrays-using-the-concat-method.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/combine-two-arrays-using-the-concat-method.md @@ -60,8 +60,9 @@ function nonMutatingConcat(original, attach) { // Only change code above this line } -var first = [1, 2, 3]; -var second = [4, 5]; + +const first = [1, 2, 3]; +const second = [4, 5]; nonMutatingConcat(first, second); ``` @@ -69,11 +70,8 @@ nonMutatingConcat(first, second); ```js function nonMutatingConcat(original, attach) { - // Only change code below this line return original.concat(attach); - // Only change code above this line } -var first = [1, 2, 3]; -var second = [4, 5]; -nonMutatingConcat(first, second); +const first = [1, 2, 3]; +const second = [4, 5]; ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype.md index a40f53303a..949663b2e8 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype.md @@ -38,17 +38,17 @@ assert(!code.match(/\.?[\s\S]*?map/g)); ```js // The global variable -var s = [23, 65, 98, 5]; +const s = [23, 65, 98, 5]; Array.prototype.myMap = function(callback) { - var newArray = []; + const newArray = []; // Only change code below this line // Only change code above this line return newArray; }; -var new_s = s.myMap(function(item) { +const new_s = s.myMap(function(item) { return item * 2; }); ``` @@ -56,20 +56,17 @@ var new_s = s.myMap(function(item) { # --solutions-- ```js -// the global Array -var s = [23, 65, 98, 5]; +const s = [23, 65, 98, 5]; Array.prototype.myMap = function(callback) { - var newArray = []; - // Only change code below this line - for (var elem of this) { + const newArray = []; + for (const elem of this) { newArray.push(callback(elem)); } - // Only change code above this line return newArray; }; -var new_s = s.myMap(function(item) { +const new_s = s.myMap(function(item) { return item * 2; }); ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/implement-the-filter-method-on-a-prototype.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/implement-the-filter-method-on-a-prototype.md index ebe22f322d..4d8ff981d3 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/implement-the-filter-method-on-a-prototype.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/implement-the-filter-method-on-a-prototype.md @@ -34,16 +34,16 @@ assert(!code.match(/\.?[\s\S]*?filter/g)); ```js // The global variable -var s = [23, 65, 98, 5]; +const s = [23, 65, 98, 5]; Array.prototype.myFilter = function(callback) { // Only change code below this line - var newArray = []; + const newArray = []; // Only change code above this line return newArray; }; -var new_s = s.myFilter(function(item) { +const new_s = s.myFilter(function(item) { return item % 2 === 1; }); ``` @@ -51,20 +51,17 @@ var new_s = s.myFilter(function(item) { # --solutions-- ```js -// the global Array -var s = [23, 65, 98, 5]; +const s = [23, 65, 98, 5]; Array.prototype.myFilter = function(callback) { - var newArray = []; - // Only change code below this line + const newArray = []; for (let i = 0; i < this.length; i++) { if (callback(this[i])) newArray.push(this[i]); } - // Only change code above this line return newArray; }; -var new_s = s.myFilter(function(item) { +const new_s = s.myFilter(function(item) { return item % 2 === 1; }); ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/introduction-to-currying-and-partial-application.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/introduction-to-currying-and-partial-application.md index 4b0ae1f192..16f2d4b588 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/introduction-to-currying-and-partial-application.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/introduction-to-currying-and-partial-application.md @@ -35,7 +35,7 @@ curried(1)(2) Esto es útil en tu programa si no puedes proporcionar todos los argumentos a una función al mismo tiempo. Puedes guardar la llamada a cada función dentro de una variable, la cual mantendrá la referencia de la función devuelta que toma el siguiente argumento cuando este disponible. Aquí hay un ejemplo utilizando la función currificada del ejemplo anterior: ```js -var funcForY = curried(1); +const funcForY = curried(1); console.log(funcForY(2)); // 3 ``` @@ -45,7 +45,8 @@ Similarmente, la aplicación de una función parcial puede describirs function impartial(x, y, z) { return x + y + z; } -var partialFn = impartial.bind(this, 1, 2); + +const partialFn = impartial.bind(this, 1, 2); partialFn(10); // 13 ``` @@ -90,6 +91,7 @@ function add(x) { // Only change code above this line } + add(10)(20)(30); ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/pass-arguments-to-avoid-external-dependence-in-a-function.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/pass-arguments-to-avoid-external-dependence-in-a-function.md index e0a87646aa..1cc861e941 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/pass-arguments-to-avoid-external-dependence-in-a-function.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/pass-arguments-to-avoid-external-dependence-in-a-function.md @@ -53,10 +53,10 @@ assert(__newValue === 5); ```js // The global variable -var fixedValue = 4; +let fixedValue = 4; // Only change code below this line -function incrementer () { +function incrementer() { // Only change code above this line @@ -66,15 +66,9 @@ function incrementer () { # --solutions-- ```js -// The global variable -var fixedValue = 4; +let fixedValue = 4; -// Only change code below this line -function incrementer (fixedValue) { +function incrementer(fixedValue) { return fixedValue + 1; - - // Only change code above this line } - - ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/remove-elements-from-an-array-using-slice-instead-of-splice.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/remove-elements-from-an-array-using-slice-instead-of-splice.md index fe201c8f62..188c50d7a4 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/remove-elements-from-an-array-using-slice-instead-of-splice.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/remove-elements-from-an-array-using-slice-instead-of-splice.md @@ -11,7 +11,7 @@ dashedName: remove-elements-from-an-array-using-slice-instead-of-splice Un patrón común al trabajar con arreglos es cuando deseas eliminar elementos y conservar el resto del arreglo. JavaScript ofrece el método `splice` para esto, que toma argumentos para el índice de dónde comenzar a eliminar elementos, luego la cantidad de elementos para eliminar. Si no se proporciona el segundo argumento, el valor predeterminado es eliminar elementos hasta el final. Sin embargo, el método `splice` muta el arreglo original en el que se llama. Por ejemplo: ```js -var cities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"]; +const cities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"]; cities.splice(3, 1); ``` @@ -69,7 +69,8 @@ function nonMutatingSplice(cities) { // Only change code above this line } -var inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"]; + +const inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"]; nonMutatingSplice(inputCities); ``` @@ -77,10 +78,7 @@ nonMutatingSplice(inputCities); ```js function nonMutatingSplice(cities) { - // Only change code below this line return cities.slice(0,3); - // Only change code above this line } -var inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"]; -nonMutatingSplice(inputCities); +const inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"]; ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/return-a-sorted-array-without-changing-the-original-array.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/return-a-sorted-array-without-changing-the-original-array.md index a55fb82f7b..14466e332d 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/return-a-sorted-array-without-changing-the-original-array.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/return-a-sorted-array-without-changing-the-original-array.md @@ -68,24 +68,23 @@ assert(JSON.stringify(nonMutatingSort([140000, 104, 99])) === ## --seed-contents-- ```js -var globalArray = [5, 6, 3, 2, 9]; +const globalArray = [5, 6, 3, 2, 9]; + function nonMutatingSort(arr) { // Only change code below this line // Only change code above this line } + nonMutatingSort(globalArray); ``` # --solutions-- ```js -var globalArray = [5, 6, 3, 2, 9]; +const globalArray = [5, 6, 3, 2, 9]; function nonMutatingSort(arr) { - // Only change code below this line return [].concat(arr).sort((a,b) => a-b); - // Only change code above this line } -nonMutatingSort(globalArray); ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/return-part-of-an-array-using-the-slice-method.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/return-part-of-an-array-using-the-slice-method.md index ac5c9b90eb..c64fccc162 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/return-part-of-an-array-using-the-slice-method.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/return-part-of-an-array-using-the-slice-method.md @@ -13,8 +13,8 @@ El método `slice` devuelve una copia de ciertos elementos de un arreglo. Puede Por ejemplo: ```js -var arr = ["Cat", "Dog", "Tiger", "Zebra"]; -var newArray = arr.slice(1, 3); +const arr = ["Cat", "Dog", "Tiger", "Zebra"]; +const newArray = arr.slice(1, 3); ``` `newArray` tendría el valor de `["Dog", "Tiger"]`. @@ -78,7 +78,8 @@ function sliceArray(anim, beginSlice, endSlice) { // Only change code above this line } -var inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"]; + +const inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"]; sliceArray(inputAnim, 1, 3); ``` @@ -86,10 +87,7 @@ sliceArray(inputAnim, 1, 3); ```js function sliceArray(anim, beginSlice, endSlice) { - // Only change code below this line - return anim.slice(beginSlice, endSlice) - // Only change code above this line + return anim.slice(beginSlice, endSlice); } -var inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"]; -sliceArray(inputAnim, 1, 3); +const inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"]; ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/sort-an-array-alphabetically-using-the-sort-method.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/sort-an-array-alphabetically-using-the-sort-method.md index 00319a5f38..169a9c8a3d 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/sort-an-array-alphabetically-using-the-sort-method.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/sort-an-array-alphabetically-using-the-sort-method.md @@ -18,6 +18,7 @@ function ascendingOrder(arr) { return a - b; }); } + ascendingOrder([1, 5, 2, 3, 4]); ``` @@ -29,6 +30,7 @@ function reverseAlpha(arr) { return a === b ? 0 : a < b ? 1 : -1; }); } + reverseAlpha(['l', 'h', 'z', 'b', 's']); ``` @@ -86,6 +88,7 @@ function alphabeticalOrder(arr) { return arr // Only change code above this line } + alphabeticalOrder(["a", "d", "c", "a", "z", "g"]); ``` @@ -93,9 +96,6 @@ alphabeticalOrder(["a", "d", "c", "a", "z", "g"]); ```js function alphabeticalOrder(arr) { - // Only change code below this line return arr.sort(); - // Only change code above this line } -alphabeticalOrder(["a", "d", "c", "a", "z", "g"]); ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/split-a-string-into-an-array-using-the-split-method.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/split-a-string-into-an-array-using-the-split-method.md index 3b0a35f278..c701217f92 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/split-a-string-into-an-array-using-the-split-method.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/split-a-string-into-an-array-using-the-split-method.md @@ -13,11 +13,11 @@ El método `split` divide una cadena en un arreglo de cadenas. Se necesita un ar Aquí hay dos ejemplos que dividen una cadena por espacios, luego otra por dígitos utilizando una expresión regular: ```js -var str = "Hello World"; -var bySpace = str.split(" "); +const str = "Hello World"; +const bySpace = str.split(" "); -var otherString = "How9are7you2today"; -var byDigits = otherString.split(/\d/); +const otherString = "How9are7you2today"; +const byDigits = otherString.split(/\d/); ``` `bySpace` tendrá el valor `["Hello", "World"]` y `byDigits` tendrá el valor `["How", "are", "you", "today"]`. @@ -74,6 +74,7 @@ function splitify(str) { // Only change code above this line } + splitify("Hello World,I-am code"); ``` @@ -81,8 +82,6 @@ splitify("Hello World,I-am code"); ```js function splitify(str) { - // Only change code below this line return str.split(/\W/); - // Only change code above this line } ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/understand-the-hazards-of-using-imperative-code.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/understand-the-hazards-of-using-imperative-code.md index 218998d858..0db9abe2e8 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/understand-the-hazards-of-using-imperative-code.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/understand-the-hazards-of-using-imperative-code.md @@ -59,29 +59,29 @@ assert.deepEqual(finalTabs.tabs, [ ```js // tabs is an array of titles of each site open within the window -var Window = function(tabs) { +const Window = function(tabs) { this.tabs = tabs; // We keep a record of the array inside the object }; // When you join two windows into one window -Window.prototype.join = function (otherWindow) { +Window.prototype.join = function(otherWindow) { this.tabs = this.tabs.concat(otherWindow.tabs); return this; }; // When you open a new tab at the end -Window.prototype.tabOpen = function (tab) { +Window.prototype.tabOpen = function(tab) { this.tabs.push('new tab'); // Let's open a new tab for now return this; }; // When you close a tab -Window.prototype.tabClose = function (index) { +Window.prototype.tabClose = function(index) { // Only change code below this line - var tabsBeforeIndex = this.tabs.splice(0, index); // Get the tabs before the tab - var tabsAfterIndex = this.tabs.splice(index + 1); // Get the tabs after the tab + const tabsBeforeIndex = this.tabs.splice(0, index); // Get the tabs before the tab + const tabsAfterIndex = this.tabs.splice(index + 1); // Get the tabs after the tab this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // Join them together @@ -91,12 +91,12 @@ Window.prototype.tabClose = function (index) { }; // Let's create three browser windows -var workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); // Your mailbox, drive, and other work sites -var socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); // Social sites -var videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); // Entertainment sites +const workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); // Your mailbox, drive, and other work sites +const socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); // Social sites +const videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); // Entertainment sites // Now perform the tab opening, closing, and other operations -var finalTabs = socialWindow +const finalTabs = socialWindow .tabOpen() // Open a new tab for cat memes .join(videoWindow.tabClose(2)) // Close third tab in video window, and join .join(workWindow.tabClose(1).tabOpen()); @@ -106,40 +106,34 @@ console.log(finalTabs.tabs); # --solutions-- ```js -// tabs is an array of titles of each site open within the window -var Window = function(tabs) { - this.tabs = tabs; // We keep a record of the array inside the object +const Window = function(tabs) { + this.tabs = tabs; }; -// When you join two windows into one window -Window.prototype.join = function (otherWindow) { +Window.prototype.join = function(otherWindow) { this.tabs = this.tabs.concat(otherWindow.tabs); return this; }; -// When you open a new tab at the end -Window.prototype.tabOpen = function (tab) { - this.tabs.push('new tab'); // Let's open a new tab for now +Window.prototype.tabOpen = function(tab) { + this.tabs.push('new tab'); return this; }; -// When you close a tab -Window.prototype.tabClose = function (index) { - var tabsBeforeIndex = this.tabs.slice(0, index); // Get the tabs before the tab - var tabsAfterIndex = this.tabs.slice(index + 1); // Get the tabs after the tab +Window.prototype.tabClose = function(index) { + const tabsBeforeIndex = this.tabs.slice(0, index); + const tabsAfterIndex = this.tabs.slice(index + 1); - this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // Join them together + this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); return this; }; -// Let's create three browser windows -var workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); // Your mailbox, drive, and other work sites -var socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); // Social sites -var videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); // Entertainment sites +const workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); +const socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); +const videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); -// Now perform the tab opening, closing, and other operations -var finalTabs = socialWindow - .tabOpen() // Open a new tab for cat memes - .join(videoWindow.tabClose(2)) // Close third tab in video window, and join +const finalTabs = socialWindow + .tabOpen() + .join(videoWindow.tabClose(2)) .join(workWindow.tabClose(1).tabOpen()); ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria.md index 7e746cd33c..a4bbb2bd69 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria.md @@ -13,7 +13,8 @@ El método `every` funciona con arreglos para comprobar si *every element* pasa Por ejemplo, el siguiente código comprobaría si cada elemento en el arreglo `numbers` es menor a 10: ```js -var numbers = [1, 5, 8, 0, 10, 11]; +const numbers = [1, 5, 8, 0, 10, 11]; + numbers.every(function(currentValue) { return currentValue < 10; }); @@ -62,6 +63,7 @@ function checkPositive(arr) { // Only change code above this line } + checkPositive([1, 2, 3, -4, 5]); ``` @@ -69,9 +71,6 @@ checkPositive([1, 2, 3, -4, 5]); ```js function checkPositive(arr) { - // Only change code below this line return arr.every(num => num > 0); - // Only change code above this line } -checkPositive([1, 2, 3, -4, 5]); ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/use-the-reduce-method-to-analyze-data.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/use-the-reduce-method-to-analyze-data.md index 4e52ed1165..f3d3aac7bc 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/use-the-reduce-method-to-analyze-data.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/use-the-reduce-method-to-analyze-data.md @@ -93,7 +93,7 @@ assert(getRating(watchList.filter((_, i) => i < 1 || i > 2)) === 8.55); ```js // The global variable -var watchList = [ +const watchList = [ { "Title": "Inception", "Year": "2010", @@ -206,22 +206,22 @@ var watchList = [ } ]; -function getRating(watchList){ +function getRating(watchList) { // Only change code below this line - var averageRating; + let averageRating; // Only change code above this line return averageRating; } + console.log(getRating(watchList)); ``` # --solutions-- ```js -// The global variable -var watchList = [ +const watchList = [ { "Title": "Inception", "Year": "2010", @@ -334,8 +334,8 @@ var watchList = [ } ]; -function getRating(watchList){ - var averageRating; +function getRating(watchList) { + let averageRating; const rating = watchList .filter(obj => obj.Director === "Christopher Nolan") .map(obj => Number(obj.imdbRating)); diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/use-the-some-method-to-check-that-any-elements-in-an-array-meet-a-criteria.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/use-the-some-method-to-check-that-any-elements-in-an-array-meet-a-criteria.md index efeffa6c6c..3673e4b4d5 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/use-the-some-method-to-check-that-any-elements-in-an-array-meet-a-criteria.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/functional-programming/use-the-some-method-to-check-that-any-elements-in-an-array-meet-a-criteria.md @@ -13,7 +13,8 @@ El método `some` funciona con arreglos para comprobar si *algún* elemento pasa Por ejemplo, el siguiente código comprobará si algún elemento en el arreglo `numbers` es menor que 10: ```js -var numbers = [10, 50, 8, 220, 110, 11]; +const numbers = [10, 50, 8, 220, 110, 11]; + numbers.some(function(currentValue) { return currentValue < 10; }); @@ -62,6 +63,7 @@ function checkPositive(arr) { // Only change code above this line } + checkPositive([1, 2, 3, -4, 5]); ``` @@ -69,9 +71,6 @@ checkPositive([1, 2, 3, -4, 5]); ```js function checkPositive(arr) { - // Only change code below this line return arr.some(elem => elem > 0); - // Only change code above this line } -checkPositive([1, 2, 3, -4, 5]); ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays.md index 056817c90c..f3a462f1b7 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays.md @@ -157,7 +157,7 @@ assert(diffArray([1, 'calf', 3, 'piglet'], [7, 'filly']).length === 6); ```js function diffArray(arr1, arr2) { - var newArr = []; + const newArr = []; return newArr; } @@ -168,13 +168,12 @@ diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]); ```js function diffArray(arr1, arr2) { - var newArr = []; - var h1 = Object.create(null); + const newArr = []; + const h1 = Object.create(null); arr1.forEach(function(e) { h1[e] = e; }); - - var h2 = Object.create(null); + const h2 = Object.create(null); arr2.forEach(function(e) { h2[e] = e; }); diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/make-a-person.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/make-a-person.md index 1f829d2b21..5c477dd5f8 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/make-a-person.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/make-a-person.md @@ -148,7 +148,7 @@ if(bob){ ## --seed-contents-- ```js -var Person = function(firstAndLast) { +const Person = function(firstAndLast) { // Only change code below this line // Complete the method below and implement the others similarly this.getFullName = function() { @@ -157,16 +157,16 @@ var Person = function(firstAndLast) { return firstAndLast; }; -var bob = new Person('Bob Ross'); +const bob = new Person('Bob Ross'); bob.getFullName(); ``` # --solutions-- ```js -var Person = function(firstAndLast) { +const Person = function(firstAndLast) { - var firstName, lastName; + let firstName, lastName; function updateName(str) { firstName = str.split(" ")[0]; @@ -201,6 +201,6 @@ var Person = function(firstAndLast) { }; }; -var bob = new Person('Bob Ross'); +const bob = new Person('Bob Ross'); bob.getFullName(); ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/map-the-debris.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/map-the-debris.md index fb35ce9597..d6dd3dd0ec 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/map-the-debris.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/map-the-debris.md @@ -51,8 +51,8 @@ assert.deepEqual( ```js function orbitalPeriod(arr) { - var GM = 398600.4418; - var earthRadius = 6367.4447; + const GM = 398600.4418; + const earthRadius = 6367.4447; return arr; } @@ -63,9 +63,9 @@ orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]); ```js function orbitalPeriod(arr) { - var GM = 398600.4418; - var earthRadius = 6367.4447; - var TAU = 2 * Math.PI; + const GM = 398600.4418; + const earthRadius = 6367.4447; + const TAU = 2 * Math.PI; return arr.map(function(obj) { return { name: obj.name, @@ -73,6 +73,4 @@ function orbitalPeriod(arr) { }; }); } - -orbitalPeriod([{name : "sputkin", avgAlt : 35873.5553}]); ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple.md index f408686531..e139bc8c50 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple.md @@ -61,7 +61,6 @@ function smallestCommons(arr) { return arr; } - smallestCommons([1,5]); ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou.md index 94aa8c67ca..40c02fa062 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou.md @@ -103,7 +103,7 @@ assert.deepEqual( ```js function whatIsInAName(collection, source) { - var arr = []; + const arr = []; // Only change code below this line @@ -118,8 +118,8 @@ whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: ```js function whatIsInAName(collection, source) { - var arr = []; - var keys = Object.keys(source); + const arr = []; + const keys = Object.keys(source); collection.forEach(function(e) { if(keys.every(function(key) {return e[key] === source[key];})) { arr.push(e); diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/caesars-cipher.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/caesars-cipher.md index cf8a206db7..06bd0ee5bb 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/caesars-cipher.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/caesars-cipher.md @@ -51,7 +51,6 @@ assert( ```js function rot13(str) { - return str; } diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/cash-register.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/cash-register.md index 0ed764ff53..252b036d14 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/cash-register.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/cash-register.md @@ -186,7 +186,7 @@ assert.deepEqual( ```js function checkCashRegister(price, cash, cid) { - var change; + let change; return change; } @@ -196,54 +196,57 @@ checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], [ # --solutions-- ```js -var denom = [ - { name: 'ONE HUNDRED', val: 100}, - { name: 'TWENTY', val: 20}, - { name: 'TEN', val: 10}, - { name: 'FIVE', val: 5}, - { name: 'ONE', val: 1}, - { name: 'QUARTER', val: 0.25}, - { name: 'DIME', val: 0.1}, - { name: 'NICKEL', val: 0.05}, - { name: 'PENNY', val: 0.01} +const denom = [ + { name: "ONE HUNDRED", val: 100 }, + { name: "TWENTY", val: 20 }, + { name: "TEN", val: 10 }, + { name: "FIVE", val: 5 }, + { name: "ONE", val: 1 }, + { name: "QUARTER", val: 0.25 }, + { name: "DIME", val: 0.1 }, + { name: "NICKEL", val: 0.05 }, + { name: "PENNY", val: 0.01 }, ]; function checkCashRegister(price, cash, cid) { - var output = {status: null, change: []}; - var change = cash - price; - var register = cid.reduce(function(acc, curr) { - acc.total += curr[1]; - acc[curr[0]] = curr[1]; - return acc; - }, {total: 0}); - if(register.total === change) { - output.status = 'CLOSED'; - output.change = cid; - return output; - } - if(register.total < change) { - output.status = 'INSUFFICIENT_FUNDS'; - return output; - } - var change_arr = denom.reduce(function(acc, curr) { - var value = 0; - while(register[curr.name] > 0 && change >= curr.val) { - change -= curr.val; - register[curr.name] -= curr.val; - value += curr.val; - change = Math.round(change * 100) / 100; - } - if(value > 0) { - acc.push([ curr.name, value ]); - } - return acc; - }, []); - if(change_arr.length < 1 || change > 0) { - output.status = 'INSUFFICIENT_FUNDS'; - return output; - } - output.status = 'OPEN'; - output.change = change_arr; - return output; + const output = { status: null, change: [] }; + let change = cash - price; + const register = cid.reduce( + function (acc, curr) { + acc.total += curr[1]; + acc[curr[0]] = curr[1]; + return acc; + }, + { total: 0 } + ); + if (register.total === change) { + output.status = "CLOSED"; + output.change = cid; + return output; + } + if (register.total < change) { + output.status = "INSUFFICIENT_FUNDS"; + return output; + } + const change_arr = denom.reduce(function (acc, curr) { + let value = 0; + while (register[curr.name] > 0 && change >= curr.val) { + change -= curr.val; + register[curr.name] -= curr.val; + value += curr.val; + change = Math.round(change * 100) / 100; + } + if (value > 0) { + acc.push([curr.name, value]); + } + return acc; + }, []); + if (change_arr.length < 1 || change > 0) { + output.status = "INSUFFICIENT_FUNDS"; + return output; + } + output.status = "OPEN"; + output.change = change_arr; + return output; } ``` diff --git a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/palindrome-checker.md b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/palindrome-checker.md index 21389cd239..d2ddb307be 100644 --- a/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/palindrome-checker.md +++ b/curriculum/challenges/espanol/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/palindrome-checker.md @@ -107,8 +107,6 @@ function palindrome(str) { return true; } - - palindrome("eye"); ``` diff --git a/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/chain-middleware-to-create-a-time-server.md b/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/chain-middleware-to-create-a-time-server.md index d68ab003f3..4f93504b33 100644 --- a/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/chain-middleware-to-create-a-time-server.md +++ b/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/chain-middleware-to-create-a-time-server.md @@ -1,6 +1,6 @@ --- id: 587d7fb1367417b2b2512bf4 -title: Chain Middleware to Create a Time Server +title: Encadenando Middlewares para crear un servidor horario challengeType: 2 forumTopicId: 301510 dashedName: chain-middleware-to-create-a-time-server @@ -8,9 +8,9 @@ dashedName: chain-middleware-to-create-a-time-server # --description-- -Middleware can be mounted at a specific route using `app.METHOD(path, middlewareFunction)`. Middleware can also be chained inside route definition. +Un middleware se puede montar en una ruta especifica usando `app.METHOD(path, middlewareFunction)`. El middleware también se puede encadenar dentro de la definición de la ruta. -Look at the following example: +Veamos el siguiente ejemplo: ```js app.get('/user', function(req, res, next) { @@ -21,17 +21,17 @@ app.get('/user', function(req, res, next) { }); ``` -This approach is useful to split the server operations into smaller units. That leads to a better app structure, and the possibility to reuse code in different places. This approach can also be used to perform some validation on the data. At each point of the middleware stack you can block the execution of the current chain and pass control to functions specifically designed to handle errors. Or you can pass control to the next matching route, to handle special cases. We will see how in the advanced Express section. +Este método es útil para dividir las operaciones del servidor en unidades más pequeñas. Lo que lleva a una mejor estructura de nuestra aplicación y a la posibilidad de reutilizar código en diferentes lugares. Este método también se puede utilizar para realizar ciertas validaciones de los datos. En cada punto de la pila del middleware puedes bloquear la ejecución de la cadena actual y darle el control a funciones diseñadas específicamente para el manejo de errores. O puedes pasar el control a la siguiente ruta que concuerde, para manejar casos especiales. Veremos cómo en la sección avanzada de Express. # --instructions-- -In the route `app.get('/now', ...)` chain a middleware function and the final handler. In the middleware function you should add the current time to the request object in the `req.time` key. You can use `new Date().toString()`. In the handler, respond with a JSON object, taking the structure `{time: req.time}`. +En la ruta `app.get('/now', ...)` encadena una función del middleware con el controlador final. En la función del middleware debes añadir la hora actual al objeto de petición en la clave `req.time`. Puedes utilizar `new Date().toString()`. En el controlador, responde con un objeto JSON, tomando la estructura `{time: req.time}`. -**Note:** The test will not pass if you don’t chain the middleware. If you mount the function somewhere else, the test will fail, even if the output result is correct. +**Nota:** La prueba no pasará si no encadenas el middleware. Si montas la función en otro lugar, la prueba fallará, incluso si el resultado de salida es correcto. # --hints-- -The /now endpoint should have mounted middleware +El endpoint /now debe tener el middleware montado ```js (getUserInput) => @@ -49,7 +49,7 @@ The /now endpoint should have mounted middleware ); ``` -The /now endpoint should return a time that is +/- 20 secs from now +El endpoint /now debe devolver un tiempo que es +/- 20 segundos a partir de este momento ```js (getUserInput) => diff --git a/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/get-data-from-post-requests.md b/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/get-data-from-post-requests.md index 8398c13973..3c471eb82c 100644 --- a/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/get-data-from-post-requests.md +++ b/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/get-data-from-post-requests.md @@ -1,6 +1,6 @@ --- id: 587d7fb2367417b2b2512bf8 -title: Get Data from POST Requests +title: Obtén datos de las peticiones POST challengeType: 2 forumTopicId: 301511 dashedName: get-data-from-post-requests @@ -8,27 +8,27 @@ dashedName: get-data-from-post-requests # --description-- -Mount a POST handler at the path `/name`. It’s the same path as before. We have prepared a form in the html frontpage. It will submit the same data of exercise 10 (Query string). If the body-parser is configured correctly, you should find the parameters in the object `req.body`. Have a look at the usual library example: +Monta un manejador POST en la ruta `/name`. Es la misma ruta de antes. Hemos preparado un formulario en la página principal html. Se enviarán los mismos datos del ejercicio 10 (Query string). Si el "body-parser" está configurado correctamente, debe encontrar los parámetros en el objeto `req.body`. Echa un vistazo al ejemplo de la biblioteca:
route: POST '/library'
urlencoded_body: userId=546&bookId=6754
req.body: {userId: '546', bookId: '6754'}
-Respond with the same JSON object as before: `{name: 'firstname lastname'}`. Test if your endpoint works using the html form we provided in the app frontpage. +Responde con el mismo objeto JSON que antes: `{name: 'firstname lastname'}`. Prueba si tu endpoint funciona usando el formulario html que proporcionamos en la página principal de la aplicación. -Tip: There are several other http methods other than GET and POST. And by convention there is a correspondence between the http verb, and the operation you are going to execute on the server. The conventional mapping is: +Nota: Hay varios métodos de http diferentes a GET y POST. Y por convención hay una correspondencia entre el verbo http y la operación que se va a ejecutar en el servidor. La asignación convencional es: -POST (sometimes PUT) - Create a new resource using the information sent with the request, +POST (a veces PUT): Crea un nuevo recurso usando la información enviada con la solicitud, -GET - Read an existing resource without modifying it, +GET: Lee un recurso existente sin modificarlo, -PUT or PATCH (sometimes POST) - Update a resource using the data sent, +PUT o PATCH (a veces POST): Actualiza un recurso usando los datos enviados, -DELETE => Delete a resource. +DELETE => Elimina un recurso. -There are also a couple of other methods which are used to negotiate a connection with the server. Except from GET, all the other methods listed above can have a payload (i.e. the data into the request body). The body-parser middleware works with these methods as well. +También hay un par de otros métodos que se utilizan para negociar una conexión con el servidor. A excepción de GET, todos los demás métodos mencionados anteriormente pueden tener un payload (es decir, los datos en el cuerpo de la solicitud). El middleware body-parser también funciona con estos métodos. # --hints-- -Test 1 : Your API endpoint should respond with the correct name +Prueba 1: El endpoint de tu API debe responder con el nombre correcto ```js (getUserInput) => @@ -46,7 +46,7 @@ Test 1 : Your API endpoint should respond with the correct name ); ``` -Test 2 : Your API endpoint should respond with the correct name +Prueba 2: El endpoint de tu API debe responder con el nombre correcto ```js (getUserInput) => diff --git a/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/get-query-parameter-input-from-the-client.md b/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/get-query-parameter-input-from-the-client.md index 0d301a9f5e..677e70b6dd 100644 --- a/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/get-query-parameter-input-from-the-client.md +++ b/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/get-query-parameter-input-from-the-client.md @@ -1,6 +1,6 @@ --- id: 587d7fb2367417b2b2512bf6 -title: Get Query Parameter Input from the Client +title: Obtén la entrada de parámetros de consulta del cliente challengeType: 2 forumTopicId: 301512 dashedName: get-query-parameter-input-from-the-client @@ -8,19 +8,19 @@ dashedName: get-query-parameter-input-from-the-client # --description-- -Another common way to get input from the client is by encoding the data after the route path, using a query string. The query string is delimited by a question mark (?), and includes field=value couples. Each couple is separated by an ampersand (&). Express can parse the data from the query string, and populate the object `req.query`. Some characters, like the percent (%), cannot be in URLs and have to be encoded in a different format before you can send them. If you use the API from JavaScript, you can use specific methods to encode/decode these characters. +Otra forma común de obtener la entrada del cliente es codificando los datos después de la ruta, usando una cadena de consulta. La cadena de consulta está delimitada por un signo de interrogación (?), e incluye parejas de campo=valor. Cada pareja está separada por un ampersand (&). Express puede analizar los datos de la cadena de consulta, y llenar el objeto `req.query`. Algunos caracteres, como el porcentaje (%), no pueden estar en URLs y tienen que ser codificados en un formato diferente antes de poder enviarlos. Si usas la API desde JavaScript, puedes usar métodos específicos para codificar/decodificar estos caracteres.
route_path: '/library'
actual_request_URL: '/library?userId=546&bookId=6754'
req.query: {userId: '546', bookId: '6754'}
# --instructions-- -Build an API endpoint, mounted at `GET /name`. Respond with a JSON document, taking the structure `{ name: 'firstname lastname'}`. The first and last name parameters should be encoded in a query string e.g. `?first=firstname&last=lastname`. +Construye un endpoint para el API, montado en `GET /name`. Responde con un documento JSON, tomando la estructura `{ name: 'firstname lastname'}`. Los parámetros del nombre y apellido deben codificarse en una cadena de consulta, por ejemplo, `?first=firstname&last=lastname`. -**Note:** In the following exercise you are going to receive data from a POST request, at the same `/name` route path. If you want, you can use the method `app.route(path).get(handler).post(handler)`. This syntax allows you to chain different verb handlers on the same path route. You can save a bit of typing, and have cleaner code. +**Nota:** En el siguiente ejercicio va a recibir datos de una solicitud POST, a la misma ruta `/name`. Si lo deseas, puedes utilizar el método `app.route(path).get(handler).post(handler)`. Esta sintaxis permite encadenar diferentes manejadores de verbos en la misma ruta. Puedes ahorrar un poco de escritura y tener un código más limpio. # --hints-- -Test 1 : Your API endpoint should respond with the correct name +Prueba 1: El endpoint de tu API debe responder con el nombre correcto ```js (getUserInput) => @@ -38,7 +38,7 @@ Test 1 : Your API endpoint should respond with the correct name ); ``` -Test 2 : Your API endpoint should respond with the correct name +Prueba 2: El endpoint de tu API debe responder con el nombre correcto ```js (getUserInput) => diff --git a/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/get-route-parameter-input-from-the-client.md b/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/get-route-parameter-input-from-the-client.md index b0055f569e..86b2649ef3 100644 --- a/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/get-route-parameter-input-from-the-client.md +++ b/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/get-route-parameter-input-from-the-client.md @@ -1,6 +1,6 @@ --- id: 587d7fb2367417b2b2512bf5 -title: Get Route Parameter Input from the Client +title: Obtén la entrada de parámetros de ruta del cliente challengeType: 2 forumTopicId: 301513 dashedName: get-route-parameter-input-from-the-client @@ -8,17 +8,17 @@ dashedName: get-route-parameter-input-from-the-client # --description-- -When building an API, we have to allow users to communicate to us what they want to get from our service. For example, if the client is requesting information about a user stored in the database, they need a way to let us know which user they're interested in. One possible way to achieve this result is by using route parameters. Route parameters are named segments of the URL, delimited by slashes (/). Each segment captures the value of the part of the URL which matches its position. The captured values can be found in the `req.params` object. +Cuando construimos una API, tenemos que permitir que los usuarios nos comuniquen lo que quieren obtener de nuestro servicio. Por ejemplo, si el cliente solicita información sobre un usuario almacenado en la base de datos, necesitan una forma de hacernos saber en qué usuario están interesados. Una posible forma de lograr este resultado es utilizando parámetros de ruta. Los parámetros de ruta son segmentos con nombre de la URL, delimitados por barras (/). Cada segmento captura el valor de la parte de la URL que coincide con su posición. Los valores capturados pueden encontrarse en el objeto `req.params`.
route_path: '/user/:userId/book/:bookId'
actual_request_URL: '/user/546/book/6754'
req.params: {userId: '546', bookId: '6754'}
# --instructions-- -Build an echo server, mounted at the route `GET /:word/echo`. Respond with a JSON object, taking the structure `{echo: word}`. You can find the word to be repeated at `req.params.word`. You can test your route from your browser's address bar, visiting some matching routes, e.g. `your-app-rootpath/freecodecamp/echo`. +Construye un servidor de eco, montado en la ruta `GET /:word/echo`. Responde con un documento JSON, tomando la estructura `{echo: word}`. Puedes encontrar la palabra que se repetirá en `req.params.word`. Puedes probar tu ruta desde la barra de direcciones de tu navegador, visitando algunas rutas coincidentes, por ejemplo, `your-app-rootpath/freecodecamp/echo`. # --hints-- -Test 1 : Your echo server should repeat words correctly +Prueba 1: Tu servidor de eco debe repetir las palabras correctamente ```js (getUserInput) => @@ -36,7 +36,7 @@ Test 1 : Your echo server should repeat words correctly ); ``` -Test 2 : Your echo server should repeat words correctly +Prueba 2: Tu servidor de eco debe repetir las palabras correctamente ```js (getUserInput) => diff --git a/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/implement-a-root-level-request-logger-middleware.md b/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/implement-a-root-level-request-logger-middleware.md index 2a2faa35c3..c101d96b21 100644 --- a/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/implement-a-root-level-request-logger-middleware.md +++ b/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/implement-a-root-level-request-logger-middleware.md @@ -1,6 +1,6 @@ --- id: 587d7fb1367417b2b2512bf3 -title: Implement a Root-Level Request Logger Middleware +title: Implementa un Middleware de registro de peticiones a nivel raíz challengeType: 2 forumTopicId: 301514 dashedName: implement-a-root-level-request-logger-middleware @@ -8,9 +8,9 @@ dashedName: implement-a-root-level-request-logger-middleware # --description-- -Earlier, you were introduced to the `express.static()` middleware function. Now it’s time to see what middleware is, in more detail. Middleware functions are functions that take 3 arguments: the request object, the response object, and the next function in the application’s request-response cycle. These functions execute some code that can have side effects on the app, and usually add information to the request or response objects. They can also end the cycle by sending a response when some condition is met. If they don’t send the response when they are done, they start the execution of the next function in the stack. This triggers calling the 3rd argument, `next()`. +Anteriormente, se te presentó la función de middleware `express.static()`. Ahora es el momento de ver lo que es un middleware con más detalle. Las funciones de Middleware son funciones que toman 3 argumentos: el objeto de la petición, el objeto de respuesta y la siguiente función en el ciclo petición-respuesta de la aplicación. Estas funciones ejecutan algún código que puede tener efectos secundarios en la aplicación, y normalmente agregan información a los objetos de la petición o respuesta. También pueden terminar el ciclo enviando una respuesta cuando se cumple alguna condición. Si no envían la respuesta cuando han terminado, comienzan la ejecución de la siguiente función en la pila de ejecución. Esto hace que se llame al tercer argumento, `next()`. -Look at the following example: +Veamos el siguiente ejemplo: ```js function(req, res, next) { @@ -19,17 +19,17 @@ function(req, res, next) { } ``` -Let’s suppose you mounted this function on a route. When a request matches the route, it displays the string “I’m a middleware…”, then it executes the next function in the stack. In this exercise, you are going to build root-level middleware. As you have seen in challenge 4, to mount a middleware function at root level, you can use the `app.use()` method. In this case, the function will be executed for all the requests, but you can also set more specific conditions. For example, if you want a function to be executed only for POST requests, you could use `app.post()`. Analogous methods exist for all the HTTP verbs (GET, DELETE, PUT, …). +Supongamos que montaste esta función en una ruta. Cuando una solicitud coincide con la ruta, muestra la cadena “I'm a middleware…”, luego ejecuta la siguiente función en la pila de ejecución. En este ejercicio, vas a construir un middleware a nivel raíz. Como has visto en el desafío 4, para montar una función middleware a nivel raíz, puedes usar el método `app.use()`. En este caso, la función se ejecutará para todas las peticiones, pero también se pueden establecer condiciones más específicas. Por ejemplo, si quieres que una función se ejecute sólo para solicitudes POST, puedes usar `app.post()`. Existen métodos análogos para todos los verbos HTTP (GET, DELETE, PUT, …). # --instructions-- -Build a simple logger. For every request, it should log to the console a string taking the following format: `method path - ip`. An example would look like this: `GET /json - ::ffff:127.0.0.1`. Note that there is a space between `method` and `path` and that the dash separating `path` and `ip` is surrounded by a space on both sides. You can get the request method (http verb), the relative route path, and the caller’s ip from the request object using `req.method`, `req.path` and `req.ip`. Remember to call `next()` when you are done, or your server will be stuck forever. Be sure to have the ‘Logs’ opened, and see what happens when some request arrives. +Construye un simple registrador. Para cada petición, debe registrar en la consola una cadena con el siguiente formato: `method path - ip`. Un ejemplo se vería así: `GET /json - ::ffff:127.0.0.1`. Ten en cuenta que hay un espacio entre `method` y `path` y que el guión que separa `path` e `ip` está rodeado por un espacio en ambos lados. Puedes obtener el método de solicitud (http verb), la ruta de ruta relativa y la ip del cliente desde el objeto de la petición usando `req.method`, `req.path` y `req.ip`. Recuerda llamar a `next()` cuando hayas terminado, o tu servidor permanecerá bloqueado permanentemente. Asegúrate de tener abiertos los "registros" y comprueba lo que sucede cuando llega una solicitud. -**Note:** Express evaluates functions in the order they appear in the code. This is true for middleware too. If you want it to work for all the routes, it should be mounted before them. +**Nota:** Express evalúa las funciones en el orden en que aparecen en el código. Esto también es cierto para los middleware. Si quieres que funcione para todas las rutas, debe montarse antes que ellas. # --hints-- -Root level logger middleware should be active +El middleware de registro a nivel raíz debe estar activo ```js (getUserInput) => diff --git a/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/serve-an-html-file.md b/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/serve-an-html-file.md index 1d61867322..4d33c4b6df 100644 --- a/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/serve-an-html-file.md +++ b/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/serve-an-html-file.md @@ -1,6 +1,6 @@ --- id: 587d7fb0367417b2b2512bef -title: Serve an HTML File +title: Sirve un archivo HTML challengeType: 2 forumTopicId: 301516 dashedName: serve-an-html-file @@ -8,7 +8,7 @@ dashedName: serve-an-html-file # --description-- -You can respond to requests with a file using the `res.sendFile(path)` method. You can put it inside the `app.get('/', ...)` route handler. Behind the scenes, this method will set the appropriate headers to instruct your browser on how to handle the file you want to send, according to its type. Then it will read and send the file. This method needs an absolute file path. We recommend you to use the Node global variable `__dirname` to calculate the path like this: +Puedes responder a peticiones con un archivo utilizando el método `res.sendFile(path)`. Puedes ponerlo dentro del gestor de rutas `app.get('/', ...)`. En segundo plano, este método establecerá las cabeceras apropiadas para indicar a tu navegador cómo manejar el archivo que se desea enviar, de acuerdo a su tipo. Entonces leerá y enviará el archivo. Este método necesita una ruta de archivo absoluta. Te recomendamos que uses la variable global de Node `__dirname` para calcular la ruta como esta: ```js absolutePath = __dirname + relativePath/file.ext @@ -16,13 +16,13 @@ absolutePath = __dirname + relativePath/file.ext # --instructions-- -Send the `/views/index.html` file as a response to GET requests to the `/` path. If you view your live app, you should see a big HTML heading (and a form that we will use later…), with no style applied. +Envía el archivo `/views/index.html` como respuesta a las solicitudes GET a la ruta `/`. Si ves tu aplicación en vivo, debes ver un gran encabezado HTML (y un formulario que usaremos más adelante…), sin ningún estilo aplicado. -**Note:** You can edit the solution of the previous challenge or create a new one. If you create a new solution, keep in mind that Express evaluates routes from top to bottom, and executes the handler for the first match. You have to comment out the preceding solution, or the server will keep responding with a string. +**Nota:** Puedes editar la solución del desafío anterior o crear uno nuevo. Si creas una nueva solución, ten en cuenta que Express evalúa las rutas de arriba a abajo, y ejecuta el manejador para la primera coincidencia. Tienes que comentar la solución anterior, o el servidor seguirá respondiendo con una cadena. # --hints-- -Your app should serve the file views/index.html +Tu app debe servir el archivo views/index.html ```js (getUserInput) => diff --git a/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/serve-json-on-a-specific-route.md b/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/serve-json-on-a-specific-route.md index 1e977061c7..d8b1bbe8c8 100644 --- a/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/serve-json-on-a-specific-route.md +++ b/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/serve-json-on-a-specific-route.md @@ -1,6 +1,6 @@ --- id: 587d7fb1367417b2b2512bf1 -title: Serve JSON on a Specific Route +title: Sirve JSON en una ruta específica challengeType: 2 forumTopicId: 301517 dashedName: serve-json-on-a-specific-route @@ -8,17 +8,17 @@ dashedName: serve-json-on-a-specific-route # --description-- -While an HTML server serves HTML, an API serves data. A REST (REpresentational State Transfer) API allows data exchange in a simple way, without the need for clients to know any detail about the server. The client only needs to know where the resource is (the URL), and the action it wants to perform on it (the verb). The GET verb is used when you are fetching some information, without modifying anything. These days, the preferred data format for moving information around the web is JSON. Simply put, JSON is a convenient way to represent a JavaScript object as a string, so it can be easily transmitted. +Mientras que un servidor HTML sirve HTML, una API sirve datos. Una API REST (REpresentational State Transfer) permite el intercambio de datos de una manera sencilla, sin necesidad de que los clientes conozcan ningún detalle sobre el servidor. El cliente sólo necesita saber dónde está el recurso (la URL), y la acción que quiere realizar en él (el verbo). El verbo GET se utiliza cuando se obtiene alguna información, sin modificar nada. En la actualidad, el formato de datos preferido para mover información por la web es JSON. En pocas palabras, JSON es una manera conveniente de representar un objeto JavaScript como una cadena de texto, por lo que puede ser fácilmente transmitido. -Let's create a simple API by creating a route that responds with JSON at the path `/json`. You can do it as usual, with the `app.get()` method. Inside the route handler, use the method `res.json()`, passing in an object as an argument. This method closes the request-response loop, returning the data. Behind the scenes, it converts a valid JavaScript object into a string, then sets the appropriate headers to tell your browser that you are serving JSON, and sends the data back. A valid object has the usual structure `{key: data}`. `data` can be a number, a string, a nested object or an array. `data` can also be a variable or the result of a function call, in which case it will be evaluated before being converted into a string. +Vamos a crear una API simple creando una ruta que responda con JSON en la ruta `/json`. Puedes hacerlo como de costumbre, con el método `app.get()`. Dentro del manejador de ruta, utiliza el método `res.json()`, pasando un objeto como argumento. Este método cierra el bucle de solicitud y respuesta, devolviendo los datos. Tras bambalinas, convierte un objeto JavaScript en una cadena, luego establece las cabeceras apropiadas para decirle a tu navegador que está sirviendo JSON, y devuelve los datos. Un objeto válido tiene la estructura habitual `{key: data}`. `data` puede ser un número, una cadena de texto, un objeto anidado o un arreglo. `data` también puede ser una variable o el resultado de una llamada a una función, en cuyo caso será evaluado antes de ser convertido en una cadena de texto. # --instructions-- -Serve the object `{"message": "Hello json"}` as a response, in JSON format, to GET requests to the `/json` route. Then point your browser to `your-app-url/json`, you should see the message on the screen. +Sirve el objeto `{"message": "Hello json"}` como respuesta, en formato JSON, a las solicitudes GET en la ruta `/json`. A continuación, apunta tu navegador a `your-app-url/json`, debes ver el mensaje en la pantalla. # --hints-- -The endpoint `/json` should serve the json object `{"message": "Hello json"}` +El endpoint `/json` debe servir el objeto json `{"message": "Hello json"}` ```js (getUserInput) => diff --git a/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/serve-static-assets.md b/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/serve-static-assets.md index f3e2796c54..bad41c52b1 100644 --- a/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/serve-static-assets.md +++ b/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/serve-static-assets.md @@ -1,6 +1,6 @@ --- id: 587d7fb0367417b2b2512bf0 -title: Serve Static Assets +title: Sirve recursos estáticos challengeType: 2 forumTopicId: 301518 dashedName: serve-static-assets @@ -8,21 +8,21 @@ dashedName: serve-static-assets # --description-- -An HTML server usually has one or more directories that are accessible by the user. You can place there the static assets needed by your application (stylesheets, scripts, images). +Un servidor HTML normalmente tiene uno o más directorios a los que el usuario puede acceder. Puedes colocar allí los recursos estáticos que necesite tu aplicación (hojas de estilo, scripts, imágenes). -In Express, you can put in place this functionality using the middleware `express.static(path)`, where the `path` parameter is the absolute path of the folder containing the assets. +En Express, puedes poner en marcha esta funcionalidad utilizando el middleware `express.static(path)`, donde el parámetro `path` es la ruta absoluta de la carpeta que contiene los recursos. -If you don’t know what middleware is... don’t worry, we will discuss in detail later. Basically, middleware are functions that intercept route handlers, adding some kind of information. A middleware needs to be mounted using the method `app.use(path, middlewareFunction)`. The first `path` argument is optional. If you don’t pass it, the middleware will be executed for all requests. +Si no sabes qué es middleware... no te preocupes, hablaremos en detalle más adelante. Básicamente, middleware son funciones que interceptan los manejadores de rutas, añadiendo algún tipo de información. Un middleware necesita ser montado usando el método `app.use(path, middlewareFunction)`. El primer argumento de `path` es opcional. Si no lo pasas, el middleware se ejecutará para todas las peticiones. # --instructions-- -Mount the `express.static()` middleware to the path `/public` with `app.use()`. The absolute path to the assets folder is `__dirname + /public`. +Monta el middleware `express.static()` a la ruta `/public` con `app.use()`. La ruta absoluta a la carpeta de recursos es `__dirname + /public`. -Now your app should be able to serve a CSS stylesheet. Note that the `/public/style.css` file is referenced in the `/views/index.html` in the project boilerplate. Your front-page should look a little better now! +Ahora tu aplicación debe ser capaz de servir una hoja de estilos CSS. Ten en cuenta que el archivo `/public/style.css` está referenciado en el archivo `/views/index.html` en el plantilla del proyecto. ¡Tu página principal debería verse un poco mejor ahora! # --hints-- -Your app should serve asset files from the `/public` directory to the `/public` path +Tu aplicación debe servir archivos de recursos desde el directorio `/public` a la ruta `/public` ```js (getUserInput) => diff --git a/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/start-a-working-express-server.md b/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/start-a-working-express-server.md index e8e3e82fc5..5052d93e20 100644 --- a/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/start-a-working-express-server.md +++ b/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/start-a-working-express-server.md @@ -1,6 +1,6 @@ --- id: 587d7fb0367417b2b2512bee -title: Start a Working Express Server +title: Inicia un servidor Express challengeType: 2 forumTopicId: 301519 dashedName: start-a-working-express-server @@ -8,9 +8,9 @@ dashedName: start-a-working-express-server # --description-- -In the first two lines of the file `myApp.js`, you can see how easy it is to create an Express app object. This object has several methods, and you will learn many of them in these challenges. One fundamental method is `app.listen(port)`. It tells your server to listen on a given port, putting it in running state. For testing reasons, we need the app to be running in the background so we added this method in the `server.js` file for you. +En las primeras dos líneas del archivo `myApp.js`, puedes ver lo fácil que es crear un objeto app Express. Este objeto tiene varios métodos, y aprenderás muchos de ellos en estos desafíos. Un método fundamental es `app.listen(port)`. Le dice a tu servidor que escuche en un puerto determinado, poniéndolo en estado de ejecución. Por razones de prueba, necesitamos que la aplicación se ejecute en segundo plano, así que añadimos este método en el archivo `server.js` para ti. -Let’s serve our first string! In Express, routes takes the following structure: `app.METHOD(PATH, HANDLER)`. METHOD is an http method in lowercase. PATH is a relative path on the server (it can be a string, or even a regular expression). HANDLER is a function that Express calls when the route is matched. Handlers take the form `function(req, res) {...}`, where req is the request object, and res is the response object. For example, the handler +¡Sirvamos nuestra primer cadena! En Express, las rutas toman la siguiente estructura: `app.METHOD(PATH, HANDLER)`. METHOD es un método http en minúsculas. PATH es una ruta relativa en el servidor (puede ser una cadena, o incluso una expresión regular). HANDLER es una función que Express llama cuando la ruta coincide. Los Handlers toman la forma `function(req, res) {...}`, donde req es el objeto de la solicitud, y res es el objeto de respuesta. Por ejemplo, el handler ```js function(req, res) { @@ -18,17 +18,17 @@ function(req, res) { } ``` -will serve the string 'Response String'. +servirá la cadena 'Response String'. # --instructions-- -Use the `app.get()` method to serve the string "Hello Express" to GET requests matching the `/` (root) path. Be sure that your code works by looking at the logs, then see the results in the preview if you are using Replit. +Utiliza el método `app.get()` para servir la cadena "Hello Express" a las peticiones GET que coincidan con la ruta `/` (raíz). Asegúrate de que tu código funciona mirando los registros, luego ve los resultados en la vista previa si estás usando Replit. -**Note:** All the code for these lessons should be added in between the few lines of code we have started you off with. +**Nota:** Todo el código de estas lecciones debe añadirse entre las pocas líneas de código con las que hemos iniciado. # --hints-- -Your app should serve the string 'Hello Express' +Tu aplicación debe mostrarte en consola la cadena 'Hello Express' ```js (getUserInput) => diff --git a/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/use-body-parser-to-parse-post-requests.md b/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/use-body-parser-to-parse-post-requests.md index 5baf9fc636..9008541c06 100644 --- a/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/use-body-parser-to-parse-post-requests.md +++ b/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/use-body-parser-to-parse-post-requests.md @@ -1,6 +1,6 @@ --- id: 587d7fb2367417b2b2512bf7 -title: Use body-parser to Parse POST Requests +title: Usa body-parser para analizar las peticiones POST challengeType: 2 forumTopicId: 301520 dashedName: use-body-parser-to-parse-post-requests @@ -8,9 +8,9 @@ dashedName: use-body-parser-to-parse-post-requests # --description-- -Besides GET, there is another common HTTP verb, it is POST. POST is the default method used to send client data with HTML forms. In REST convention, POST is used to send data to create new items in the database (a new user, or a new blog post). You don’t have a database in this project, but you are going to learn how to handle POST requests anyway. +Además de GET, hay otro verbo HTTP común, es POST. POST es el método por defecto utilizado para enviar datos del cliente con formularios HTML. En la convención REST, POST se utiliza para enviar datos para crear nuevos elementos en la base de datos (un nuevo usuario, o una nueva entrada de blog). No tienes una base de datos en este proyecto, pero de todos modos aprenderás a manejar las peticiones POST. -In these kind of requests, the data doesn’t appear in the URL, it is hidden in the request body. The body is a part of the HTTP request, also called the payload. Even though the data is not visible in the URL, this does not mean that it is private. To see why, look at the raw content of an HTTP POST request: +En este tipo de peticiones, los datos no aparecen en la URL, están ocultos en el cuerpo de la petición. El cuerpo es parte de la petición HTTP, también llamada la carga útil. Aunque los datos no son visibles en la URL, esto no significa que sean privados. Para ver por qué, mire el contenido bruto de una petición HTTP POST: ```http POST /path/subpath HTTP/1.0 @@ -22,19 +22,19 @@ Content-Length: 20 name=John+Doe&age=25 ``` -As you can see, the body is encoded like the query string. This is the default format used by HTML forms. With Ajax, you can also use JSON to handle data having a more complex structure. There is also another type of encoding: multipart/form-data. This one is used to upload binary files. In this exercise, you will use a urlencoded body. To parse the data coming from POST requests, you have to install the `body-parser` package. This package allows you to use a series of middleware, which can decode data in different formats. +Como puedes ver, el cuerpo está codificado como la cadena de consulta. Este es el formato por defecto utilizado por los formularios HTML. Con Ajax, también puedes utilizar JSON para manejar datos con una estructura más compleja. También hay otro tipo de codificación: multiparte/form-data. Este se utiliza para subir archivos binarios. En este ejercicio, usarás un cuerpo urlencoded. Para analizar los datos provenientes de peticiones POST, tienes que instalar el paquete `body-parser`. Este paquete te permite usar una serie de middleware, que pueden decodificar datos en diferentes formatos. # --instructions-- -Install the `body-parser` module in your `package.json`. Then, `require` it at the top of the file. Store it in a variable named `bodyParser`. The middleware to handle urlencoded data is returned by `bodyParser.urlencoded({extended: false})`. Pass the function returned by the previous method call to `app.use()`. As usual, the middleware must be mounted before all the routes that depend on it. +Instala el módulo `body-parser` en tu `package.json`. Luego, agrega `require` en la parte superior del archivo con el nuevo módulo. Almacénelo en una variable llamada `bodyParser`. El middleware para manejar datos urlencoded es devuelto por `bodyParser.urlencoded({extended: false})`. Pasa la función devuelta por el método anterior llamada a `app.use()`. Como de costumbre, el middleware debe ser montado antes de todas las rutas que dependen de él. -**Note:** `extended` is a configuration option that tells `body-parser` which parsing needs to be used. When `extended=false` it uses the classic encoding `querystring` library. When `extended=true` it uses `qs` library for parsing. +**Nota:** `extended` es una opción de configuración que le dice a `body-parser` qué análisis necesita ser usado. Cuando `extended=false`, utiliza la biblioteca `querystring` de codificación clásica. Cuando `extended=true` utiliza la biblioteca `qs` para analizar la sintaxis. -When using `extended=false`, values can be only strings or arrays. The object returned when using `querystring` does not prototypically inherit from the default JavaScript `Object`, which means functions like `hasOwnProperty`, `toString` will not be available. The extended version allows more data flexibility, but it is outmatched by JSON. +Cuando se utiliza `extended=false`, los valores sólo pueden ser cadenas o arreglos. El objeto devuelto al usar `querystring` no hereda de forma prototípica del `Object` de JavaScript por defecto, lo que significa que funciones como `hasOwnProperty`, `toString` no estarán disponibles. La versión "extended" permite más flexibilidad de datos, pero es superada por JSON. # --hints-- -The 'body-parser' middleware should be mounted +El middleware 'body-parser' debe ser montado ```js (getUserInput) => diff --git a/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/use-the-.env-file.md b/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/use-the-.env-file.md index e953553f4b..12f586e435 100644 --- a/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/use-the-.env-file.md +++ b/curriculum/challenges/espanol/05-back-end-development-and-apis/basic-node-and-express/use-the-.env-file.md @@ -1,6 +1,6 @@ --- id: 587d7fb1367417b2b2512bf2 -title: Use the .env File +title: Usa el archivo .env challengeType: 2 forumTopicId: 301521 dashedName: use-the--env-file @@ -8,23 +8,25 @@ dashedName: use-the--env-file # --description-- -The `.env` file is a hidden file that is used to pass environment variables to your application. This file is secret, no one but you can access it, and it can be used to store data that you want to keep private or hidden. For example, you can store API keys from external services or your database URI. You can also use it to store configuration options. By setting configuration options, you can change the behavior of your application, without the need to rewrite some code. +El archivo `.env` es un archivo oculto que se utiliza para pasar variables de entorno a la aplicación. Este archivo es secreto, solamente tú puedes acceder a él, y puede ser utilizado para almacenar datos que desees mantener privados u ocultos. Por ejemplo, puedes almacenar claves de APIs de servicios externos o la URI de tu base de datos. También puedes usarlo para guardar opciones de configuración. Modificando las opciones de configuración, puedes cambiar el comportamiento de tu aplicación, sin necesidad de reescribir código. -The environment variables are accessible from the app as `process.env.VAR_NAME`. The `process.env` object is a global Node object, and variables are passed as strings. By convention, the variable names are all uppercase, with words separated by an underscore. The `.env` is a shell file, so you don’t need to wrap names or values in quotes. It is also important to note that there cannot be space around the equals sign when you are assigning values to your variables, e.g. `VAR_NAME=value`. Usually, you will put each variable definition on a separate line. +Las variables de entorno son accesibles desde la aplicación como `process.env.VAR_NAME`. El objeto `process.env` es un objeto global de Node, y las variables son pasadas como cadenas de texto. Por convención, los nombres de las variables son en letras mayúsculas, con las palabras separadas por guión bajo. El archivo `.env` es un archivo shell, por lo que no es necesario incluir los nombres o valores entre comillas. También es importante tener en cuenta que no pueden haber espacios alrededor del signo de igual cuando se asignan valores a las variables, por ejemplo: `VAR_NAME=value`. Normalmente, usted pondrá cada definición de variable en una línea separada. # --instructions-- -Let's add an environment variable as a configuration option. +Añadamos una variable de entorno como opción de configuración. -Create a `.env` file in the root of your project directory, and store the variable `MESSAGE_STYLE=uppercase` in it. +Crea un archivo `.env` en la raíz del directorio de tu proyecto y almacena la variable `MESSAGE_STYLE=uppercase` en él. -Then, in the `/json` GET route handler you created in the last challenge, transform the response object's message to uppercase if `process.env.MESSAGE_STYLE` equals `uppercase`. The response object should either be `{"message": "Hello json"}` or `{"message": "HELLO JSON"}`, depending on the `MESSAGE_STYLE` value. +Luego, en el manejador de rutas `/json` GET creado en el último desafío, transforma el mensaje del objeto de respuesta a mayúsculas si `process.env.MESSAGE_STYLE` es igual a `uppercase`. El objeto de respuesta debe ser `{"message": "Hello json"}` o `{"message": "HELLO JSON"}`, dependiendo del valor `MESSAGE_STYLE`. -**Note:** If you are using Replit, you cannot create a `.env` file. Instead, use the built-in SECRETS tab to add the variable. +**Nota:** Si estás usando Replit, no puedes crear un archivo `.env`. En su lugar, utiliza la pestaña integrada SECRETS para añadir la variable. + +Si estás trabajando localmente, necesitarás el paquete `dotenv`. Carga variables de entorno desde tu archivo `.env` en `process.env`. Instálalo con `npm install dotenv`. Luego, en la parte superior de tu archivo `myApp.js`, importa y carga las variables con `require('dotenv').config()`. # --hints-- -The response of the endpoint `/json` should change according to the environment variable `MESSAGE_STYLE` +La respuesta del endpoint `/json` debe cambiar de acuerdo a la variable de entorno `MESSAGE_STYLE` ```js (getUserInput) => diff --git a/curriculum/challenges/italian/01-responsive-web-design/applied-accessibility/use-headings-to-show-hierarchical-relationships-of-content.md b/curriculum/challenges/italian/01-responsive-web-design/applied-accessibility/use-headings-to-show-hierarchical-relationships-of-content.md index d997fd3250..abcd3bafcf 100644 --- a/curriculum/challenges/italian/01-responsive-web-design/applied-accessibility/use-headings-to-show-hierarchical-relationships-of-content.md +++ b/curriculum/challenges/italian/01-responsive-web-design/applied-accessibility/use-headings-to-show-hierarchical-relationships-of-content.md @@ -17,7 +17,7 @@ Se stai scrivendo un articolo con un'introduzione, un corpo, e una conclusione, Le intestazioni di rango uguale (o superiore) iniziano nuove sezioni implicite, intestazioni di rango minore iniziano sottosezioni di quella precedente. -Ad esempio, una pagina con un elemento `h2` seguito da diverse sottosezioni etichettate con tag `h4` confonderebbe un utente di screen reader. Con sei scelte, è allettante utilizzare un tag perché appare meglio nel browser, ma ricorda che puoi utilizzare CSS per modificarne la dimensione. +Ad esempio, una pagina con un elemento `h2` seguito da diverse sottosezioni etichettate con elementi `h4` confonderebbe un utente di screen reader. Con sei scelte, è allettante utilizzare un tag perché appare meglio nel browser, ma ricorda che puoi utilizzare CSS per modificarne la dimensione. Un ultimo punto: ogni pagina dovrebbe avere sempre uno (e uno solo) elemento `h1`, relativo al tema principale del tuo contenuto. Questa e le altre intestazioni sono utilizzate in parte dai motori di ricerca per capire l'argomento della pagina. @@ -27,7 +27,7 @@ Camper Cat vuole una pagina sul suo sito dedicata a come diventare un ninja. Aiu # --hints-- -Il tuo codice dovrebbe avere 6 tag `h3`. +Il tuo codice dovrebbe avere 6 elementi `h3`. ```js assert($('h3').length === 6); @@ -39,7 +39,7 @@ Il tuo codice dovrebbe avere 6 tag di chiusura `h3`. assert((code.match(/\/h3/g) || []).length === 6); ``` -Il tuo codice non dovrebbe avere alcun tag `h5`. +Il tuo codice non dovrebbe avere alcun elemento `h5`. ```js assert($('h5').length === 0); diff --git a/curriculum/challenges/italian/01-responsive-web-design/applied-visual-design/adjust-the-size-of-a-heading-element-versus-a-paragraph-element.md b/curriculum/challenges/italian/01-responsive-web-design/applied-visual-design/adjust-the-size-of-a-heading-element-versus-a-paragraph-element.md index 56204bf5d4..2c478a2e41 100644 --- a/curriculum/challenges/italian/01-responsive-web-design/applied-visual-design/adjust-the-size-of-a-heading-element-versus-a-paragraph-element.md +++ b/curriculum/challenges/italian/01-responsive-web-design/applied-visual-design/adjust-the-size-of-a-heading-element-versus-a-paragraph-element.md @@ -1,6 +1,6 @@ --- id: 587d781b367417b2b2512abd -title: Regolare la dimensione di un'intestazione rispetto a quella di un paragrafo +title: Regolare la dimensione di un elemento di intestazione rispetto a quella di un elemento paragrafo challengeType: 0 videoUrl: 'https://scrimba.com/c/c3bRPTz' forumTopicId: 301037 @@ -9,11 +9,11 @@ dashedName: adjust-the-size-of-a-heading-element-versus-a-paragraph-element # --description-- -La dimensione del carattere dei tag di intestazione (da `h1` a `h6`) dovrebbe essere generalmente più grande della dimensione del carattere dei tag di paragrafo. Questo rende più facile per l'utente capire visivamente il layout e il livello di importanza di ogni elemento della pagina. Si utilizza la proprietà `font-size` per regolare la dimensione del testo in un elemento. +La dimensione del carattere degli elementi di intestazione (da `h1` a `h6`) dovrebbe essere generalmente più grande della dimensione del carattere degli elementi di paragrafo. Questo rende più facile per l'utente capire visivamente il layout e il livello di importanza di ogni elemento della pagina. Si utilizza la proprietà `font-size` per regolare la dimensione del testo in un elemento. # --instructions-- -Per rendere l'intestazione significativamente più grande del paragrafo, porta `font-size` del tag `h4` a 27 pixel. +Per rendere l'intestazione significativamente più grande del paragrafo, porta `font-size` dell'elemento `h4` a 27 pixel. # --hints-- @@ -116,3 +116,4 @@ assert($('h4').css('font-size') == '27px'); ``` + diff --git a/curriculum/challenges/italian/01-responsive-web-design/applied-visual-design/create-visual-balance-using-the-text-align-property.md b/curriculum/challenges/italian/01-responsive-web-design/applied-visual-design/create-visual-balance-using-the-text-align-property.md index 702bfb2cbb..bafd04a670 100644 --- a/curriculum/challenges/italian/01-responsive-web-design/applied-visual-design/create-visual-balance-using-the-text-align-property.md +++ b/curriculum/challenges/italian/01-responsive-web-design/applied-visual-design/create-visual-balance-using-the-text-align-property.md @@ -13,7 +13,7 @@ Questa sezione del curriculum si concentra sul Visual Design applicato. Il primo Il testo è spesso una buona parte del contenuto web. Il CSS ha diverse opzioni su come allinearlo con la proprietà `text-align`. -`text-align: justify;` fa sì che tutte le righe di testo tranne l'ultima riga incontrino i bordi sinistro e destro della riga. +`text-align: justify;` spazia il testo in modo che ogni riga abbia la stessa lunghezza. `text-align: center;` centra il testo diff --git a/curriculum/challenges/italian/01-responsive-web-design/applied-visual-design/use-the-s-tag-to-strikethrough-text.md b/curriculum/challenges/italian/01-responsive-web-design/applied-visual-design/use-the-s-tag-to-strikethrough-text.md index 82af33cf42..b891883d61 100644 --- a/curriculum/challenges/italian/01-responsive-web-design/applied-visual-design/use-the-s-tag-to-strikethrough-text.md +++ b/curriculum/challenges/italian/01-responsive-web-design/applied-visual-design/use-the-s-tag-to-strikethrough-text.md @@ -13,7 +13,7 @@ Per barrare il testo, ovvero tracciare una linea orizzontale che tagli i caratte # --instructions-- -Avvolgi il tag `s` intorno a `Google` all'interno del tag `h4`, quindi aggiungi la parola `Alphabet` accanto ad esso, senza applicarle la formattazione barrata. +Avvolgi le tag `s` attorno a `Google` dentro le tag `h4` e poi aggiungi la parola `Alphabet` affianco senza la formattazione barrata. # --hints-- diff --git a/curriculum/challenges/italian/01-responsive-web-design/applied-visual-design/use-the-strong-tag-to-make-text-bold.md b/curriculum/challenges/italian/01-responsive-web-design/applied-visual-design/use-the-strong-tag-to-make-text-bold.md index 8452d6cd85..351d9c13e8 100644 --- a/curriculum/challenges/italian/01-responsive-web-design/applied-visual-design/use-the-strong-tag-to-make-text-bold.md +++ b/curriculum/challenges/italian/01-responsive-web-design/applied-visual-design/use-the-strong-tag-to-make-text-bold.md @@ -13,7 +13,7 @@ Per rendere il testo in grassetto, puoi usare il tag `strong`. Esso viene spesso # --instructions-- -Avvolgi un tag `strong` intorno al testo `Stanford University` all'interno del tag `p` (non includere il punto). +Avvolgi le `strong` tag attorno al testo `Stanford University` dentro al tag `p` (non includere il punto!). # --hints-- diff --git a/curriculum/challenges/italian/01-responsive-web-design/basic-html-and-html5/check-radio-buttons-and-checkboxes-by-default.md b/curriculum/challenges/italian/01-responsive-web-design/basic-html-and-html5/check-radio-buttons-and-checkboxes-by-default.md index 3d98d33115..b991257298 100644 --- a/curriculum/challenges/italian/01-responsive-web-design/basic-html-and-html5/check-radio-buttons-and-checkboxes-by-default.md +++ b/curriculum/challenges/italian/01-responsive-web-design/basic-html-and-html5/check-radio-buttons-and-checkboxes-by-default.md @@ -35,6 +35,18 @@ La prima casella di spunta del tuo modulo dovrebbe essere spuntata di default. assert($('input[type="checkbox"]').prop('checked')); ``` +Non dovresti cambiare il testo all'interno dell'etichetta `Indoor`. + +```js +assert.equal(document.querySelector('label[for="indoor"]')?.innerText?.trim(), 'Indoor'); +``` + +Non dovresti cambiare il testo all'interno dell'etichetta `Loving`. + +```js +assert.equal(document.querySelector('label[for="loving"]')?.innerText?.trim(), 'Loving'); +``` + # --seed-- ## --seed-contents-- diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/access-array-data-with-indexes.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/access-array-data-with-indexes.md index 4ed5680ec7..f616299623 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/access-array-data-with-indexes.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/access-array-data-with-indexes.md @@ -18,9 +18,9 @@ Gli indici degli array sono scritti nella stessa notazione tra parentesi usata d **Esempio** ```js -var array = [50,60,70]; +const array = [50, 60, 70]; array[0]; -var data = array[1]; +const data = array[1]; ``` `array[0]` ora è `50` e `data` ha il valore `60`. @@ -76,7 +76,7 @@ if(typeof myArray !== "undefined" && typeof myData !== "undefined"){(function(y, ## --seed-contents-- ```js -var myArray = [50,60,70]; +const myArray = [50, 60, 70]; ``` @@ -84,6 +84,6 @@ var myArray = [50,60,70]; # --solutions-- ```js -var myArray = [50,60,70]; -var myData = myArray[0]; +const myArray = [50, 60, 70]; +const myData = myArray[0]; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/access-multi-dimensional-arrays-with-indexes.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/access-multi-dimensional-arrays-with-indexes.md index 6dc9eca87b..002237ffc8 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/access-multi-dimensional-arrays-with-indexes.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/access-multi-dimensional-arrays-with-indexes.md @@ -14,12 +14,13 @@ dashedName: access-multi-dimensional-arrays-with-indexes **Esempio** ```js -var arr = [ - [1,2,3], - [4,5,6], - [7,8,9], - [[10,11,12], 13, 14] +const arr = [ + [1, 2, 3], + [4, 5, 6], + [7, 8, 9], + [[10, 11, 12], 13, 14] ]; + arr[3]; arr[3][0]; arr[3][0][1]; @@ -58,14 +59,19 @@ if(typeof myArray !== "undefined"){(function(){return "myData: " + myData + " my ## --seed-contents-- ```js -var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]]; +const myArray = [ + [1, 2, 3], + [4, 5, 6], + [7, 8, 9], + [[10, 11, 12], 13, 14], +]; -var myData = myArray[0][0]; +const myData = myArray[0][0]; ``` # --solutions-- ```js -var myArray = [[1,2,3],[4,5,6], [7,8,9], [[10,11,12], 13, 14]]; -var myData = myArray[2][1]; +const myArray = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [[10, 11, 12], 13, 14]]; +const myData = myArray[2][1]; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-arrays.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-arrays.md index e4e3c27111..2521cb7174 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-arrays.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-arrays.md @@ -14,7 +14,7 @@ Come abbiamo visto in precedenti esempi, gli oggetti possono contenere sia ogget Ecco un esempio di come accedere a un array nidificato: ```js -var ourPets = [ +const ourPets = [ { animalType: "cat", names: [ @@ -32,6 +32,7 @@ var ourPets = [ ] } ]; + ourPets[0].names[1]; ourPets[1].names[0]; ``` @@ -72,7 +73,7 @@ assert(/=\s*myPlants\[1\].list\[1\]/.test(code)); ## --seed-contents-- ```js -var myPlants = [ +const myPlants = [ { type: "flowers", list: [ @@ -91,13 +92,13 @@ var myPlants = [ } ]; -var secondTree = ""; +const secondTree = ""; ``` # --solutions-- ```js -var myPlants = [ +const myPlants = [ { type: "flowers", list: [ @@ -116,5 +117,5 @@ var myPlants = [ } ]; -var secondTree = myPlants[1].list[1]; +const secondTree = myPlants[1].list[1]; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-objects.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-objects.md index 0343cea510..2a577d8e0a 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-objects.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-objects.md @@ -14,7 +14,7 @@ Le sotto-proprietà degli oggetti possono essere accessibili concatenando insiem Ecco un oggetto nidificato: ```js -var ourStorage = { +const ourStorage = { "desk": { "drawer": "stapler" }, @@ -26,6 +26,7 @@ var ourStorage = { "bottom drawer": "soda" } }; + ourStorage.cabinet["top drawer"].folder2; ourStorage.desk.drawer; ``` @@ -66,7 +67,7 @@ assert(/=\s*myStorage\.car\.inside\[\s*("|')glove box\1\s*\]/g.test(code)); ## --seed-contents-- ```js -var myStorage = { +const myStorage = { "car": { "inside": { "glove box": "maps", @@ -78,13 +79,13 @@ var myStorage = { } }; -var gloveBoxContents = undefined; +const gloveBoxContents = undefined; ``` # --solutions-- ```js -var myStorage = { +const myStorage = { "car":{ "inside":{ "glove box":"maps", @@ -95,5 +96,5 @@ var myStorage = { } } }; -var gloveBoxContents = myStorage.car.inside["glove box"]; +const gloveBoxContents = myStorage.car.inside["glove box"]; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-bracket-notation.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-bracket-notation.md index fb5d7d29a0..447f7067b7 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-bracket-notation.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-bracket-notation.md @@ -16,11 +16,12 @@ Tuttavia, puoi ancora usare la notazione a parentesi sulle proprietà dell'ogget Ecco un esempio di come usare la notazione a parentesi per leggere la proprietà di un oggetto: ```js -var myObj = { +const myObj = { "Space Name": "Kirk", "More Space": "Spock", "NoSpace": "USS Enterprise" }; + myObj["Space Name"]; myObj['More Space']; myObj["NoSpace"]; @@ -78,26 +79,25 @@ assert(code.match(/testObj\s*?\[('|")[^'"]+\1\]/g).length > 1); ```js // Setup -var testObj = { +const testObj = { "an entree": "hamburger", "my side": "veggies", "the drink": "water" }; // Only change code below this line - -var entreeValue = testObj; // Change this line -var drinkValue = testObj; // Change this line +const entreeValue = testObj; // Change this line +const drinkValue = testObj; // Change this line ``` # --solutions-- ```js -var testObj = { +const testObj = { "an entree": "hamburger", "my side": "veggies", "the drink": "water" }; -var entreeValue = testObj["an entree"]; -var drinkValue = testObj['the drink']; +const entreeValue = testObj["an entree"]; +const drinkValue = testObj['the drink']; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-dot-notation.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-dot-notation.md index 1a145c00b9..2f17b7f882 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-dot-notation.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-dot-notation.md @@ -16,15 +16,17 @@ La notazione a punti è quella che usi quando conosci già il nome della proprie Di seguito è riportato un esempio di utilizzo della notazione a punti (`.`) per leggere la proprietà di un oggetto: ```js -var myObj = { +const myObj = { prop1: "val1", prop2: "val2" }; -var prop1val = myObj.prop1; -var prop2val = myObj.prop2; + +const prop1val = myObj.prop1; +const prop2val = myObj.prop2; ``` `prop1val` ha il valore della stringa `val1` e `prop2val` ha il avere un valore della stringa `val2`. + # --instructions-- Leggi i valori delle proprietà di `testObj` utilizzando la notazione a punti. Imposta la variabile `hatValue` in modo che sia uguale alla proprietà `hat` dell'oggetto, e imposta la variabile `shirtValue` in modo che sia uguale alla proprietà `shirt` dell'oggetto. @@ -73,27 +75,26 @@ assert(code.match(/testObj\.\w+/g).length > 1); ```js // Setup -var testObj = { +const testObj = { "hat": "ballcap", "shirt": "jersey", "shoes": "cleats" }; // Only change code below this line - -var hatValue = testObj; // Change this line -var shirtValue = testObj; // Change this line +const hatValue = testObj; // Change this line +const shirtValue = testObj; // Change this line ``` # --solutions-- ```js -var testObj = { +const testObj = { "hat": "ballcap", "shirt": "jersey", "shoes": "cleats" }; -var hatValue = testObj.hat; -var shirtValue = testObj.shirt; +const hatValue = testObj.hat; +const shirtValue = testObj.shirt; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-variables.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-variables.md index 7e48babe8a..0a55b7ccb5 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-variables.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-variables.md @@ -14,11 +14,14 @@ Un altro uso della notazione a parentesi con gli oggetti è quello di accedere a Ecco un esempio di utilizzo di una variabile per accedere a una proprietà: ```js -var dogs = { - Fido: "Mutt", Hunter: "Doberman", Snoopie: "Beagle" +const dogs = { + Fido: "Mutt", + Hunter: "Doberman", + Snoopie: "Beagle" }; -var myDog = "Hunter"; -var myBreed = dogs[myDog]; + +const myDog = "Hunter"; +const myBreed = dogs[myDog]; console.log(myBreed); ``` @@ -27,14 +30,16 @@ La stringa `Doberman` sarà visualizzata nella console. Un altro modo per utilizzare questo concetto è quando il nome della proprietà viene ottenuto dinamicamente durante l'esecuzione del programma, come segue: ```js -var someObj = { +const someObj = { propName: "John" }; + function propPrefix(str) { - var s = "prop"; + const s = "prop"; return s + str; } -var someProp = propPrefix("Name"); + +const someProp = propPrefix("Name"); console.log(someObj[someProp]); ``` @@ -96,26 +101,25 @@ if(typeof player !== "undefined"){(function(v){return v;})(player);} ```js // Setup -var testObj = { +const testObj = { 12: "Namath", 16: "Montana", 19: "Unitas" }; // Only change code below this line - -var playerNumber; // Change this line -var player = testObj; // Change this line +const playerNumber = 42; // Change this line +const player = testObj; // Change this line ``` # --solutions-- ```js -var testObj = { +const testObj = { 12: "Namath", 16: "Montana", 19: "Unitas" }; -var playerNumber = 16; -var player = testObj[playerNumber]; +const playerNumber = 16; +const player = testObj[playerNumber]; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/add-new-properties-to-a-javascript-object.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/add-new-properties-to-a-javascript-object.md index b7c1d3b39e..e2c379658e 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/add-new-properties-to-a-javascript-object.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/add-new-properties-to-a-javascript-object.md @@ -28,7 +28,7 @@ Ora quando valuteremo `ourDog.bark`, otterremo il suo abbaiare, `bow-wow`. Esempio: ```js -var ourDog = { +const ourDog = { "name": "Camper", "legs": 4, "tails": 1, @@ -67,7 +67,7 @@ assert(!/bark[^\n]:/.test(code)); ## --seed-contents-- ```js -var myDog = { +const myDog = { "name": "Happy Coder", "legs": 4, "tails": 1, @@ -80,7 +80,7 @@ var myDog = { # --solutions-- ```js -var myDog = { +const myDog = { "name": "Happy Coder", "legs": 4, "tails": 1, diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/add-two-numbers-with-javascript.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/add-two-numbers-with-javascript.md index db44754a40..5c51addbbf 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/add-two-numbers-with-javascript.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/add-two-numbers-with-javascript.md @@ -18,7 +18,7 @@ JavaScript utilizza il simbolo `+` come operatore di addizione quando è posizio **Esempio:** ```js -myVar = 5 + 10; +const myVar = 5 + 10; ``` `myVar` ora ha il valore `15`. @@ -52,11 +52,11 @@ assert(/\+/.test(code)); ## --seed-contents-- ```js -var sum = 10 + 0; +const sum = 10 + 0; ``` # --solutions-- ```js -var sum = 10 + 10; +const sum = 10 + 10; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/adding-a-default-option-in-switch-statements.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/adding-a-default-option-in-switch-statements.md index 29a1a0d95b..601d3e6c71 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/adding-a-default-option-in-switch-statements.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/adding-a-default-option-in-switch-statements.md @@ -92,7 +92,7 @@ assert(code.match(/break/g).length > 2); ```js function switchOfStuff(val) { - var answer = ""; + let answer = ""; // Only change code below this line @@ -108,7 +108,7 @@ switchOfStuff(1); ```js function switchOfStuff(val) { - var answer = ""; + let answer = ""; switch(val) { case "a": diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/appending-variables-to-strings.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/appending-variables-to-strings.md index 4ab02ac5ab..64d7c32aad 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/appending-variables-to-strings.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/appending-variables-to-strings.md @@ -14,8 +14,8 @@ Proprio come possiamo costruire una stringa su più righe di stringhe lette Esempio: ```js -var anAdjective = "awesome!"; -var ourStr = "freeCodeCamp is "; +const anAdjective = "awesome!"; +let ourStr = "freeCodeCamp is "; ourStr += anAdjective; ``` @@ -64,15 +64,14 @@ assert(code.match(/myStr\s*\+=\s*someAdjective\s*/).length > 0); ```js // Change code below this line - -var someAdjective; -var myStr = "Learning to code is "; +const someAdjective = ""; +let myStr = "Learning to code is "; ``` # --solutions-- ```js -var someAdjective = "neat"; -var myStr = "Learning to code is "; +const someAdjective = "neat"; +let myStr = "Learning to code is "; myStr += someAdjective; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/assignment-with-a-returned-value.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/assignment-with-a-returned-value.md index 7f5495e0fe..4a410f6d46 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/assignment-with-a-returned-value.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/assignment-with-a-returned-value.md @@ -49,13 +49,14 @@ assert(/processed\s*=\s*processArg\(\s*7\s*\)/.test(code)); ```js // Setup -var processed = 0; +let processed = 0; function processArg(num) { return (num + 3) / 5; } // Only change code below this line + ``` # --solutions-- diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/build-javascript-objects.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/build-javascript-objects.md index 7c2e39e0c5..2bc4084a84 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/build-javascript-objects.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/build-javascript-objects.md @@ -18,7 +18,7 @@ Gli oggetti sono utili per archiviare i dati in modo strutturato e possono rappr Ecco un esempio di oggetto gatto (cat): ```js -var cat = { +const cat = { "name": "Whiskers", "legs": 4, "tails": 1, @@ -29,7 +29,7 @@ var cat = { In questo esempio, tutte le proprietà sono memorizzate come stringhe, come `name`, `legs`e `tails`. Per le proprietà puoi anche usare i numeri. Puoi anche omettere le virgolette per le proprietà di tipo stringa di una sola parola, come segue: ```js -var anotherObject = { +const anotherObject = { make: "Ford", 5: "five", "model": "focus" @@ -139,18 +139,18 @@ assert( ## --seed-contents-- ```js -var myDog = { -// Only change code below this line +const myDog = { + // Only change code below this line -// Only change code above this line + // Only change code above this line }; ``` # --solutions-- ```js -var myDog = { +const myDog = { "name": "Camper", "legs": 4, "tails": 1, diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-equality-operator.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-equality-operator.md index c9c1eb08d1..9751c1dc03 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-equality-operator.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-equality-operator.md @@ -16,7 +16,7 @@ L'operatore di base è l'operatore di uguaglianza `==`. L'operatore di uguaglian ```js function equalityTest(myVal) { if (myVal == 10) { - return "Equal"; + return "Equal"; } return "Not Equal"; } diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-inequality-operator.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-inequality-operator.md index 048161809c..7b8c7ea317 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-inequality-operator.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-inequality-operator.md @@ -25,7 +25,7 @@ Nell'ordine, queste espressioni saranno valutate `true`, `false`, `false`, `fals # --instructions-- -Aggiungi l'operatore di disuguaglianza `!=` nell'istruzione `if` in modo che la funzione restituisca la stringa `Not Equal` quando `val` non equivale a `99` +Aggiungi l'operatore di disuguaglianza `!=` nella condizione dell' `if` in modo che la funzione restituisca la stringa `Not Equal` quando `val` non equivale a `99`. # --hints-- diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-strict-equality-operator.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-strict-equality-operator.md index eac103167e..3107758b4d 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-strict-equality-operator.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-strict-equality-operator.md @@ -26,7 +26,7 @@ Nel secondo esempio, `3` è un tipo `Number` e `'3'` è un tipo `String`. # --instructions-- -Usa l'operatore di uguaglianza stretta nell'istruzione `if` in modo che la funzione restituisca la stringa `Equal` quando `val` è strettamente uguale a `7` +Usa l'operatore di uguaglianza stretta nella condizione dell'`if` in modo che la funzione restituisca la stringa `Equal` quando `val` è strettamente uguale a `7`. # --hints-- diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-addition.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-addition.md index 3a7516605f..4549ea2628 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-addition.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-addition.md @@ -20,7 +20,7 @@ per aggiungere `5` a `myVar`. Poiché questo è uno scherma molto comune, ci son Uno di questi operatori è l'operatore `+=`. ```js -var myVar = 1; +let myVar = 1; myVar += 5; console.log(myVar); ``` @@ -61,9 +61,9 @@ Non dovresti modificare il codice sopra il commento specificato. ```js assert( - /var a = 3;/.test(code) && - /var b = 17;/.test(code) && - /var c = 12;/.test(code) + /let a = 3;/.test(code) && + /let b = 17;/.test(code) && + /let c = 12;/.test(code) ); ``` @@ -78,9 +78,9 @@ assert( ## --seed-contents-- ```js -var a = 3; -var b = 17; -var c = 12; +let a = 3; +let b = 17; +let c = 12; // Only change code below this line a = a + 12; @@ -91,9 +91,9 @@ c = c + 7; # --solutions-- ```js -var a = 3; -var b = 17; -var c = 12; +let a = 3; +let b = 17; +let c = 12; a += 12; b += 9; diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-division.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-division.md index b14acf94bf..446a9a9564 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-division.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-division.md @@ -55,9 +55,9 @@ Non dovresti modificare il codice sopra il commento specificato. ```js assert( - /var a = 48;/.test(code) && - /var b = 108;/.test(code) && - /var c = 33;/.test(code) + /let a = 48;/.test(code) && + /let b = 108;/.test(code) && + /let c = 33;/.test(code) ); ``` @@ -72,9 +72,9 @@ assert( ## --seed-contents-- ```js -var a = 48; -var b = 108; -var c = 33; +let a = 48; +let b = 108; +let c = 33; // Only change code below this line a = a / 12; @@ -85,9 +85,9 @@ c = c / 11; # --solutions-- ```js -var a = 48; -var b = 108; -var c = 33; +let a = 48; +let b = 108; +let c = 33; a /= 12; b /= 4; diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-multiplication.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-multiplication.md index 6ba1434e32..5229214cda 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-multiplication.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-multiplication.md @@ -55,9 +55,9 @@ Non dovresti modificare il codice sopra il commento specificato. ```js assert( - /var a = 5;/.test(code) && - /var b = 12;/.test(code) && - /var c = 4\.6;/.test(code) + /let a = 5;/.test(code) && + /let b = 12;/.test(code) && + /let c = 4\.6;/.test(code) ); ``` @@ -72,9 +72,9 @@ assert( ## --seed-contents-- ```js -var a = 5; -var b = 12; -var c = 4.6; +let a = 5; +let b = 12; +let c = 4.6; // Only change code below this line a = a * 5; @@ -85,9 +85,9 @@ c = c * 10; # --solutions-- ```js -var a = 5; -var b = 12; -var c = 4.6; +let a = 5; +let b = 12; +let c = 4.6; a *= 5; b *= 3; diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-subtraction.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-subtraction.md index 37aaeb515a..9604a3105b 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-subtraction.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-subtraction.md @@ -55,7 +55,7 @@ Non dovresti modificare il codice sopra il commento specificato. ```js assert( - /var a = 11;/.test(code) && /var b = 9;/.test(code) && /var c = 3;/.test(code) + /let a = 11;/.test(code) && /let b = 9;/.test(code) && /let c = 3;/.test(code) ); ``` @@ -70,9 +70,9 @@ assert( ## --seed-contents-- ```js -var a = 11; -var b = 9; -var c = 3; +let a = 11; +let b = 9; +let c = 3; // Only change code below this line a = a - 6; @@ -83,9 +83,9 @@ c = c - 1; # --solutions-- ```js -var a = 11; -var b = 9; -var c = 3; +let a = 11; +let b = 9; +let c = 3; a -= 6; b -= 15; diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-plus-operator.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-plus-operator.md index 022391c2fa..4d892a62d2 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-plus-operator.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-plus-operator.md @@ -22,7 +22,7 @@ In JavaScript, quando l'operatore `+` viene usato con un valore di tipo `String` Esempio: ```js -var ourStr = "I come first. " + "I come second."; +const ourStr = "I come first. " + "I come second."; ``` La stringa `I come first. I come second.` sarebbe visualizzata nella console. @@ -44,10 +44,10 @@ Dovresti usare l'operatore `+` per costruire `myStr`. assert(code.match(/(["']).*\1\s*\+\s*(["']).*\2/g)); ``` -`myStr` dovrebbe essere creato usando la parola chiave `var`. +`myStr` dovrebbe essere creato usando la parola chiave `const`. ```js -assert(/var\s+myStr/.test(code)); +assert(/const\s+myStr/.test(code)); ``` Dovresti assegnare il risultato alla variabile `myStr`. @@ -73,11 +73,11 @@ assert(/myStr\s*=/.test(code)); ## --seed-contents-- ```js -var myStr; // Change this line +const myStr = ""; // Change this line ``` # --solutions-- ```js -var myStr = "This is the start. " + "This is the end."; +const myStr = "This is the start. " + "This is the end."; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-the-plus-equals-operator.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-the-plus-equals-operator.md index b8676edf8b..9dbaaec167 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-the-plus-equals-operator.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-the-plus-equals-operator.md @@ -16,7 +16,7 @@ Possiamo anche usare l'operatore `+=` per concatenare una stringa all Esempio: ```js -var ourStr = "I come first. "; +let ourStr = "I come first. "; ourStr += "I come second."; ``` @@ -57,14 +57,12 @@ assert(code.match(/myStr\s*\+=\s*(["']).*\1/g)); ## --seed-contents-- ```js -// Only change code below this line - -var myStr; +let myStr; ``` # --solutions-- ```js -var myStr = "This is the first sentence. "; +let myStr = "This is the first sentence. "; myStr += "This is the second sentence."; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/constructing-strings-with-variables.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/constructing-strings-with-variables.md index 809fc93be2..464e2e5b56 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/constructing-strings-with-variables.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/constructing-strings-with-variables.md @@ -14,8 +14,8 @@ A volte dovrai costruire una stringa, nello stile di [Mad Libs](https://en.wikip Esempio: ```js -var ourName = "freeCodeCamp"; -var ourStr = "Hello, our name is " + ourName + ", how are you?"; +const ourName = "freeCodeCamp"; +const ourStr = "Hello, our name is " + ourName + ", how are you?"; ``` `ourStr` avrà un valore stringa `Hello, our name is freeCodeCamp, how are you?`. @@ -63,13 +63,13 @@ assert(code.match(/["']\s*\+\s*myName\s*\+\s*["']/g).length > 0); ```js // Only change code below this line -var myName; -var myStr; +const myName = ""; +const myStr = ""; ``` # --solutions-- ```js -var myName = "Bob"; -var myStr = "My name is " + myName + " and I am well!"; +const myName = "Bob"; +const myStr = "My name is " + myName + " and I am well!"; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/count-backwards-with-a-for-loop.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/count-backwards-with-a-for-loop.md index 34f024419b..fb9839f603 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/count-backwards-with-a-for-loop.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/count-backwards-with-a-for-loop.md @@ -16,13 +16,14 @@ Per decrementare di due ad ogni iterazione, dovremo cambiare la nostra inizializ Inizieremo da `i = 10` e ripeteremo finché `i > 0`. Diminuiremo `i` di 2 ad ogni ciclo con `i -= 2`. ```js -var ourArray = []; -for (var i = 10; i > 0; i -= 2) { +const ourArray = []; + +for (let i = 10; i > 0; i -= 2) { ourArray.push(i); } ``` -`ourArray` adesso conterrà `[10,8,6,4,2]`. Cambiamo la nostra inizializzazione e espressione finale in modo da poter contare indietro di due per creare un array di numeri dispari discendenti. +`ourArray` adesso conterrà `[10, 8, 6, 4, 2]`. Cambiamo la nostra inizializzazione e espressione finale in modo da poter contare indietro di due per creare un array di numeri dispari discendenti. # --instructions-- @@ -42,7 +43,7 @@ Dovresti usare il metodo array `push`. assert(code.match(/myArray.push/)); ``` -`myArray` dovrebbe essere uguale a `[9,7,5,3,1]`. +`myArray` dovrebbe essere uguale a `[9, 7, 5, 3, 1]`. ```js assert.deepEqual(myArray, [9, 7, 5, 3, 1]); @@ -60,16 +61,17 @@ if(typeof myArray !== "undefined"){(function(){return myArray;})();} ```js // Setup -var myArray = []; +const myArray = []; // Only change code below this line + ``` # --solutions-- ```js -var myArray = []; -for (var i = 9; i > 0; i -= 2) { +const myArray = []; +for (let i = 9; i > 0; i -= 2) { myArray.push(i); } ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/counting-cards.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/counting-cards.md index cf0e722a4b..2b77d02d98 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/counting-cards.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/counting-cards.md @@ -159,7 +159,7 @@ assert( ## --seed-contents-- ```js -var count = 0; +let count = 0; function cc(card) { // Only change code below this line @@ -175,7 +175,7 @@ cc(2); cc(3); cc(7); cc('K'); cc('A'); # --solutions-- ```js -var count = 0; +let count = 0; function cc(card) { switch(card) { case 2: diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/create-decimal-numbers-with-javascript.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/create-decimal-numbers-with-javascript.md index 936dfa0527..8e3efadda9 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/create-decimal-numbers-with-javascript.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/create-decimal-numbers-with-javascript.md @@ -42,13 +42,14 @@ assert(myDecimal % 1 != 0); ## --seed-contents-- ```js -var ourDecimal = 5.7; +const ourDecimal = 5.7; // Only change code below this line + ``` # --solutions-- ```js -var myDecimal = 9.9; +const myDecimal = 9.9; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/declare-a-read-only-variable-with-the-const-keyword.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/declare-a-read-only-variable-with-the-const-keyword.md index cca667f914..4144ea4cec 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/declare-a-read-only-variable-with-the-const-keyword.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/declare-a-read-only-variable-with-the-const-keyword.md @@ -10,7 +10,7 @@ dashedName: declare-a-read-only-variable-with-the-const-keyword La parola chiave `let` non è l'unico nuovo modo per dichiarare le variabili. In ES6, puoi anche dichiarare variabili usando la parola chiave `const`. -`const` ha tutte le fantastiche caratteristiche che ha `let`, con il il valore aggiunto che le variabili dichiarate utilizzando `const` sono di sola lettura. Esse sono un valore costante, il che significa che una volta assegnata una variabile con `const`, non può più essere riassegnata. +`const` ha tutte le fantastiche caratteristiche che ha `let`, con il il valore aggiunto che le variabili dichiarate utilizzando `const` sono di sola lettura. Esse sono un valore costante, il che significa che una volta assegnata una variabile con `const`, non può più essere riassegnata: ```js const FAV_PET = "Cats"; @@ -19,9 +19,11 @@ FAV_PET = "Dogs"; La console mostrerà un errore a causa della riassegnazione del valore di `FAV_PET`. -Come puoi vedere, cercare di riassegnare una variabile dichiarata con `const` genererà un errore. Dovresti sempre dichiarare le variabili che non vuoi riassegnare usando la parola chiave `const`. Questo aiuta quando nel caso dovessi tentare accidentalmente di riassegnare il valore a una variabile che è destinata a rimanere costante. Una pratica comune quando si dà il nome alle costanti è usare tutte le lettere maiuscole, separando le parole con un underscore. +Dovresti sempre dichiarare le variabili che non vuoi riassegnare usando la parola chiave `const`. Questo aiuta quando nel caso dovessi tentare accidentalmente di riassegnare il valore a una variabile che è destinata a rimanere costante. -**Nota:** È pratica comune per gli sviluppatori usare identificatori di variabili a lettere maiuscole per valori immutabili e a lettere minuscole o camelCase per valori mutabili (oggetti e array). In una sfida successiva vedrai un esempio di identificatore di variabile con lettere minuscole utilizzato per un array. +Una pratica comune quando si dà il nome alle costanti è usare tutte le lettere maiuscole, separando le parole con un underscore. + +**Nota:** È pratica comune per gli sviluppatori usare identificatori di variabili a lettere maiuscole per valori immutabili e a lettere minuscole o camelCase per valori mutabili (oggetti e array). Imparerai di più su oggetti, array, e valori mutabili e immutabili in sfide future. In sfide future vedrai esempi di identificatori di variavile in maiuscolo, minuscolo e camelCase. # --instructions-- @@ -35,23 +37,33 @@ Modifica il codice in modo che tutte le variabili siano dichiarate utilizzando ` (getUserInput) => assert(!getUserInput('index').match(/var/g)); ``` -`SENTENCE` dovrebbe essere una variabile costante dichiarata con `const`. +Dovresti cambiare `fCC` a solo maiuscole. ```js -(getUserInput) => assert(getUserInput('index').match(/(const SENTENCE)/g)); +(getUserInput) => { + assert(getUserInput('index').match(/(FCC)/)); + assert(!getUserInput('index').match(/fCC/)); +} ``` -`i` dovrebbe essere dichiarata con `let`. +`FCC` dovrebbe essere una variabile costante dichiarata con `const`. ```js -(getUserInput) => assert(getUserInput('index').match(/(let i)/g)); +assert.equal(FCC, 'freeCodeCamp'); +assert.match(code, /const\s+FCC/); ``` -`console.log` dovrebbe essere cambiato per stampare la variabile `SENTENCE`. +`fact` dovrebbe essere dichiarata con `let`. + +```js +(getUserInput) => assert(getUserInput('index').match(/(let fact)/g)); +``` + +`console.log` dovrebbe essere cambiato in modo da stampare le variabili `FCC` e `fact`. ```js (getUserInput) => - assert(getUserInput('index').match(/console\.log\(\s*SENTENCE\s*\)\s*;?/g)); + assert(getUserInput('index').match(/console\.log\(\s*FCC\s*\,\s*fact\s*\)\s*;?/g)); ``` # --seed-- @@ -59,31 +71,21 @@ Modifica il codice in modo che tutte le variabili siano dichiarate utilizzando ` ## --seed-contents-- ```js -function printManyTimes(str) { +// Only change code below this line +var fCC = "freeCodeCamp"; +var fact = "is cool!"; +// Only change code above this line - // Only change code below this line - - var sentence = str + " is cool!"; - for (var i = 0; i < str.length; i+=2) { - console.log(sentence); - } - - // Only change code above this line - -} -printManyTimes("freeCodeCamp"); +fact = "is awesome!"; +console.log(fCC, fact); ``` # --solutions-- ```js -function printManyTimes(str) { +const FCC = "freeCodeCamp"; +let fact = "is cool!"; - const SENTENCE = str + " is cool!"; - for (let i = 0; i < str.length; i+=2) { - console.log(SENTENCE); - } - -} -printManyTimes("freeCodeCamp"); +fact = "is awesome!"; +console.log(FCC, fact); ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/declare-string-variables.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/declare-string-variables.md index 93851155f1..21013359bc 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/declare-string-variables.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/declare-string-variables.md @@ -9,13 +9,19 @@ dashedName: declare-string-variables # --description-- -Precedentemente abbiamo usato il codice +In precedenza hai usato il seguente codice per dichiarare una variabile: + +```js +var myName; +``` + +Ma puoi anche dichiarare una variabile con valore stringa in questo modo: ```js var myName = "your name"; ``` -`"your name"` è chiamato una stringa letterale. È una stringa perché è una serie di zero o più caratteri racchiusi in virgolette singole o doppie. +`"your name"` è chiamato una stringa letterale. Una stringa letterale, o stringa, è una serie di zero o più caratteri racchiusi in virgolette singole o doppie. # --instructions-- diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/decrement-a-number-with-javascript.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/decrement-a-number-with-javascript.md index 0c04704652..75bd853e1f 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/decrement-a-number-with-javascript.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/decrement-a-number-with-javascript.md @@ -39,7 +39,7 @@ assert(myVar === 10); ```js assert( - /var\s*myVar\s*=\s*11;\s*\/*.*\s*([-]{2}\s*myVar|myVar\s*[-]{2});/.test(code) + /let\s*myVar\s*=\s*11;\s*\/*.*\s*([-]{2}\s*myVar|myVar\s*[-]{2});/.test(code) ); ``` @@ -52,7 +52,7 @@ assert(/[-]{2}\s*myVar|myVar\s*[-]{2}/.test(code)); Non dovresti modificare il codice sopra il commento specificato. ```js -assert(/var myVar = 11;/.test(code)); +assert(/let myVar = 11;/.test(code)); ``` # --seed-- @@ -66,7 +66,7 @@ assert(/var myVar = 11;/.test(code)); ## --seed-contents-- ```js -var myVar = 11; +let myVar = 11; // Only change code below this line myVar = myVar - 1; @@ -75,6 +75,6 @@ myVar = myVar - 1; # --solutions-- ```js -var myVar = 11; +let myVar = 11; myVar--; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/delete-properties-from-a-javascript-object.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/delete-properties-from-a-javascript-object.md index 01b03808be..1ab4e1e7ad 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/delete-properties-from-a-javascript-object.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/delete-properties-from-a-javascript-object.md @@ -18,7 +18,7 @@ delete ourDog.bark; Esempio: ```js -var ourDog = { +const ourDog = { "name": "Camper", "legs": 4, "tails": 1, @@ -70,7 +70,7 @@ assert(code.match(/"tails": 1/g).length > 0); ```js // Setup -var myDog = { +const myDog = { "name": "Happy Coder", "legs": 4, "tails": 1, @@ -79,12 +79,13 @@ var myDog = { }; // Only change code below this line + ``` # --solutions-- ```js -var myDog = { +const myDog = { "name": "Happy Coder", "legs": 4, "tails": 1, diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-decimal-by-another-with-javascript.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-decimal-by-another-with-javascript.md index 1cca4be92d..ad30fcc1a9 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-decimal-by-another-with-javascript.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-decimal-by-another-with-javascript.md @@ -46,11 +46,11 @@ assert(code.match(/quotient/g).length === 1); ## --seed-contents-- ```js -var quotient = 0.0 / 2.0; // Change this line +const quotient = 0.0 / 2.0; // Change this line ``` # --solutions-- ```js -var quotient = 4.4 / 2.0; +const quotient = 4.4 / 2.0; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-number-by-another-with-javascript.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-number-by-another-with-javascript.md index 0240fb3111..0739cc32c2 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-number-by-another-with-javascript.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-number-by-another-with-javascript.md @@ -16,7 +16,7 @@ JavaScript utilizza il simbolo `/` per la divisione. **Esempio** ```js -myVar = 16 / 2; +const myVar = 16 / 2; ``` `myVar` ora ha il valore `8`. @@ -49,11 +49,11 @@ assert(/\d+\s*\/\s*\d+/.test(code)); ## --seed-contents-- ```js -var quotient = 66 / 0; +const quotient = 66 / 0; ``` # --solutions-- ```js -var quotient = 66 / 33; +const quotient = 66 / 33; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/escape-sequences-in-strings.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/escape-sequences-in-strings.md index 98b4514870..17aad98a65 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/escape-sequences-in-strings.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/escape-sequences-in-strings.md @@ -89,11 +89,11 @@ console.log('myStr:\n' + myStr);}})(); ## --seed-contents-- ```js -var myStr; // Change this line +const myStr = ""; // Change this line ``` # --solutions-- ```js -var myStr = "FirstLine\n\t\\SecondLine\nThirdLine"; +const myStr = "FirstLine\n\t\\SecondLine\nThirdLine"; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/escaping-literal-quotes-in-strings.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/escaping-literal-quotes-in-strings.md index 8a7022ecf3..40fc3c2823 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/escaping-literal-quotes-in-strings.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/escaping-literal-quotes-in-strings.md @@ -14,7 +14,7 @@ Quando definisci una stringa devi cominciare e finire con una virgoletta singola In JavaScript, puoi fare l'escape di una virgoletta per distinguerla da quella usata per terminare la stringa posizionando una barra rovesciata (`\`) davanti alla virgoletta. ```js -var sampleStr = "Alan said, \"Peter is learning JavaScript\"."; +const sampleStr = "Alan said, \"Peter is learning JavaScript\"."; ``` Questo segnala a JavaScript che la virgoletta seguente non è la fine della stringa, ma dovrebbe invece apparire dentro la stringa. Quindi se dovessi farla visualizzare nella console, otterresti: @@ -62,11 +62,11 @@ assert(/I am a "double quoted" string inside "double quotes(\."|"\.)$/.test(mySt ## --seed-contents-- ```js -var myStr = ""; // Change this line +const myStr = ""; // Change this line ``` # --solutions-- ```js -var myStr = "I am a \"double quoted\" string inside \"double quotes\"."; +const myStr = "I am a \"double quoted\" string inside \"double quotes\"."; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/explore-differences-between-the-var-and-let-keywords.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/explore-differences-between-the-var-and-let-keywords.md index 9e5a126c03..bc3fff3b86 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/explore-differences-between-the-var-and-let-keywords.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/explore-differences-between-the-var-and-let-keywords.md @@ -8,32 +8,30 @@ dashedName: explore-differences-between-the-var-and-let-keywords # --description-- -Uno dei maggiori problemi quando si dichiarano delle variabili con la parola chiave `var` è che è possibile sovrascrivere le dichiarazioni delle variabili senza errori. +Uno dei maggiori problemi quando si dichiarano delle variabili con la parola chiave `var` è che è possibile sovrascrivere facilmente le dichiarazioni delle variabili: ```js -var camper = 'James'; -var camper = 'David'; +var camper = "James"; +var camper = "David"; console.log(camper); ``` -Qui la console mostrerà la stringa `David`. +Nel codice qui sopra, la variabile `camper` è originariamente dichiarata come `James` per poi essere sovrascritta con `David`. La console poi mostra la stringa `David`. -Come puoi vedere nel codice qui sopra, la variabile `camper` è originariamente dichiarata come `James` per poi essere sovrascritta con `David`. In una piccola applicazione si potrebbe non incorrere in questo tipo di problema, ma quando il codice diventa più grande, potresti accidentalmente sovrascrivere una variabile che non hai intenzione di sovrascrivere. Poiché questo comportamento non lancia un errore, la ricerca e la correzione di bug diventa più difficile. -Una nuova parola chiave, chiamata `let`, è stata introdotta in ES6 per risolvere questo potenziale problema con la parola chiave `var`. Se dovessi sostituire `var` con `let` nelle dichiarazioni delle variabili nel codice sopra, il risultato sarebbe un errore. +In una piccola applicazione, potresti non incorrere in questo tipo di problema. Ma man mano che il tuo codebase diventa più grande potresti accidentalmente sovrascrivere una variabile che non intendevi sovrascrivere. Poiché questo comportamento non da errore, cercare e sistemare bug diventa più difficile. + +Una parola chiave chiamata `let` è stata introdotta in ES6, un aggiornamento importante a JavaScript, per risolvere questo potenziale problema con la parola chiave `var`. Imparerai altre caratteristiche di ES6 in sfide future. + +Se sostituisci `var` con `let` nel codice qua sopra, risulta in un errore: ```js -let camper = 'James'; -let camper = 'David'; +let camper = "James"; +let camper = "David"; ``` -Questo errore può essere visto nella console del tuo browser. Quindi, a differenza di `var`, quando si utilizza `let`, una variabile con lo stesso nome può essere dichiarata solo una volta. Nota l'`"use strict"`. Questo abilita la Strict Mode (Modalità Rigorosa), che cattura gli errori di codifica comuni e le azioni "non sicure". Per esempio: +L'errore può essere visto nella console del browser. -```js -"use strict"; -x = 3.14; -``` - -Questo mostrerà l'errore `x is not defined`. +Quindi a differenza di `var`, wuando usi `let`, una variabile con lo stesso nome può essere dichiarata una sola volta. # --instructions-- @@ -53,10 +51,10 @@ Aggiorna il codice in modo che utilizzi solo la parola chiave `let`. assert(catName === 'Oliver'); ``` -`quote` dovrebbe essere uguale alla stringa `Oliver says Meow!` +`catSound` dovrebbe essere uguale alla stringa `Meow!` ```js -assert(quote === 'Oliver says Meow!'); +assert(catSound === 'Meow!'); ``` # --seed-- @@ -64,28 +62,13 @@ assert(quote === 'Oliver says Meow!'); ## --seed-contents-- ```js -var catName; -var quote; -function catTalk() { - "use strict"; - - catName = "Oliver"; - quote = catName + " says Meow!"; - -} -catTalk(); +var catName = "Oliver"; +var catSound = "Meow!"; ``` # --solutions-- ```js -let catName; -let quote; -function catTalk() { - 'use strict'; - - catName = 'Oliver'; - quote = catName + ' says Meow!'; -} -catTalk(); +let catName = "Oliver"; +let catSound = "Meow!"; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/find-the-length-of-a-string.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/find-the-length-of-a-string.md index ccfc058a17..e590f6893d 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/find-the-length-of-a-string.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/find-the-length-of-a-string.md @@ -17,7 +17,7 @@ console.log("Alan Peter".length); Il valore `10` sarà visualizzato nella console. -Ad esempio, se avessimo creato una variabile `var firstName = "Ada"`, potremmo scoprire quanto è lunga la stringa `Ada` utilizzando la proprietà `firstName.length`. +Ad esempio, se avessimo creato una variabile `const firstName = "Ada"`, potremmo scoprire quanto è lunga la stringa `Ada` utilizzando la proprietà `firstName.length`. # --instructions-- @@ -29,8 +29,8 @@ Non dovresti cambiare le dichiarazioni della variabile nella sezione `// Setup`. ```js assert( - code.match(/var lastNameLength = 0;/) && - code.match(/var lastName = "Lovelace";/) + code.match(/let lastNameLength = 0;/) && + code.match(/const lastName = "Lovelace";/) ); ``` @@ -52,18 +52,17 @@ assert(code.match(/=\s*lastName\.length/g) && !code.match(/lastName\s*=\s*8/)); ```js // Setup -var lastNameLength = 0; -var lastName = "Lovelace"; +let lastNameLength = 0; +const lastName = "Lovelace"; // Only change code below this line - lastNameLength = lastName; ``` # --solutions-- ```js -var lastNameLength = 0; -var lastName = "Lovelace"; +let lastNameLength = 0; +const lastName = "Lovelace"; lastNameLength = lastName.length; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/finding-a-remainder-in-javascript.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/finding-a-remainder-in-javascript.md index 5640d2122b..5985a29924 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/finding-a-remainder-in-javascript.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/finding-a-remainder-in-javascript.md @@ -31,7 +31,7 @@ Imposta `remainder` pari al resto di `11` diviso per `3` utilizzando l'operatore La variabile `remainder` dovrebbe essere inizializzata ```js -assert(/var\s+?remainder/.test(code)); +assert(/(const|let|var)\s+?remainder/.test(code)); ``` Il valore di `remainder` dovrebbe essere `2` @@ -57,13 +57,11 @@ assert(/\s+?remainder\s*?=\s*?.*%.*;?/.test(code)); ## --seed-contents-- ```js -// Only change code below this line - -var remainder; +const remainder = 0; ``` # --solutions-- ```js -var remainder = 11 % 3; +const remainder = 11 % 3; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/global-scope-and-functions.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/global-scope-and-functions.md index 499da827e0..e662de1aad 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/global-scope-and-functions.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/global-scope-and-functions.md @@ -11,13 +11,13 @@ dashedName: global-scope-and-functions In JavaScript, lo scope (campo di applicazione o ambito di visibilità) si riferisce alla visibilità delle variabili. Le variabili che sono definite al di fuori del blocco di una funzione hanno un campo di applicazione globale. Questo significa che possono essere viste ovunque nel tuo codice JavaScript. -Le variabili che vengono dichiarate senza la parola chiave `var` vengono create automaticamente nell'ambito `global`. Questo può dare delle conseguenze indesiderate da un'altra parte nel tuo codice o quando si esegue nuovamente la funzione. Dovresti sempre dichiarare le tue variabili con `var`. +Le variabili che vengono dichiarate senza la parola chiave `let` o la parola chiave `const` vengono create automaticamente nell'ambito `global`. Questo può dare delle conseguenze indesiderate da un'altra parte nel tuo codice o quando si esegue nuovamente la funzione. Dovresti sempre dichiarare le tue variabili con `let` o `const`. # --instructions-- -Usando `var`, dichiara una variabile globale denominata `myGlobal` al di fuori di qualsiasi funzione. Inizializzala con un valore di `10`. +Usando `let` o `const`, dichiara una variabile globale denominata `myGlobal` al di fuori di qualsiasi funzione. Inizializzala con un valore di `10`. -All'interno della funzione `fun1`, assegna `5` a `oopsGlobal` ***senza*** utilizzare la parola chiave `var`. +All'interno della funzione `fun1`, assegna `5` a `oopsGlobal` ***senza*** utilizzare le parole chiave `let` o `const`. # --hints-- @@ -33,10 +33,10 @@ assert(typeof myGlobal != 'undefined'); assert(myGlobal === 10); ``` -`myGlobal` dovrebbe essere dichiarata usando la parola chiave `var` +`myGlobal` dovrebbe essere dichiarata usando la parola chiave `let` o `const` ```js -assert(/var\s+myGlobal/.test(code)); +assert(/(let|const)\s+myGlobal/.test(code)); ``` `oopsGlobal` dovrebbe essere una variabile globale e avere un valore di `5` @@ -109,7 +109,7 @@ function fun2() { # --solutions-- ```js -var myGlobal = 10; +const myGlobal = 10; function fun1() { oopsGlobal = 5; diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/global-vs.-local-scope-in-functions.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/global-vs.-local-scope-in-functions.md index 852c88daa2..40cedbbfd8 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/global-vs.-local-scope-in-functions.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/global-vs.-local-scope-in-functions.md @@ -14,9 +14,10 @@ dashedName: global-vs--local-scope-in-functions In questo esempio: ```js -var someVar = "Hat"; +const someVar = "Hat"; + function myFun() { - var someVar = "Head"; + const someVar = "Head"; return someVar; } ``` @@ -53,13 +54,11 @@ assert(/return outerWear/.test(code)); ```js // Setup -var outerWear = "T-Shirt"; +const outerWear = "T-Shirt"; function myOutfit() { // Only change code below this line - - // Only change code above this line return outerWear; } @@ -70,9 +69,9 @@ myOutfit(); # --solutions-- ```js -var outerWear = "T-Shirt"; +const outerWear = "T-Shirt"; function myOutfit() { - var outerWear = "sweater"; + const outerWear = "sweater"; return outerWear; } ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/golf-code.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/golf-code.md index ba3b91c600..e74d90aead 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/golf-code.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/golf-code.md @@ -90,7 +90,8 @@ assert(golfScore(5, 9) === 'Go Home!'); ## --seed-contents-- ```js -var names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"]; +const names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"]; + function golfScore(par, strokes) { // Only change code below this line diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/increment-a-number-with-javascript.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/increment-a-number-with-javascript.md index 8d0f9a7c1f..435b92ad32 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/increment-a-number-with-javascript.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/increment-a-number-with-javascript.md @@ -39,7 +39,7 @@ Non dovresti utilizzare l'operatore di assegnazione. ```js assert( - /var\s*myVar\s*=\s*87;\s*\/*.*\s*([+]{2}\s*myVar|myVar\s*[+]{2});/.test(code) + /let\s*myVar\s*=\s*87;\s*\/*.*\s*([+]{2}\s*myVar|myVar\s*[+]{2});/.test(code) ); ``` @@ -52,7 +52,7 @@ assert(/[+]{2}\s*myVar|myVar\s*[+]{2}/.test(code)); Non dovresti cambiare il codice sopra il commento specificato. ```js -assert(/var myVar = 87;/.test(code)); +assert(/let myVar = 87;/.test(code)); ``` # --seed-- @@ -66,7 +66,7 @@ assert(/var myVar = 87;/.test(code)); ## --seed-contents-- ```js -var myVar = 87; +let myVar = 87; // Only change code below this line myVar = myVar + 1; @@ -75,6 +75,6 @@ myVar = myVar + 1; # --solutions-- ```js -var myVar = 87; +let myVar = 87; myVar++; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/introducing-else-statements.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/introducing-else-statements.md index 5a725a78ec..640f3be83a 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/introducing-else-statements.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/introducing-else-statements.md @@ -64,7 +64,7 @@ assert(testElse(10) === 'Bigger than 5'); Non dovresti modificare il codice sopra o sotto i commenti specificati. ```js -assert(/var result = "";/.test(code) && /return result;/.test(code)); +assert(/let result = "";/.test(code) && /return result;/.test(code)); ``` # --seed-- @@ -73,7 +73,7 @@ assert(/var result = "";/.test(code) && /return result;/.test(code)); ```js function testElse(val) { - var result = ""; + let result = ""; // Only change code below this line if (val > 5) { @@ -95,7 +95,7 @@ testElse(4); ```js function testElse(val) { - var result = ""; + let result = ""; if(val > 5) { result = "Bigger than 5"; } else { diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-odd-numbers-with-a-for-loop.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-odd-numbers-with-a-for-loop.md index 8da2578342..02f2ac569b 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-odd-numbers-with-a-for-loop.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-odd-numbers-with-a-for-loop.md @@ -14,13 +14,14 @@ I cicli for non devono necessariamente iterare un numero alla volta. Modificando Inizieremo da `i = 0` e ripeteremo il ciclo finché `i < 10`. Incrementeremo `i` di 2 ad ogni ciclo con `i += 2`. ```js -var ourArray = []; -for (var i = 0; i < 10; i += 2) { +const ourArray = []; + +for (let i = 0; i < 10; i += 2) { ourArray.push(i); } ``` -`ourArray` ora conterrà `[0,2,4,6,8]`. Cambiamo la nostra `initialization` in modo da poter iterare sui numeri dispari. +`ourArray` ora conterrà `[0, 2, 4, 6, 8]`. Cambiamo la nostra `initialization` in modo da poter iterare sui numeri dispari. # --instructions-- @@ -34,7 +35,7 @@ Dovresti usare un ciclo `for`. assert(/for\s*\([^)]+?\)/.test(code)); ``` -`myArray` dovrebbe essere uguale a `[1,3,5,7,9]`. +`myArray` dovrebbe essere uguale a `[1, 3, 5, 7, 9]`. ```js assert.deepEqual(myArray, [1, 3, 5, 7, 9]); @@ -52,16 +53,17 @@ if(typeof myArray !== "undefined"){(function(){return myArray;})();} ```js // Setup -var myArray = []; +const myArray = []; // Only change code below this line + ``` # --solutions-- ```js -var myArray = []; -for (var i = 1; i < 10; i += 2) { +const myArray = []; +for (let i = 1; i < 10; i += 2) { myArray.push(i); } ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-through-an-array-with-a-for-loop.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-through-an-array-with-a-for-loop.md index ab85b7eac8..5be90a8aae 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-through-an-array-with-a-for-loop.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-through-an-array-with-a-for-loop.md @@ -12,8 +12,9 @@ dashedName: iterate-through-an-array-with-a-for-loop Un compito comune in JavaScript è quello di iterare attraverso i contenuti di un array. Un modo per farlo è con un ciclo `for`. Questo codice visualizzerà ogni elemento dell'array `arr` nella console: ```js -var arr = [10, 9, 8, 7, 6]; -for (var i = 0; i < arr.length; i++) { +const arr = [10, 9, 8, 7, 6]; + +for (let i = 0; i < arr.length; i++) { console.log(arr[i]); } ``` @@ -62,18 +63,19 @@ assert(!__helpers.removeWhiteSpace(code).match(/total[=+-]0*[1-9]+/gm)); ```js // Setup -var myArr = [ 2, 3, 4, 5, 6]; +const myArr = [2, 3, 4, 5, 6]; // Only change code below this line + ``` # --solutions-- ```js -var myArr = [ 2, 3, 4, 5, 6]; -var total = 0; +const myArr = [2, 3, 4, 5, 6]; +let total = 0; -for (var i = 0; i < myArr.length; i++) { +for (let i = 0; i < myArr.length; i++) { total += myArr[i]; } ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-do...while-loops.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-do...while-loops.md index 83c3450121..e55ddddf26 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-do...while-loops.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-do...while-loops.md @@ -12,8 +12,9 @@ dashedName: iterate-with-javascript-do---while-loops Il prossimo tipo di ciclo che vedremo si chiama `do...while`. Si chiama ciclo `do... while` perché prima eseguirà (`do`) un passaggio del codice all'interno del ciclo indipendentemente dalle condizioni, e poi continuerà ad eseguire il ciclo finché (`while`) la condizione specificata avrà valore `true`. ```js -var ourArray = []; -var i = 0; +const ourArray = []; +let i = 0; + do { ourArray.push(i); i++; @@ -23,8 +24,9 @@ do { L'esempio sopra si comporta come altri tipi di cicli, e l'array risultante sarà `[0, 1, 2, 3, 4]`. Tuttavia, ciò che rende il `do...while` diverso da altri cicli è come si comporta quando la condizione fallisce al primo controllo. Vediamolo in azione: ecco un normale ciclo `while` che eseguirà il codice nel ciclo finché `i < 5`: ```js -var ourArray = []; -var i = 5; +const ourArray = []; +let i = 5; + while (i < 5) { ourArray.push(i); i++; @@ -34,8 +36,9 @@ while (i < 5) { In questo esempio, inizializziamo il valore di `ourArray` a un array vuoto e il valore di `i` a 5. Quando eseguiamo il ciclo `while`, la condizione vale `false` perché `i` non è inferiore a 5, e in questo modo non eseguiremo il codice all'interno del ciclo. Il risultato è che `ourArray` finirà per non avere valori aggiunti, e sarà ancora simile a `[]` quando tutto il codice nell'esempio precedente sarà stato completato. Ora, dai un'occhiata a un ciclo `do...while`: ```js -var ourArray = []; -var i = 5; +const ourArray = []; +let i = 5; + do { ourArray.push(i); i++; @@ -80,8 +83,8 @@ if(typeof myArray !== "undefined"){(function(){return myArray;})();} ```js // Setup -var myArray = []; -var i = 10; +const myArray = []; +let i = 10; // Only change code below this line while (i < 5) { @@ -93,8 +96,8 @@ while (i < 5) { # --solutions-- ```js -var myArray = []; -var i = 10; +const myArray = []; +let i = 10; do { myArray.push(i); i++; diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-for-loops.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-for-loops.md index 4ad581c295..46a73d0507 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-for-loops.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-for-loops.md @@ -26,13 +26,14 @@ L'espressione finale è eseguita alla fine di ogni iterazione del ciclo, prima d Nell'esempio seguente inizializziamo con `i = 0` e iteriamo finché la nostra condizione `i < 5` è vera. Incrementeremo `i` di `1` ad ogni iterazione del ciclo con `i++` come espressione finale. ```js -var ourArray = []; -for (var i = 0; i < 5; i++) { +const ourArray = []; + +for (let i = 0; i < 5; i++) { ourArray.push(i); } ``` -`ourArray` ha ora il valore `[0,1,2,3,4]`. +`ourArray` ha ora il valore `[0, 1, 2, 3, 4]`. # --instructions-- @@ -46,7 +47,7 @@ Dovresti usare un ciclo `for`. assert(/for\s*\([^)]+?\)/.test(code)); ``` -`myArray` dovrebbe essere uguale a `[1,2,3,4,5]`. +`myArray` dovrebbe essere uguale a `[1, 2, 3, 4, 5]`. ```js assert.deepEqual(myArray, [1, 2, 3, 4, 5]); @@ -64,16 +65,17 @@ if (typeof myArray !== "undefined"){(function(){return myArray;})();} ```js // Setup -var myArray = []; +const myArray = []; // Only change code below this line + ``` # --solutions-- ```js -var myArray = []; -for (var i = 1; i < 6; i++) { +const myArray = []; +for (let i = 1; i < 6; i++) { myArray.push(i); } ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-while-loops.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-while-loops.md index 266673087d..0aa2bb494e 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-while-loops.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-while-loops.md @@ -14,9 +14,10 @@ dashedName: iterate-with-javascript-while-loops Il primo tipo di ciclo che vedremo è chiamato un ciclo `while` perché viene eseguito finché (while) una condizione specificata è vera e si arresta una volta che la condizione non è più vera. ```js -var ourArray = []; -var i = 0; -while(i < 5) { +const ourArray = []; +let i = 0; + +while (i < 5) { ourArray.push(i); i++; } @@ -38,7 +39,7 @@ Dovresti usare un ciclo `while`. assert(code.match(/while/g)); ``` -`myArray` dovrebbe essere uguale a `[5,4,3,2,1,0]`. +`myArray` dovrebbe essere uguale a `[5, 4, 3, 2, 1, 0]`. ```js assert.deepEqual(myArray, [5, 4, 3, 2, 1, 0]); @@ -56,17 +57,18 @@ if(typeof myArray !== "undefined"){(function(){return myArray;})();} ```js // Setup -var myArray = []; +const myArray = []; // Only change code below this line + ``` # --solutions-- ```js -var myArray = []; -var i = 5; -while(i >= 0) { +const myArray = []; +let i = 5; +while (i >= 0) { myArray.push(i); i--; } diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/local-scope-and-functions.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/local-scope-and-functions.md index cd289d6d2e..49cc50547e 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/local-scope-and-functions.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/local-scope-and-functions.md @@ -15,9 +15,10 @@ Ecco una funzione `myTest` con una variabile locale chiamata `loc`. ```js function myTest() { - var loc = "foo"; + const loc = "foo"; console.log(loc); } + myTest(); console.log(loc); ``` @@ -38,6 +39,7 @@ Il codice non dovrebbe contenere una variabile globale `myVar`. function declared() { myVar; } + assert.throws(declared, ReferenceError); ``` @@ -57,7 +59,6 @@ assert( ```js function myLocalScope() { - // Only change code below this line console.log('inside myLocalScope', myVar); @@ -73,9 +74,8 @@ console.log('outside myLocalScope', myVar); ```js function myLocalScope() { - // Only change code below this line - var myVar; + let myVar; console.log('inside myLocalScope', myVar); } myLocalScope(); diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-pop.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-pop.md index c1e3d5b8e9..1b84fa8670 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-pop.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-pop.md @@ -16,8 +16,8 @@ Un altro modo per cambiare i dati in un array è con la funzione `.pop()`. Qualsiasi tipo di elemento può essere estratto da un array - numeri, stringhe, anche array annidati. ```js -var threeArr = [1, 4, 6]; -var oneDown = threeArr.pop(); +const threeArr = [1, 4, 6]; +const oneDown = threeArr.pop(); console.log(oneDown); console.log(threeArr); ``` @@ -26,7 +26,7 @@ Il primo `console.log` mostrerà il valore `6`e il secondo mostrerà il valore ` # --instructions-- -Utilizza la funzione `.pop()` per rimuovere l'ultimo elemento da `myArray`, assegnando il valore estratto a `removedFromMyArray`. +Utilizza la funzione `.pop()` per rimuovere l'ultimo elemento da `myArray` e assegna il valore estratto a `removedFromMyArray`. # --hints-- @@ -69,22 +69,22 @@ assert( ## --after-user-code-- ```js -(function(y, z){return 'myArray = ' + JSON.stringify(y) + ' & removedFromMyArray = ' + JSON.stringify(z);})(myArray, removedFromMyArray); +if (typeof removedFromMyArray !== 'undefined') (function(y, z){return 'myArray = ' + JSON.stringify(y) + ' & removedFromMyArray = ' + JSON.stringify(z);})(myArray, removedFromMyArray); ``` ## --seed-contents-- ```js // Setup -var myArray = [["John", 23], ["cat", 2]]; +const myArray = [["John", 23], ["cat", 2]]; // Only change code below this line -var removedFromMyArray; + ``` # --solutions-- ```js -var myArray = [["John", 23], ["cat", 2]]; -var removedFromMyArray = myArray.pop(); +const myArray = [["John", 23], ["cat", 2]]; +const removedFromMyArray = myArray.pop(); ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-push.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-push.md index a09fe87259..f1ffde2dfb 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-push.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-push.md @@ -16,10 +16,10 @@ Un modo semplice per aggiungere dei dati alla fine di un array è tramite la fun Esempi: ```js -var arr1 = [1,2,3]; +const arr1 = [1, 2, 3]; arr1.push(4); -var arr2 = ["Stimpson", "J", "cat"]; +const arr2 = ["Stimpson", "J", "cat"]; arr2.push(["happy", "joy"]); ``` @@ -64,14 +64,15 @@ assert( ```js // Setup -var myArray = [["John", 23], ["cat", 2]]; +const myArray = [["John", 23], ["cat", 2]]; // Only change code below this line + ``` # --solutions-- ```js -var myArray = [["John", 23], ["cat", 2]]; +const myArray = [["John", 23], ["cat", 2]]; myArray.push(["dog",3]); ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-shift.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-shift.md index 6486d361e5..302b952f49 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-shift.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-shift.md @@ -16,15 +16,15 @@ dashedName: manipulate-arrays-with-shift Esempio: ```js -var ourArray = ["Stimpson", "J", ["cat"]]; -var removedFromOurArray = ourArray.shift(); +const ourArray = ["Stimpson", "J", ["cat"]]; +const removedFromOurArray = ourArray.shift(); ``` `removedFromOurArray` dovrebbe avere un valore stringa `Stimpson`e `ourArray` dovrebbe valere `["J", ["cat"]]`. # --instructions-- -Utilizza la funzione `.shift()` per rimuovere il primo elemento da `myArray`, assegnando il valore "spostato" a `removedFromMyArray`. +Utilizza la funzione `.shift()` per rimuovere il primo elemento da `myArray` e assegna il valore estratto a `removedFromMyArray`. # --hints-- @@ -65,24 +65,24 @@ assert( ## --after-user-code-- ```js -(function(y, z){return 'myArray = ' + JSON.stringify(y) + ' & removedFromMyArray = ' + JSON.stringify(z);})(myArray, removedFromMyArray); +if (typeof removedFromMyArray !== 'undefined') (function(y, z){return 'myArray = ' + JSON.stringify(y) + ' & removedFromMyArray = ' + JSON.stringify(z);})(myArray, removedFromMyArray); ``` ## --seed-contents-- ```js // Setup -var myArray = [["John", 23], ["dog", 3]]; +const myArray = [["John", 23], ["dog", 3]]; // Only change code below this line -var removedFromMyArray; + ``` # --solutions-- ```js -var myArray = [["John", 23], ["dog", 3]]; +const myArray = [["John", 23], ["dog", 3]]; // Only change code below this line -var removedFromMyArray = myArray.shift(); +const removedFromMyArray = myArray.shift(); ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-unshift.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-unshift.md index 63437d2bd2..9eded38dad 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-unshift.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-unshift.md @@ -16,7 +16,7 @@ Non puoi solo fare uno `shift` di elementi dall'inizio di un array: puoi anche f Esempio: ```js -var ourArray = ["Stimpson", "J", "cat"]; +const ourArray = ["Stimpson", "J", "cat"]; ourArray.shift(); ourArray.unshift("Happy"); ``` @@ -25,7 +25,7 @@ Dopo lo `shift`, `ourArray` avrà il valore `["J", "cat"]`. Dopo l'`unshift`, `o # --instructions-- -Aggiungi `["Paul",35]` all'inizio della variabile `myArray` usando `unshift()`. +Aggiungi `["Paul", 35]` all'inizio della variabile `myArray` usando `unshift()`. # --hints-- @@ -63,16 +63,17 @@ assert( ```js // Setup -var myArray = [["John", 23], ["dog", 3]]; +const myArray = [["John", 23], ["dog", 3]]; myArray.shift(); // Only change code below this line + ``` # --solutions-- ```js -var myArray = [["John", 23], ["dog", 3]]; +const myArray = [["John", 23], ["dog", 3]]; myArray.shift(); myArray.unshift(["Paul", 35]); ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/manipulating-complex-objects.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/manipulating-complex-objects.md index 7dc5e34fff..ee2a3f97b1 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/manipulating-complex-objects.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/manipulating-complex-objects.md @@ -14,7 +14,7 @@ A volte potresti voler memorizzare i dati in una struttura di dati fl Ecco un esempio di struttura di dati complessa: ```js -var ourMusic = [ +const ourMusic = [ { "artist": "Daft Punk", "title": "Homework", @@ -135,7 +135,7 @@ myMusic.forEach(object => { ## --seed-contents-- ```js -var myMusic = [ +const myMusic = [ { "artist": "Billy Joel", "title": "Piano Man", @@ -153,7 +153,7 @@ var myMusic = [ # --solutions-- ```js -var myMusic = [ +const myMusic = [ { "artist": "Billy Joel", "title": "Piano Man", diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/modify-array-data-with-indexes.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/modify-array-data-with-indexes.md index e1d6023794..f88063fda3 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/modify-array-data-with-indexes.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/modify-array-data-with-indexes.md @@ -9,12 +9,12 @@ dashedName: modify-array-data-with-indexes # --description-- -A differenza delle stringhe, gli elementi degli array sono mutabili e possono essere cambiati liberamente. +A differenza delle stringhe, gli elementi degli array sono mutabili e possono essere cambiati liberamente, anche se l'array è stato dichiarato con `const`. **Esempio** ```js -var ourArray = [50,40,30]; +const ourArray = [50, 40, 30]; ourArray[0] = 15; ``` @@ -28,7 +28,7 @@ Modificare i dati memorizzati all'indice `0` di `myArray` a un valore di `45`. # --hints-- -`myArray` dovrebbe ora essere `[45,64,99]`. +`myArray` dovrebbe ora essere `[45, 64, 99]`. ```js assert( @@ -73,14 +73,15 @@ if(typeof myArray !== "undefined"){(function(){return myArray;})();} ```js // Setup -var myArray = [18,64,99]; +const myArray = [18, 64, 99]; // Only change code below this line + ``` # --solutions-- ```js -var myArray = [18,64,99]; +const myArray = [18, 64, 99]; myArray[0] = 45; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/multiple-identical-options-in-switch-statements.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/multiple-identical-options-in-switch-statements.md index 91ee911e17..75ac587771 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/multiple-identical-options-in-switch-statements.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/multiple-identical-options-in-switch-statements.md @@ -12,7 +12,7 @@ dashedName: multiple-identical-options-in-switch-statements Se l'istruzione `break` viene omessa da un'istruzione `switch` e in particolare da un suo `case`, le istruzione `case` successive sono eseguite fino a quando non si incontra un `break`. Se hai diversi input con lo stesso output, potrai rappresentarli in un'istruzione `switch` come la seguente: ```js -var result = ""; +let result = ""; switch(val) { case 1: case 2: @@ -109,7 +109,7 @@ assert(code.match(/case/g).length === 9); ```js function sequentialSizes(val) { - var answer = ""; + let answer = ""; // Only change code below this line @@ -125,7 +125,7 @@ sequentialSizes(1); ```js function sequentialSizes(val) { - var answer = ""; + let answer = ""; switch(val) { case 1: diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-decimals-with-javascript.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-decimals-with-javascript.md index 0154e925e8..ba1c14e105 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-decimals-with-javascript.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-decimals-with-javascript.md @@ -42,11 +42,11 @@ assert(/\*/.test(code)); ## --seed-contents-- ```js -var product = 2.0 * 0.0; +const product = 2.0 * 0.0; ``` # --solutions-- ```js -var product = 2.0 * 2.5; +const product = 2.0 * 2.5; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-numbers-with-javascript.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-numbers-with-javascript.md index 9f83522436..4895a754e9 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-numbers-with-javascript.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-numbers-with-javascript.md @@ -16,7 +16,7 @@ JavaScript utilizza il simbolo `*` per la moltiplicazione di due numeri. **Esempio** ```js -myVar = 13 * 13; +const myVar = 13 * 13; ``` `myVar` dovrebbe avere il valore `169`. @@ -50,11 +50,11 @@ assert(/\*/.test(code)); ## --seed-contents-- ```js -var product = 8 * 0; +const product = 8 * 0; ``` # --solutions-- ```js -var product = 8 * 10; +const product = 8 * 10; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/nest-one-array-within-another-array.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/nest-one-array-within-another-array.md index 63ca252c75..a0d376d974 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/nest-one-array-within-another-array.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/nest-one-array-within-another-array.md @@ -12,7 +12,7 @@ dashedName: nest-one-array-within-another-array È anche possibile nidificare array all'interno di altri array, come nell'esempio: ```js -[["Bulls", 23], ["White Sox", 45]] +const teams = [["Bulls", 23], ["White Sox", 45]]; ``` Questo viene anche chiamato un array multidimensionale. @@ -41,11 +41,11 @@ if(typeof myArray !== "undefined"){(function(){return myArray;})();} ```js // Only change code below this line -var myArray = []; +const myArray = []; ``` # --solutions-- ```js -var myArray = [[1,2,3]]; +const myArray = [[1, 2, 3]]; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/nesting-for-loops.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/nesting-for-loops.md index c098d946a5..111d183e81 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/nesting-for-loops.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/nesting-for-loops.md @@ -12,11 +12,12 @@ dashedName: nesting-for-loops Se disponi di un array multidimensionale, è possibile utilizzare la stessa logica del punto precedente per iterare sia attraverso l'array che attraverso i suoi sottoarray. Ecco un esempio: ```js -var arr = [ - [1,2], [3,4], [5,6] +const arr = [ + [1, 2], [3, 4], [5, 6] ]; -for (var i=0; i < arr.length; i++) { - for (var j=0; j < arr[i].length; j++) { + +for (let i = 0; i < arr.length; i++) { + for (let j = 0; j < arr[i].length; j++) { console.log(arr[i][j]); } } @@ -30,13 +31,13 @@ Modifica la funzione `multiplyAll` in modo che restituisca il prodotto di tutti # --hints-- -`multiplyAll([[1],[2],[3]])` dovrebbe restituire `6` +`multiplyAll([[1], [2], [3]])` dovrebbe restituire `6` ```js assert(multiplyAll([[1], [2], [3]]) === 6); ``` -`multiplyAll([[1,2],[3,4],[5,6,7]])` dovrebbe restituire `5040` +`multiplyAll([[1, 2], [3, 4], [5, 6, 7]])` dovrebbe restituire `5040` ```js assert( @@ -48,7 +49,7 @@ assert( ); ``` -`multiplyAll([[5,1],[0.2, 4, 0.5],[3, 9]])` dovrebbe restituire `54` +`multiplyAll([[5, 1], [0.2, 4, 0.5], [3, 9]])` dovrebbe restituire `54` ```js assert( @@ -66,28 +67,26 @@ assert( ```js function multiplyAll(arr) { - var product = 1; + let product = 1; // Only change code below this line // Only change code above this line return product; } -multiplyAll([[1,2],[3,4],[5,6,7]]); +multiplyAll([[1, 2], [3, 4], [5, 6, 7]]); ``` # --solutions-- ```js function multiplyAll(arr) { - var product = 1; - for (var i = 0; i < arr.length; i++) { - for (var j = 0; j < arr[i].length; j++) { + let product = 1; + for (let i = 0; i < arr.length; i++) { + for (let j = 0; j < arr[i].length; j++) { product *= arr[i][j]; } } return product; } - -multiplyAll([[1,2],[3,4],[5,6,7]]); ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/profile-lookup.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/profile-lookup.md index ee07d56f52..f4955a3dd1 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/profile-lookup.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/profile-lookup.md @@ -68,34 +68,33 @@ assert(lookUpProfile('Akira', 'address') === 'No such property'); ```js // Setup -var contacts = [ - { - "firstName": "Akira", - "lastName": "Laine", - "number": "0543236543", - "likes": ["Pizza", "Coding", "Brownie Points"] - }, - { - "firstName": "Harry", - "lastName": "Potter", - "number": "0994372684", - "likes": ["Hogwarts", "Magic", "Hagrid"] - }, - { - "firstName": "Sherlock", - "lastName": "Holmes", - "number": "0487345643", - "likes": ["Intriguing Cases", "Violin"] - }, - { - "firstName": "Kristian", - "lastName": "Vos", - "number": "unknown", - "likes": ["JavaScript", "Gaming", "Foxes"] - } +const contacts = [ + { + firstName: "Akira", + lastName: "Laine", + number: "0543236543", + likes: ["Pizza", "Coding", "Brownie Points"], + }, + { + firstName: "Harry", + lastName: "Potter", + number: "0994372684", + likes: ["Hogwarts", "Magic", "Hagrid"], + }, + { + firstName: "Sherlock", + lastName: "Holmes", + number: "0487345643", + likes: ["Intriguing Cases", "Violin"], + }, + { + firstName: "Kristian", + lastName: "Vos", + number: "unknown", + likes: ["JavaScript", "Gaming", "Foxes"], + }, ]; - function lookUpProfile(name, prop) { // Only change code below this line @@ -108,44 +107,38 @@ lookUpProfile("Akira", "likes"); # --solutions-- ```js -var contacts = [ - { - "firstName": "Akira", - "lastName": "Laine", - "number": "0543236543", - "likes": ["Pizza", "Coding", "Brownie Points"] - }, - { - "firstName": "Harry", - "lastName": "Potter", - "number": "0994372684", - "likes": ["Hogwarts", "Magic", "Hagrid"] - }, - { - "firstName": "Sherlock", - "lastName": "Holmes", - "number": "0487345643", - "likes": ["Intriguing Cases", "Violin"] - }, - { - "firstName": "Kristian", - "lastName": "Vos", - "number": "unknown", - "likes": ["JavaScript", "Gaming", "Foxes"] - }, +const contacts = [ + { + firstName: "Akira", + lastName: "Laine", + number: "0543236543", + likes: ["Pizza", "Coding", "Brownie Points"], + }, + { + firstName: "Harry", + lastName: "Potter", + number: "0994372684", + likes: ["Hogwarts", "Magic", "Hagrid"], + }, + { + firstName: "Sherlock", + lastName: "Holmes", + number: "0487345643", + likes: ["Intriguing Cases", "Violin"], + }, + { + firstName: "Kristian", + lastName: "Vos", + number: "unknown", + likes: ["JavaScript", "Gaming", "Foxes"], + }, ]; - - -//Write your function in between these comments -function lookUpProfile(name, prop){ - for(var i in contacts){ - if(contacts[i].firstName === name) { - return contacts[i][prop] || "No such property"; - } +function lookUpProfile(name, prop) { + for (let i in contacts) { + if (contacts[i].firstName === name) { + return contacts[i][prop] || "No such property"; } - return "No such contact"; + } + return "No such contact"; } -//Write your function in between these comments - -lookUpProfile("Akira", "likes"); ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/quoting-strings-with-single-quotes.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/quoting-strings-with-single-quotes.md index 4bfd19ae6c..5f9caec414 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/quoting-strings-with-single-quotes.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/quoting-strings-with-single-quotes.md @@ -12,21 +12,21 @@ dashedName: quoting-strings-with-single-quotes I valori Stringa in JavaScript possono essere scritti con virgolette singole o doppie, purché si inizi e si termini con lo stesso tipo di virgolette. A differenza di alcuni altri linguaggi di programmazione, le virgolette singole e doppie funzionano allo stesso modo in JavaScript. ```js -doubleQuoteStr = "This is a string"; -singleQuoteStr = 'This is also a string'; +const doubleQuoteStr = "This is a string"; +const singleQuoteStr = 'This is also a string'; ``` Il motivo per cui potresti voler usare un tipo di virgolette piuttosto dell'altro è se volessi usare entrambi in una stringa. Questo potrebbe accadere volendo salvare una conversazione in una stringa e avendo la conversazione tra virgolette. Un altro uso sarebbe salvare un tag `` con vari attributi tra virgolette, tutto all'interno di una stringa. ```js -conversation = 'Finn exclaims to Jake, "Algebraic!"'; +const conversation = 'Finn exclaims to Jake, "Algebraic!"'; ``` Tuttavia, questo diventa un problema se è necessario utilizzare le virgolette più esterne al suo interno. Ricorda, una stringa ha lo stesso tipo di virgolette all'inizio e alla fine. Ma se hai la stessa virgoletta da qualche parte nel mezzo, la stringa si fermerà anzitempo e lancerà un errore. ```js -goodStr = 'Jake asks Finn, "Hey, let\'s go on an adventure?"'; -badStr = 'Finn responds, "Let's go!"'; +const goodStr = 'Jake asks Finn, "Hey, let\'s go on an adventure?"'; +const badStr = 'Finn responds, "Let's go!"'; ``` Qui `badStr` genererà un errore. @@ -71,11 +71,11 @@ assert(code.match(/"/g).length === 4 && code.match(/'/g).length === 2); ## --seed-contents-- ```js -var myStr = "Link"; +const myStr = "Link"; ``` # --solutions-- ```js -var myStr = 'Link'; +const myStr = 'Link'; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/record-collection.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/record-collection.md index 3614886d35..12a7b5a260 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/record-collection.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/record-collection.md @@ -115,7 +115,7 @@ const _recordCollection = { ```js // Setup -var recordCollection = { +const recordCollection = { 2548: { albumTitle: 'Slippery When Wet', artist: 'Bon Jovi', @@ -146,7 +146,7 @@ updateRecords(recordCollection, 5439, 'artist', 'ABBA'); # --solutions-- ```js -var recordCollection = { +const recordCollection = { 2548: { albumTitle: 'Slippery When Wet', artist: 'Bon Jovi', diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/replace-loops-using-recursion.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/replace-loops-using-recursion.md index 33bba64de8..a429908231 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/replace-loops-using-recursion.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/replace-loops-using-recursion.md @@ -14,9 +14,9 @@ La ricorsione è il concetto che una funzione può essere espressa in termini di ```js function multiply(arr, n) { - var product = 1; - for (var i = 0; i < n; i++) { - product *= arr[i]; + let product = 1; + for (let i = 0; i < n; i++) { + product *= arr[i]; } return product; } diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/replacing-if-else-chains-with-switch.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/replacing-if-else-chains-with-switch.md index 6db6c8ebfc..0495ccbb34 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/replacing-if-else-chains-with-switch.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/replacing-if-else-chains-with-switch.md @@ -108,7 +108,7 @@ assert(chainToSwitch(156) === ''); ```js function chainToSwitch(val) { - var answer = ""; + let answer = ""; // Only change code below this line if (val === "bob") { @@ -134,7 +134,7 @@ chainToSwitch(7); ```js function chainToSwitch(val) { - var answer = ""; + let answer = ""; switch(val) { case "bob": diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/return-a-value-from-a-function-with-return.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/return-a-value-from-a-function-with-return.md index 3ef69cfb90..a00a5893cb 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/return-a-value-from-a-function-with-return.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/return-a-value-from-a-function-with-return.md @@ -17,7 +17,8 @@ Possiamo passare dei valori a una funzione con gli argomenti. È poss function plusThree(num) { return num + 3; } -var answer = plusThree(5); + +const answer = plusThree(5); ``` `answer` ha il valore `8`. diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/return-early-pattern-for-functions.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/return-early-pattern-for-functions.md index bfab0e5bbe..102f744000 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/return-early-pattern-for-functions.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/return-early-pattern-for-functions.md @@ -33,43 +33,43 @@ Ricorda che [`undefined` è una parola chiave](https://www.freecodecamp.org/lear # --hints-- -`abTest(2,2)` dovrebbe restituire un numero +`abTest(2, 2)` dovrebbe restituire un numero ```js assert(typeof abTest(2, 2) === 'number'); ``` -`abTest(2,2)` dovrebbe restituire `8` +`abTest(2, 2)` dovrebbe restituire `8` ```js assert(abTest(2, 2) === 8); ``` -`abTest(-2,2)` dovrebbe restituire `undefined` +`abTest(-2, 2)` dovrebbe restituire `undefined` ```js assert(abTest(-2, 2) === undefined); ``` -`abTest(2,-2)` dovrebbe restituire `undefined` +`abTest(2, -2)` dovrebbe restituire `undefined` ```js assert(abTest(2, -2) === undefined); ``` -`abTest(2,8)` dovrebbe restituire `18` +`abTest(2, 8)` dovrebbe restituire `18` ```js assert(abTest(2, 8) === 18); ``` -`abTest(3,3)` dovrebbe restituire `12` +`abTest(3, 3)` dovrebbe restituire `12` ```js assert(abTest(3, 3) === 12); ``` -`abTest(0,0)` dovrebbe restituire `0` +`abTest(0, 0)` dovrebbe restituire `0` ```js assert(abTest(0, 0) === 0); diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/returning-boolean-values-from-functions.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/returning-boolean-values-from-functions.md index 661409438e..7f4c3d06b4 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/returning-boolean-values-from-functions.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/returning-boolean-values-from-functions.md @@ -14,7 +14,7 @@ dashedName: returning-boolean-values-from-functions A volte le persone usano un'istruzione `if/else` per fare un confronto, in questo modo: ```js -function isEqual(a,b) { +function isEqual(a, b) { if (a === b) { return true; } else { @@ -26,7 +26,7 @@ function isEqual(a,b) { Ma c'è un modo migliore per farlo. Dal momento che `===` restituisce `true` o `false`, possiamo restituire il risultato del confronto: ```js -function isEqual(a,b) { +function isEqual(a, b) { return a === b; } ``` @@ -37,13 +37,13 @@ Correggi la funzione `isLess` per rimuovere le istruzioni `if/else`. # --hints-- -`isLess(10,15)` dovrebbe restituire `true` +`isLess(10, 15)` dovrebbe restituire `true` ```js assert(isLess(10, 15) === true); ``` -`isLess(15,10)` dovrebbe restituire `false` +`isLess(15, 10)` dovrebbe restituire `false` ```js assert(isLess(15, 10) === false); diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/selecting-from-many-options-with-switch-statements.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/selecting-from-many-options-with-switch-statements.md index cb0671f1e6..155d38ab42 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/selecting-from-many-options-with-switch-statements.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/selecting-from-many-options-with-switch-statements.md @@ -78,7 +78,7 @@ assert(code.match(/break/g).length > 2); ```js function caseInSwitch(val) { - var answer = ""; + let answer = ""; // Only change code below this line @@ -94,7 +94,7 @@ caseInSwitch(1); ```js function caseInSwitch(val) { - var answer = ""; + let answer = ""; switch(val) { case 1: diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/shopping-list.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/shopping-list.md index e5815c13d4..1e73a85374 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/shopping-list.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/shopping-list.md @@ -81,13 +81,13 @@ var hasNumber = false; ## --seed-contents-- ```js -var myList = []; +const myList = []; ``` # --solutions-- ```js -var myList = [ +const myList = [ ["Candy", 10], ["Potatoes", 12], ["Eggs", 12], diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/stand-in-line.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/stand-in-line.md index 0d18c887b4..1547a7b8a4 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/stand-in-line.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/stand-in-line.md @@ -93,12 +93,10 @@ function nextInLine(arr, item) { return item; // Only change code above this line - - } // Setup -var testArr = [1,2,3,4,5]; +const testArr = [1, 2, 3, 4, 5]; // Display code console.log("Before: " + JSON.stringify(testArr)); @@ -109,7 +107,7 @@ console.log("After: " + JSON.stringify(testArr)); # --solutions-- ```js -var testArr = [ 1,2,3,4,5]; +const testArr = [1, 2, 3, 4, 5]; function nextInLine(arr, item) { arr.push(item); diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/store-multiple-values-in-one-variable-using-javascript-arrays.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/store-multiple-values-in-one-variable-using-javascript-arrays.md index d280f77f5b..99e986b2a9 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/store-multiple-values-in-one-variable-using-javascript-arrays.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/store-multiple-values-in-one-variable-using-javascript-arrays.md @@ -14,7 +14,7 @@ Con le variabili `array` di JavaScript, possiamo memorizzare diversi dati in un La dichiarazione di un array inizia con una parentesi quadra di apertura, e termina con una parentesi quadra di chiusura, con gli elementi separati da virgole, in questo modo: ```js -var sandwich = ["peanut butter", "jelly", "bread"] +const sandwich = ["peanut butter", "jelly", "bread"]; ``` # --instructions-- @@ -53,11 +53,11 @@ assert(typeof myArray[1] !== 'undefined' && typeof myArray[1] == 'number'); ```js // Only change code below this line -var myArray = []; +const myArray = []; ``` # --solutions-- ```js -var myArray = ["The Answer", 42]; +const myArray = ["The Answer", 42]; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/subtract-one-number-from-another-with-javascript.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/subtract-one-number-from-another-with-javascript.md index 767509bb36..627d6b8ff6 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/subtract-one-number-from-another-with-javascript.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/subtract-one-number-from-another-with-javascript.md @@ -16,7 +16,7 @@ JavaScript utilizza il simbolo `-` per la sottrazione. **Esempio** ```js -myVar = 12 - 6; +const myVar = 12 - 6; ``` `myVar` avrà il valore `6`. @@ -49,11 +49,11 @@ assert(/difference=45-33;?/.test(__helpers.removeWhiteSpace(code))); ## --seed-contents-- ```js -var difference = 45 - 0; +const difference = 45 - 0; ``` # --solutions-- ```js -var difference = 45 - 33; +const difference = 45 - 33; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties.md index a7ac814057..01345fc396 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties.md @@ -13,10 +13,11 @@ A volte è utile verificare se la proprietà di un dato oggetto esiste o meno. P **Esempio** ```js -var myObj = { +const myObj = { top: "hat", bottom: "pants" }; + myObj.hasOwnProperty("top"); myObj.hasOwnProperty("middle"); ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/understand-string-immutability.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/understand-string-immutability.md index 779c4661df..0f3a4e8bb7 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/understand-string-immutability.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/understand-string-immutability.md @@ -14,14 +14,14 @@ In JavaScript, le stringhe (`String`) sono immutabili, il che signifi Ad esempio, il codice seguente: ```js -var myStr = "Bob"; +let myStr = "Bob"; myStr[0] = "J"; ``` non può modificare il valore di `myStr` in `Job`, poiché il contenuto di `myStr` non può essere modificato. Tieni presente che questo *non* significa che `myStr` non può essere modificato, ma solo che i singoli caratteri di una stringa letterale non possono essere cambiati. L'unico modo per modificare `myStr` è di assegnargli una nuova stringa, in questo modo: ```js -var myStr = "Bob"; +let myStr = "Bob"; myStr = "Job"; ``` @@ -55,7 +55,7 @@ assert(/myStr = "Jello World"/.test(code)); ```js // Setup -var myStr = "Jello World"; +let myStr = "Jello World"; // Only change code below this line myStr[0] = "H"; // Change this line @@ -65,6 +65,6 @@ myStr[0] = "H"; // Change this line # --solutions-- ```js -var myStr = "Jello World"; +let myStr = "Jello World"; myStr = "Hello World"; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-boolean-values.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-boolean-values.md index 15d85f5f60..5d3c5e13fc 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-boolean-values.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-boolean-values.md @@ -43,7 +43,6 @@ welcomeToBooleans(); ```js function welcomeToBooleans() { - // Only change code below this line return false; // Change this line diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-undefined-value-returned-from-a-function.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-undefined-value-returned-from-a-function.md index ec452a1a41..c622963208 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-undefined-value-returned-from-a-function.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-undefined-value-returned-from-a-function.md @@ -14,10 +14,12 @@ Una funzione può includere l'istruzione `return` ma questa non deve essere nece **Esempio** ```js -var sum = 0; +let sum = 0; + function addSum(num) { sum = sum + num; } + addSum(3); ``` @@ -61,7 +63,7 @@ assert( ```js // Setup -var sum = 0; +let sum = 0; function addThree() { sum = sum + 3; @@ -79,7 +81,7 @@ addFive(); # --solutions-- ```js -var sum = 0; +let sum = 0; function addThree() { sum = sum + 3; diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/updating-object-properties.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/updating-object-properties.md index c3141f438f..27d8a790c0 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/updating-object-properties.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/updating-object-properties.md @@ -14,7 +14,7 @@ Dopo aver creato un oggetto JavaScript, è possibile aggiornare le sue propriet Ad esempio, diamo un'occhiata a `ourDog`: ```js -var ourDog = { +const ourDog = { "name": "Camper", "legs": 4, "tails": 1, @@ -54,7 +54,7 @@ assert(/"name": "Coder"/.test(code)); ```js // Setup -var myDog = { +const myDog = { "name": "Coder", "legs": 4, "tails": 1, @@ -62,12 +62,13 @@ var myDog = { }; // Only change code below this line + ``` # --solutions-- ```js -var myDog = { +const myDog = { "name": "Coder", "legs": 4, "tails": 1, diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-first-character-in-a-string.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-first-character-in-a-string.md index 7b22d3e89f..a4f84e0268 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-first-character-in-a-string.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-first-character-in-a-string.md @@ -13,13 +13,13 @@ dashedName: use-bracket-notation-to-find-the-first-character-in-a-string La maggior parte dei moderni linguaggi di programmazione, come JavaScript, non inizia a contare da 1 come gli esseri umani. Loro iniziano dallo 0. Questo è indicato come indicizzazione Zero-based. -Ad esempio, il carattere all'indice 0 nella parola `Charles` è `C`. Quindi, se `var firstName = "Charles"`, è possibile ottenere il valore della prima lettera della stringa utilizzando `firstName[0]`. +Ad esempio, il carattere all'indice 0 nella parola `Charles` è `C`. Quindi, se `const firstName = "Charles"`, è possibile ottenere il valore della prima lettera della stringa utilizzando `firstName[0]`. Esempio: ```js -var firstName = "Charles"; -var firstLetter = firstName[0]; +const firstName = "Charles"; +const firstLetter = firstName[0]; ``` `firstLetter` dovrebbe avere un valore stringa `C`. @@ -56,8 +56,8 @@ assert(code.match(/firstLetterOfLastName\s*?=\s*?lastName\[.*?\]/)); ```js // Setup -var firstLetterOfLastName = ""; -var lastName = "Lovelace"; +let firstLetterOfLastName = ""; +const lastName = "Lovelace"; // Only change code below this line firstLetterOfLastName = lastName; // Change this line @@ -66,8 +66,8 @@ firstLetterOfLastName = lastName; // Change this line # --solutions-- ```js -var firstLetterOfLastName = ""; -var lastName = "Lovelace"; +let firstLetterOfLastName = ""; +const lastName = "Lovelace"; // Only change code below this line firstLetterOfLastName = lastName[0]; diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-last-character-in-a-string.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-last-character-in-a-string.md index 728b070b50..e19e3fe9fe 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-last-character-in-a-string.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-last-character-in-a-string.md @@ -11,13 +11,13 @@ dashedName: use-bracket-notation-to-find-the-last-character-in-a-string Al fine di ottenere l'ultima lettera di una stringa, è possibile sottrarre uno dalla lunghezza della stringa. -Per esempio, se `var firstName = "Ada"`, puoi ottenere il valore dell'ultima lettera della stringa usando `firstName[firstName.length - 1]`. +Per esempio, se `const firstName = "Ada"`, puoi ottenere il valore dell'ultima lettera della stringa usando `firstName[firstName.length - 1]`. Esempio: ```js -var firstName = "Ada"; -var lastLetter = firstName[firstName.length - 1]; +const firstName = "Ada"; +const lastLetter = firstName[firstName.length - 1]; ``` `lastLetter` dovrebbe avere un valore stringa `a`. @@ -54,15 +54,15 @@ assert(code.match(/\.length/g).length > 0); ```js // Setup -var lastName = "Lovelace"; +const lastName = "Lovelace"; // Only change code below this line -var lastLetterOfLastName = lastName; // Change this line +const lastLetterOfLastName = lastName; // Change this line ``` # --solutions-- ```js -var lastName = "Lovelace"; -var lastLetterOfLastName = lastName[lastName.length - 1]; +const lastName = "Lovelace"; +const lastLetterOfLastName = lastName[lastName.length - 1]; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-nth-character-in-a-string.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-nth-character-in-a-string.md index 32b4010e76..0e89b3f80f 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-nth-character-in-a-string.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-nth-character-in-a-string.md @@ -16,8 +16,8 @@ Ricorda che i computer iniziano a contare da `0`, quindi il primo carattere è i Esempio: ```js -var firstName = "Ada"; -var secondLetterOfFirstName = firstName[1]; +const firstName = "Ada"; +const secondLetterOfFirstName = firstName[1]; ``` `secondLetterOfFirstName` dovrebbe acere un valore stringa `d`. @@ -54,15 +54,15 @@ assert(code.match(/thirdLetterOfLastName\s*?=\s*?lastName\[.*?\]/)); ```js // Setup -var lastName = "Lovelace"; +const lastName = "Lovelace"; // Only change code below this line -var thirdLetterOfLastName = lastName; // Change this line +const thirdLetterOfLastName = lastName; // Change this line ``` # --solutions-- ```js -var lastName = "Lovelace"; -var thirdLetterOfLastName = lastName[2]; +const lastName = "Lovelace"; +const thirdLetterOfLastName = lastName[2]; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-nth-to-last-character-in-a-string.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-nth-to-last-character-in-a-string.md index f29cf5783d..9e288b6f46 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-nth-to-last-character-in-a-string.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-nth-to-last-character-in-a-string.md @@ -11,13 +11,13 @@ dashedName: use-bracket-notation-to-find-the-nth-to-last-character-in-a-string È possibile utilizzare lo stesso principio che abbiamo appena usato per recuperare l'ultimo carattere in una stringa per recuperare il carattere n-ultimo dalla fine. -Ad esempio, puoi ottenere il valore della terzultima lettera della stringa `var firstName = "Augusta"` usando `firstName[firstName. lunghezza - 3]` +Ad esempio, puoi ottenere il valore della terzultima lettera della stringa `const firstName = "Augusta"` usando `firstName[firstName.length - 3]` Esempio: ```js -var firstName = "Augusta"; -var thirdToLastLetter = firstName[firstName.length - 3]; +const firstName = "Augusta"; +const thirdToLastLetter = firstName[firstName.length - 3]; ``` `thirdToLastLetter` dovrebbe avere un valore stringa `s`. @@ -54,15 +54,15 @@ assert(code.match(/\.length/g).length > 0); ```js // Setup -var lastName = "Lovelace"; +const lastName = "Lovelace"; // Only change code below this line -var secondToLastLetterOfLastName = lastName; // Change this line +const secondToLastLetterOfLastName = lastName; // Change this line ``` # --solutions-- ```js -var lastName = "Lovelace"; -var secondToLastLetterOfLastName = lastName[lastName.length - 2]; +const lastName = "Lovelace"; +const secondToLastLetterOfLastName = lastName[lastName.length - 2]; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/use-conditional-logic-with-if-statements.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/use-conditional-logic-with-if-statements.md index d563f229c8..a0712627a3 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/use-conditional-logic-with-if-statements.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/use-conditional-logic-with-if-statements.md @@ -9,7 +9,7 @@ dashedName: use-conditional-logic-with-if-statements # --description-- -Le istruzioni `If` sono usate nel codice per prendere decisioni. La parola chiave `if` dice a JavaScript di eseguire il codice nelle parentesi graffe in determinate condizioni, definite nelle parentesi tonde. Queste condizioni sono note come condizioni `Boolean` e possono essere solo `true` o `false`. +Le istruzioni `if` sono usate nel codice per prendere decisioni. La parola chiave `if` dice a JavaScript di eseguire il codice nelle parentesi graffe in determinate condizioni, definite nelle parentesi tonde. Queste condizioni sono note come condizioni `Boolean` e possono essere solo `true` o `false`. Quando la condizione valuta un `true`, il programma esegue la dichiarazione all'interno delle parentesi graffe. Quando la condizione booleana valuta un `false`, la dichiarazione all'interno delle parentesi graffe non sarà eseguita. @@ -22,10 +22,11 @@ Quando la condizione valuta un `true`, il programma esegue la dichiarazione all' ```js function test (myCondition) { if (myCondition) { - return "It was true"; + return "It was true"; } return "It was false"; } + test(true); test(false); ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/use-recursion-to-create-a-range-of-numbers.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/use-recursion-to-create-a-range-of-numbers.md index 3f3574500e..11cfe95741 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/use-recursion-to-create-a-range-of-numbers.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/use-recursion-to-create-a-range-of-numbers.md @@ -73,7 +73,7 @@ function rangeOfNumbers(startNum, endNum) { if (endNum - startNum === 0) { return [startNum]; } else { - var numbers = rangeOfNumbers(startNum, endNum - 1); + const numbers = rangeOfNumbers(startNum, endNum - 1); numbers.push(endNum); return numbers; } diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function-with-a-radix.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function-with-a-radix.md index a13766d684..a4001a6006 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function-with-a-radix.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function-with-a-radix.md @@ -20,7 +20,7 @@ parseInt(string, radix); Ecco un esempio: ```js -var a = parseInt("11", 2); +const a = parseInt("11", 2); ``` La variabile radix dice che `11` è nel sistema binario, o in base 2. Questo esempio converte la stringa `11` in un intero `3`. diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function.md index ded630df7a..3d11acc508 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function.md @@ -12,7 +12,7 @@ dashedName: use-the-parseint-function La funzione `parseInt()` analizza una stringa e restituisce un numero intero. Ecco un esempio: ```js -var a = parseInt("007"); +const a = parseInt("007"); ``` La funzione di cui sopra converte la stringa `007` nell'intero `7`. Se il primo carattere della stringa non può essere convertito in un numero, restituisce `NaN`. diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/using-objects-for-lookups.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/using-objects-for-lookups.md index f238d440ba..bc280c8f39 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/using-objects-for-lookups.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/using-objects-for-lookups.md @@ -14,7 +14,7 @@ Gli oggetti possono essere pensati come una memorizzazione di coppie chiave / va Ecco l'esempio di una semplice ricerca in un alfabeto inverso: ```js -var alpha = { +const alpha = { 1:"Z", 2:"Y", 3:"X", @@ -24,10 +24,11 @@ var alpha = { 25:"B", 26:"A" }; + alpha[2]; alpha[24]; -var value = 2; +const value = 2; alpha[value]; ``` @@ -102,7 +103,7 @@ assert( ```js // Setup function phoneticLookup(val) { - var result = ""; + let result = ""; // Only change code below this line switch(val) { @@ -136,9 +137,9 @@ phoneticLookup("charlie"); ```js function phoneticLookup(val) { - var result = ""; + let result = ""; - var lookup = { + const lookup = { alpha: "Adams", bravo: "Boston", charlie: "Chicago", diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/word-blanks.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/word-blanks.md index b358f58679..96e39636aa 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/word-blanks.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/word-blanks.md @@ -16,7 +16,7 @@ In un gioco "Mad Libs" ti vengono fornite frasi con alcune parole mancanti, come Considera questa frase: It was really **\_\_\_\_**, and we **\_\_\_\_** ourselves **\_\_\_\_**. Questa frase ha tre parti mancanti - un aggettivo, un verbo e un avverbio, e possiamo aggiungere parole di nostra scelta per completarla. Possiamo quindi assegnare la frase completata a una variabile come segue: ```js -var sentence = "It was really " + "hot" + ", and we " + "laughed" + " ourselves " + "silly" + "."; +const sentence = "It was really " + "hot" + ", and we " + "laughed" + " ourselves " + "silly" + "."; ``` # --instructions-- @@ -84,24 +84,24 @@ const removeAssignments = str => str ## --seed-contents-- ```js -var myNoun = "dog"; -var myAdjective = "big"; -var myVerb = "ran"; -var myAdverb = "quickly"; +const myNoun = "dog"; +const myAdjective = "big"; +const myVerb = "ran"; +const myAdverb = "quickly"; // Only change code below this line -var wordBlanks = ""; // Change this line +const wordBlanks = ""; // Change this line // Only change code above this line ``` # --solutions-- ```js -var myNoun = "dog"; -var myAdjective = "big"; -var myVerb = "ran"; -var myAdverb = "quickly"; +const myNoun = "dog"; +const myAdjective = "big"; +const myVerb = "ran"; +const myAdverb = "quickly"; -var wordBlanks = "Once there was a " + myNoun + " which was very " + myAdjective + ". "; +let wordBlanks = "Once there was a " + myNoun + " which was very " + myAdjective + ". "; wordBlanks += "It " + myVerb + " " + myAdverb + " around the yard."; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/es6/compare-scopes-of-the-var-and-let-keywords.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/es6/compare-scopes-of-the-var-and-let-keywords.md index 78b0ae1d53..8f8ef090d2 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/es6/compare-scopes-of-the-var-and-let-keywords.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/es6/compare-scopes-of-the-var-and-let-keywords.md @@ -8,11 +8,13 @@ dashedName: compare-scopes-of-the-var-and-let-keywords # --description-- +Se non hai familiarità con `let`, guarda [questa sfida](/italian/learn/javascript-algorithms-and-data-structures/basic-javascript/explore-differences-between-the-var-and-let-keywords). + Quando si dichiara una variabile con la parola chiave `var`, essa viene dichiarata globalmente, o localmente se dichiarata all'interno di una funzione. La parola chiave `let` si comporta allo stesso modo, ma con alcune funzioni extra. Quando si dichiara una variabile con la parola chiave `let` all'interno di un blocco, di una dichiarazione o di un'espressione, il suo ambito di applicazione è limitato a tale blocco, dichiarazione o espressione. -Ad esempio: +Per esempio: ```js var numArray = []; diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/es6/mutate-an-array-declared-with-const.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/es6/mutate-an-array-declared-with-const.md index 90afce5d3b..584d9b959e 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/es6/mutate-an-array-declared-with-const.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/es6/mutate-an-array-declared-with-const.md @@ -8,6 +8,8 @@ dashedName: mutate-an-array-declared-with-const # --description-- +Se non hai familiarità con `const`, guarda [questa sfida](/italian/learn/javascript-algorithms-and-data-structures/basic-javascript/declare-a-read-only-variable-with-the-const-keyword). + La dichiarazione `const` ha molti casi di utilizzo nel JavaScript moderno. Alcuni sviluppatori preferiscono assegnare tutte le loro variabili usando `const` come impostazione predefinita, a meno che non sappiano che dovranno riassegnare il valore. Solo in quel caso usano `let`. diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/add-elements-to-the-end-of-an-array-using-concat-instead-of-push.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/add-elements-to-the-end-of-an-array-using-concat-instead-of-push.md index ec106d4bad..7de60422fe 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/add-elements-to-the-end-of-an-array-using-concat-instead-of-push.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/add-elements-to-the-end-of-an-array-using-concat-instead-of-push.md @@ -13,7 +13,7 @@ La programmazione funzionale riguarda la creazione e l'utilizzo di funzioni non L'ultima sfida ha introdotto il metodo `concat` come modo per combinare degli array in uno nuovo senza mutare gli array originali. Confronta `concat` con il metodo `push`. `push` aggiunge un elemento alla fine dello stesso array sul quale viene richiamato, mutando quello stesso array. Ecco un esempio: ```js -var arr = [1, 2, 3]; +const arr = [1, 2, 3]; arr.push([4, 5, 6]); ``` @@ -71,8 +71,9 @@ function nonMutatingPush(original, newItem) { // Only change code above this line } -var first = [1, 2, 3]; -var second = [4, 5]; + +const first = [1, 2, 3]; +const second = [4, 5]; nonMutatingPush(first, second); ``` @@ -82,7 +83,6 @@ nonMutatingPush(first, second); function nonMutatingPush(original, newItem) { return original.concat(newItem); } -var first = [1, 2, 3]; -var second = [4, 5]; -nonMutatingPush(first, second); +const first = [1, 2, 3]; +const second = [4, 5]; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs.md index b17658cb35..0be730b16e 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs.md @@ -77,7 +77,6 @@ function urlSlug(title) { # --solutions-- ```js -// Only change code below this line function urlSlug(title) { return title.trim().split(/\s+/).join("-").toLowerCase(); } diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/avoid-mutations-and-side-effects-using-functional-programming.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/avoid-mutations-and-side-effects-using-functional-programming.md index 4c05d5ff64..d3aabcc8b0 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/avoid-mutations-and-side-effects-using-functional-programming.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/avoid-mutations-and-side-effects-using-functional-programming.md @@ -57,9 +57,9 @@ La tua funzione `incrementer` dovrebbe restituire un valore basato sul valore de ```js // The global variable -var fixedValue = 4; +let fixedValue = 4; -function incrementer () { +function incrementer() { // Only change code below this line @@ -70,7 +70,7 @@ function incrementer () { # --solutions-- ```js -var fixedValue = 4 +let fixedValue = 4 function incrementer() { return fixedValue + 1 diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/combine-an-array-into-a-string-using-the-join-method.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/combine-an-array-into-a-string-using-the-join-method.md index 8cbb8ed9d9..276483c0d6 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/combine-an-array-into-a-string-using-the-join-method.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/combine-an-array-into-a-string-using-the-join-method.md @@ -13,8 +13,8 @@ Il metodo `join` viene utilizzato per unire gli elementi di un array per creare Ecco un esempio: ```js -var arr = ["Hello", "World"]; -var str = arr.join(" "); +const arr = ["Hello", "World"]; +const str = arr.join(" "); ``` `str` conterrà la stringa `Hello World`. @@ -76,6 +76,7 @@ function sentensify(str) { // Only change code above this line } + sentensify("May-the-force-be-with-you"); ``` @@ -83,8 +84,6 @@ sentensify("May-the-force-be-with-you"); ```js function sentensify(str) { - // Only change code below this line return str.split(/\W/).join(' '); - // Only change code above this line } ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/combine-two-arrays-using-the-concat-method.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/combine-two-arrays-using-the-concat-method.md index 2e670d61e9..9080414f5b 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/combine-two-arrays-using-the-concat-method.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/combine-two-arrays-using-the-concat-method.md @@ -60,8 +60,9 @@ function nonMutatingConcat(original, attach) { // Only change code above this line } -var first = [1, 2, 3]; -var second = [4, 5]; + +const first = [1, 2, 3]; +const second = [4, 5]; nonMutatingConcat(first, second); ``` @@ -69,11 +70,8 @@ nonMutatingConcat(first, second); ```js function nonMutatingConcat(original, attach) { - // Only change code below this line return original.concat(attach); - // Only change code above this line } -var first = [1, 2, 3]; -var second = [4, 5]; -nonMutatingConcat(first, second); +const first = [1, 2, 3]; +const second = [4, 5]; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype.md index 7481fe5ad4..f86c26fd5a 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype.md @@ -38,17 +38,17 @@ assert(!code.match(/\.?[\s\S]*?map/g)); ```js // The global variable -var s = [23, 65, 98, 5]; +const s = [23, 65, 98, 5]; Array.prototype.myMap = function(callback) { - var newArray = []; + const newArray = []; // Only change code below this line // Only change code above this line return newArray; }; -var new_s = s.myMap(function(item) { +const new_s = s.myMap(function(item) { return item * 2; }); ``` @@ -56,20 +56,17 @@ var new_s = s.myMap(function(item) { # --solutions-- ```js -// the global Array -var s = [23, 65, 98, 5]; +const s = [23, 65, 98, 5]; Array.prototype.myMap = function(callback) { - var newArray = []; - // Only change code below this line - for (var elem of this) { + const newArray = []; + for (const elem of this) { newArray.push(callback(elem)); } - // Only change code above this line return newArray; }; -var new_s = s.myMap(function(item) { +const new_s = s.myMap(function(item) { return item * 2; }); ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/implement-the-filter-method-on-a-prototype.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/implement-the-filter-method-on-a-prototype.md index 0ac91d4557..be2cd8f1b8 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/implement-the-filter-method-on-a-prototype.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/implement-the-filter-method-on-a-prototype.md @@ -34,16 +34,16 @@ assert(!code.match(/\.?[\s\S]*?filter/g)); ```js // The global variable -var s = [23, 65, 98, 5]; +const s = [23, 65, 98, 5]; Array.prototype.myFilter = function(callback) { // Only change code below this line - var newArray = []; + const newArray = []; // Only change code above this line return newArray; }; -var new_s = s.myFilter(function(item) { +const new_s = s.myFilter(function(item) { return item % 2 === 1; }); ``` @@ -51,20 +51,17 @@ var new_s = s.myFilter(function(item) { # --solutions-- ```js -// the global Array -var s = [23, 65, 98, 5]; +const s = [23, 65, 98, 5]; Array.prototype.myFilter = function(callback) { - var newArray = []; - // Only change code below this line + const newArray = []; for (let i = 0; i < this.length; i++) { if (callback(this[i])) newArray.push(this[i]); } - // Only change code above this line return newArray; }; -var new_s = s.myFilter(function(item) { +const new_s = s.myFilter(function(item) { return item % 2 === 1; }); ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/introduction-to-currying-and-partial-application.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/introduction-to-currying-and-partial-application.md index 08b0f55094..a16389a119 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/introduction-to-currying-and-partial-application.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/introduction-to-currying-and-partial-application.md @@ -35,7 +35,7 @@ curried(1)(2) Questo sarà utile nel tuo programma se non sarai in grado di fornire tutti gli argomenti ad una funzione in una sola volta. Potrai salvare ogni chiamata di funzione in una variabile, che manterrà il riferimento alla funzione restituita, che prenderà l'argomento successivo quando sarà disponibile. Ecco un esempio usando la funzione curried dell'esempio visto sopra: ```js -var funcForY = curried(1); +const funcForY = curried(1); console.log(funcForY(2)); // 3 ``` @@ -45,7 +45,8 @@ Allo stesso modo, l'applicazione parziale può essere descritta come function impartial(x, y, z) { return x + y + z; } -var partialFn = impartial.bind(this, 1, 2); + +const partialFn = impartial.bind(this, 1, 2); partialFn(10); // 13 ``` @@ -90,6 +91,7 @@ function add(x) { // Only change code above this line } + add(10)(20)(30); ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/pass-arguments-to-avoid-external-dependence-in-a-function.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/pass-arguments-to-avoid-external-dependence-in-a-function.md index abbc1b478f..593d57dbe9 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/pass-arguments-to-avoid-external-dependence-in-a-function.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/pass-arguments-to-avoid-external-dependence-in-a-function.md @@ -53,10 +53,10 @@ assert(__newValue === 5); ```js // The global variable -var fixedValue = 4; +let fixedValue = 4; // Only change code below this line -function incrementer () { +function incrementer() { // Only change code above this line @@ -66,15 +66,9 @@ function incrementer () { # --solutions-- ```js -// The global variable -var fixedValue = 4; +let fixedValue = 4; -// Only change code below this line -function incrementer (fixedValue) { +function incrementer(fixedValue) { return fixedValue + 1; - - // Only change code above this line } - - ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/refactor-global-variables-out-of-functions.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/refactor-global-variables-out-of-functions.md index ac1d10eac0..0f1f353bd3 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/refactor-global-variables-out-of-functions.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/refactor-global-variables-out-of-functions.md @@ -10,7 +10,7 @@ dashedName: refactor-global-variables-out-of-functions Finora abbiamo visto due principi distinti per la programmazione funzionale: -1) Non modificare una variabile o un oggetto - se necessario creare nuove variabili e oggetti e restituirli da una funzione. Suggerimento: usando qualcosa come `var newArr = arrVar`, dove `arrVar` è un array, creerai semplicemente un riferimento alla variabile esistente e non una copia. Quindi cambiando un valore in `newArr` cambierà anche il valore in `arrVar`. +1) Non modificare una variabile o un oggetto - se necessario creare nuove variabili e oggetti e restituirli da una funzione. Suggerimento: usando qualcosa come `const newArr = arrVar`, dove `arrVar` è un array, creerai semplicemente un riferimento alla variabile esistente e non una copia. Quindi cambiando un valore in `newArr` cambierà anche il valore in `arrVar`. 2) Dichiarare i parametri della funzione - qualsiasi calcolo all'interno di una funzione deve dipendere solo dagli argomenti passati alla funzione, e non da qualsiasi oggetto o variabile globale. @@ -86,7 +86,7 @@ assert( ```js // The global variable -var bookList = ["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae"]; +const bookList = ["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae"]; // Change code below this line function add (bookName) { @@ -99,7 +99,7 @@ function add (bookName) { // Change code below this line function remove (bookName) { - var book_index = bookList.indexOf(bookName); + const book_index = bookList.indexOf(bookName); if (book_index >= 0) { bookList.splice(book_index, 1); @@ -109,9 +109,9 @@ function remove (bookName) { } } -var newBookList = add(bookList, 'A Brief History of Time'); -var newerBookList = remove(bookList, 'On The Electrodynamics of Moving Bodies'); -var newestBookList = remove(add(bookList, 'A Brief History of Time'), 'On The Electrodynamics of Moving Bodies'); +const newBookList = add(bookList, 'A Brief History of Time'); +const newerBookList = remove(bookList, 'On The Electrodynamics of Moving Bodies'); +const newestBookList = remove(add(bookList, 'A Brief History of Time'), 'On The Electrodynamics of Moving Bodies'); console.log(bookList); ``` @@ -120,13 +120,13 @@ console.log(bookList); ```js // The global variable -var bookList = ["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae"]; +const bookList = ["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae"]; -function add (bookList, bookName) { +function add(bookList, bookName) { return [...bookList, bookName]; } -function remove (bookList, bookName) { +function remove(bookList, bookName) { const bookListCopy = [...bookList]; const bookNameIndex = bookList.indexOf(bookName); if (bookNameIndex >= 0) { @@ -135,7 +135,7 @@ function remove (bookList, bookName) { return bookListCopy; } -var newBookList = add(bookList, 'A Brief History of Time'); -var newerBookList = remove(bookList, 'On The Electrodynamics of Moving Bodies'); -var newestBookList = remove(add(bookList, 'A Brief History of Time'), 'On The Electrodynamics of Moving Bodies'); +const newBookList = add(bookList, 'A Brief History of Time'); +const newerBookList = remove(bookList, 'On The Electrodynamics of Moving Bodies'); +const newestBookList = remove(add(bookList, 'A Brief History of Time'), 'On The Electrodynamics of Moving Bodies'); ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/remove-elements-from-an-array-using-slice-instead-of-splice.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/remove-elements-from-an-array-using-slice-instead-of-splice.md index 98ba6cd7ea..42204ce06e 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/remove-elements-from-an-array-using-slice-instead-of-splice.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/remove-elements-from-an-array-using-slice-instead-of-splice.md @@ -11,7 +11,7 @@ dashedName: remove-elements-from-an-array-using-slice-instead-of-splice Un'operazione che si fa comunemente lavorando con gli array è quella di rimuovere degli elemento mantenendo il resto dell'array. A questo scopo JavaScript offre il metodo `splice`, che richiede degli argomenti per la posizione (indice) di dove iniziare a rimuovere gli elementi, e per il numero di elementi da rimuovere. Se il secondo argomento non è fornito, il comportamento predefinito è quello di rimuovere gli elementi fino alla fine. Tuttavia, il metodo `splice` muta l'array originale su cui viene chiamato. Ecco un esempio: ```js -var cities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"]; +const cities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"]; cities.splice(3, 1); ``` @@ -69,7 +69,8 @@ function nonMutatingSplice(cities) { // Only change code above this line } -var inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"]; + +const inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"]; nonMutatingSplice(inputCities); ``` @@ -77,10 +78,7 @@ nonMutatingSplice(inputCities); ```js function nonMutatingSplice(cities) { - // Only change code below this line return cities.slice(0,3); - // Only change code above this line } -var inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"]; -nonMutatingSplice(inputCities); +const inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"]; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/return-a-sorted-array-without-changing-the-original-array.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/return-a-sorted-array-without-changing-the-original-array.md index c68e75beab..41dd0b004c 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/return-a-sorted-array-without-changing-the-original-array.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/return-a-sorted-array-without-changing-the-original-array.md @@ -68,24 +68,23 @@ assert(JSON.stringify(nonMutatingSort([140000, 104, 99])) === ## --seed-contents-- ```js -var globalArray = [5, 6, 3, 2, 9]; +const globalArray = [5, 6, 3, 2, 9]; + function nonMutatingSort(arr) { // Only change code below this line // Only change code above this line } + nonMutatingSort(globalArray); ``` # --solutions-- ```js -var globalArray = [5, 6, 3, 2, 9]; +const globalArray = [5, 6, 3, 2, 9]; function nonMutatingSort(arr) { - // Only change code below this line return [].concat(arr).sort((a,b) => a-b); - // Only change code above this line } -nonMutatingSort(globalArray); ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/return-part-of-an-array-using-the-slice-method.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/return-part-of-an-array-using-the-slice-method.md index 100adb00ac..7334fcec52 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/return-part-of-an-array-using-the-slice-method.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/return-part-of-an-array-using-the-slice-method.md @@ -13,8 +13,8 @@ Il metodo `slice` restituisce una copia di alcuni elementi di un array. Può pre Ecco un esempio: ```js -var arr = ["Cat", "Dog", "Tiger", "Zebra"]; -var newArray = arr.slice(1, 3); +const arr = ["Cat", "Dog", "Tiger", "Zebra"]; +const newArray = arr.slice(1, 3); ``` `newArray` avrà il valore `["Dog", "Tiger"]`. @@ -78,7 +78,8 @@ function sliceArray(anim, beginSlice, endSlice) { // Only change code above this line } -var inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"]; + +const inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"]; sliceArray(inputAnim, 1, 3); ``` @@ -86,10 +87,7 @@ sliceArray(inputAnim, 1, 3); ```js function sliceArray(anim, beginSlice, endSlice) { - // Only change code below this line - return anim.slice(beginSlice, endSlice) - // Only change code above this line + return anim.slice(beginSlice, endSlice); } -var inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"]; -sliceArray(inputAnim, 1, 3); +const inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"]; ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/sort-an-array-alphabetically-using-the-sort-method.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/sort-an-array-alphabetically-using-the-sort-method.md index ffda7234fe..5f20c74f67 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/sort-an-array-alphabetically-using-the-sort-method.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/sort-an-array-alphabetically-using-the-sort-method.md @@ -18,6 +18,7 @@ function ascendingOrder(arr) { return a - b; }); } + ascendingOrder([1, 5, 2, 3, 4]); ``` @@ -29,6 +30,7 @@ function reverseAlpha(arr) { return a === b ? 0 : a < b ? 1 : -1; }); } + reverseAlpha(['l', 'h', 'z', 'b', 's']); ``` @@ -86,6 +88,7 @@ function alphabeticalOrder(arr) { return arr // Only change code above this line } + alphabeticalOrder(["a", "d", "c", "a", "z", "g"]); ``` @@ -93,9 +96,6 @@ alphabeticalOrder(["a", "d", "c", "a", "z", "g"]); ```js function alphabeticalOrder(arr) { - // Only change code below this line return arr.sort(); - // Only change code above this line } -alphabeticalOrder(["a", "d", "c", "a", "z", "g"]); ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/split-a-string-into-an-array-using-the-split-method.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/split-a-string-into-an-array-using-the-split-method.md index 1cdcb7b47a..4a9e267ca4 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/split-a-string-into-an-array-using-the-split-method.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/split-a-string-into-an-array-using-the-split-method.md @@ -13,11 +13,11 @@ Il metodo `split` divide una stringa in un array di stringhe. Esso richiede un a Ecco un esempio che divide una stringa in base agli spazi, poi un altro in base alle cifre facendo uso di un'espressione regolare: ```js -var str = "Hello World"; -var bySpace = str.split(" "); +const str = "Hello World"; +const bySpace = str.split(" "); -var otherString = "How9are7you2today"; -var byDigits = otherString.split(/\d/); +const otherString = "How9are7you2today"; +const byDigits = otherString.split(/\d/); ``` `bySpace` avrà il valore `["Hello", "World"]` e `byDigits` avrà il valore `["How", "are", "you", "today"]`. @@ -74,6 +74,7 @@ function splitify(str) { // Only change code above this line } + splitify("Hello World,I-am code"); ``` @@ -81,8 +82,6 @@ splitify("Hello World,I-am code"); ```js function splitify(str) { - // Only change code below this line return str.split(/\W/); - // Only change code above this line } ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/understand-the-hazards-of-using-imperative-code.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/understand-the-hazards-of-using-imperative-code.md index 05be76d717..ce4c54fcf2 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/understand-the-hazards-of-using-imperative-code.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/understand-the-hazards-of-using-imperative-code.md @@ -59,29 +59,29 @@ assert.deepEqual(finalTabs.tabs, [ ```js // tabs is an array of titles of each site open within the window -var Window = function(tabs) { +const Window = function(tabs) { this.tabs = tabs; // We keep a record of the array inside the object }; // When you join two windows into one window -Window.prototype.join = function (otherWindow) { +Window.prototype.join = function(otherWindow) { this.tabs = this.tabs.concat(otherWindow.tabs); return this; }; // When you open a new tab at the end -Window.prototype.tabOpen = function (tab) { +Window.prototype.tabOpen = function(tab) { this.tabs.push('new tab'); // Let's open a new tab for now return this; }; // When you close a tab -Window.prototype.tabClose = function (index) { +Window.prototype.tabClose = function(index) { // Only change code below this line - var tabsBeforeIndex = this.tabs.splice(0, index); // Get the tabs before the tab - var tabsAfterIndex = this.tabs.splice(index + 1); // Get the tabs after the tab + const tabsBeforeIndex = this.tabs.splice(0, index); // Get the tabs before the tab + const tabsAfterIndex = this.tabs.splice(index + 1); // Get the tabs after the tab this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // Join them together @@ -91,12 +91,12 @@ Window.prototype.tabClose = function (index) { }; // Let's create three browser windows -var workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); // Your mailbox, drive, and other work sites -var socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); // Social sites -var videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); // Entertainment sites +const workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); // Your mailbox, drive, and other work sites +const socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); // Social sites +const videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); // Entertainment sites // Now perform the tab opening, closing, and other operations -var finalTabs = socialWindow +const finalTabs = socialWindow .tabOpen() // Open a new tab for cat memes .join(videoWindow.tabClose(2)) // Close third tab in video window, and join .join(workWindow.tabClose(1).tabOpen()); @@ -106,40 +106,34 @@ console.log(finalTabs.tabs); # --solutions-- ```js -// tabs is an array of titles of each site open within the window -var Window = function(tabs) { - this.tabs = tabs; // We keep a record of the array inside the object +const Window = function(tabs) { + this.tabs = tabs; }; -// When you join two windows into one window -Window.prototype.join = function (otherWindow) { +Window.prototype.join = function(otherWindow) { this.tabs = this.tabs.concat(otherWindow.tabs); return this; }; -// When you open a new tab at the end -Window.prototype.tabOpen = function (tab) { - this.tabs.push('new tab'); // Let's open a new tab for now +Window.prototype.tabOpen = function(tab) { + this.tabs.push('new tab'); return this; }; -// When you close a tab -Window.prototype.tabClose = function (index) { - var tabsBeforeIndex = this.tabs.slice(0, index); // Get the tabs before the tab - var tabsAfterIndex = this.tabs.slice(index + 1); // Get the tabs after the tab +Window.prototype.tabClose = function(index) { + const tabsBeforeIndex = this.tabs.slice(0, index); + const tabsAfterIndex = this.tabs.slice(index + 1); - this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // Join them together + this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); return this; }; -// Let's create three browser windows -var workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); // Your mailbox, drive, and other work sites -var socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); // Social sites -var videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); // Entertainment sites +const workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); +const socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); +const videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); -// Now perform the tab opening, closing, and other operations -var finalTabs = socialWindow - .tabOpen() // Open a new tab for cat memes - .join(videoWindow.tabClose(2)) // Close third tab in video window, and join +const finalTabs = socialWindow + .tabOpen() + .join(videoWindow.tabClose(2)) .join(workWindow.tabClose(1).tabOpen()); ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria.md index a0aa580e98..02cfc87dd5 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria.md @@ -13,7 +13,8 @@ Il metodo `every` funziona con gli array per controllare se *ogni* elemento supe Ad esempio, il seguente codice controllerà se ogni elemento nell'array `numbers` è inferiore a 10: ```js -var numbers = [1, 5, 8, 0, 10, 11]; +const numbers = [1, 5, 8, 0, 10, 11]; + numbers.every(function(currentValue) { return currentValue < 10; }); @@ -62,6 +63,7 @@ function checkPositive(arr) { // Only change code above this line } + checkPositive([1, 2, 3, -4, 5]); ``` @@ -69,9 +71,6 @@ checkPositive([1, 2, 3, -4, 5]); ```js function checkPositive(arr) { - // Only change code below this line return arr.every(num => num > 0); - // Only change code above this line } -checkPositive([1, 2, 3, -4, 5]); ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/use-the-filter-method-to-extract-data-from-an-array.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/use-the-filter-method-to-extract-data-from-an-array.md index 1806ad107d..d07c29105c 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/use-the-filter-method-to-extract-data-from-an-array.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/use-the-filter-method-to-extract-data-from-an-array.md @@ -55,7 +55,7 @@ Il tuo codice non dovrebbe utilizzare un ciclo `for`. assert(!code.match(/for\s*?\([\s\S]*?\)/g)); ``` -`filteredList` dovrebbe essere uguale a `[{"title": "Inception","rating": "8.8"},{"title": "Interstellar","rating": "8.6"},{"title": "The Dark Knight","rating": "9.0"},{"title": "Batman Begins","rating": "8.3"}]`. +`filteredList` dovrebbe essere uguale a `[{"title": "Inception", "rating": "8.8"}, {"title": "Interstellar", "rating": "8.6"}, {"title": "The Dark Knight", "rating": "9.0"}, {"title": "Batman Begins", "rating": "8.3"}]`. ```js assert.deepEqual(filteredList, [ @@ -72,7 +72,7 @@ assert.deepEqual(filteredList, [ ```js // The global variable -var watchList = [ +const watchList = [ { "Title": "Inception", "Year": "2010", @@ -187,7 +187,7 @@ var watchList = [ // Only change code below this line -var filteredList; +const filteredList = ""; // Only change code above this line @@ -197,8 +197,7 @@ console.log(filteredList); # --solutions-- ```js -// The global variable -var watchList = [ +const watchList = [ { "Title": "Inception", "Year": "2010", @@ -311,7 +310,5 @@ var watchList = [ } ]; -// Only change code below this line -let filteredList = watchList.filter(e => e.imdbRating >= 8).map( ({Title: title, imdbRating: rating}) => ({title, rating}) ); -// Only change code above this line +const filteredList = watchList.filter(e => e.imdbRating >= 8).map( ({Title: title, imdbRating: rating}) => ({title, rating}) ); ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/use-the-map-method-to-extract-data-from-an-array.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/use-the-map-method-to-extract-data-from-an-array.md index 4560004153..5990cfeae4 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/use-the-map-method-to-extract-data-from-an-array.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/use-the-map-method-to-extract-data-from-an-array.md @@ -61,7 +61,7 @@ Il tuo codice dovrebbe utilizzare il metodo `map`. assert(code.match(/\.map/g)); ``` -`ratings` dovrebbe essere uguale a `[{"title":"Inception","rating":"8.8"},{"title":"Interstellar","rating":"8.6"},{"title":"The Dark Knight","rating":"9.0"},{"title":"Batman Begins","rating":"8.3"},{"title":"Avatar","rating":"7.9"}]`. +`ratings` dovrebbe essere uguale a `[{"title": "Inception", "rating": "8.8"}, {"title": "Interstellar", "rating": "8.6"}, {"title": "The Dark Knight", "rating": "9.0"},{"title": "Batman Begins", "rating": "8.3"}, {"title": "Avatar", "rating": "7.9"}]`. ```js assert.deepEqual(ratings, [ @@ -79,7 +79,7 @@ assert.deepEqual(ratings, [ ```js // The global variable -var watchList = [ +const watchList = [ { "Title": "Inception", "Year": "2010", @@ -194,9 +194,9 @@ var watchList = [ // Only change code below this line -var ratings = []; -for(var i=0; i < watchList.length; i++){ - ratings.push({title: watchList[i]["Title"], rating: watchList[i]["imdbRating"]}); +const ratings = []; +for (let i = 0; i < watchList.length; i++) { + ratings.push({title: watchList[i]["Title"], rating: watchList[i]["imdbRating"]}); } // Only change code above this line @@ -207,8 +207,7 @@ console.log(JSON.stringify(ratings)); # --solutions-- ```js -// The global variable -var watchList = [ +const watchList = [ { "Title": "Inception", "Year": "2010", @@ -321,7 +320,7 @@ var watchList = [ } ]; -var ratings = watchList.map(function(movie) { +const ratings = watchList.map(function(movie) { return { title: movie["Title"], rating: movie["imdbRating"] diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/use-the-reduce-method-to-analyze-data.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/use-the-reduce-method-to-analyze-data.md index b099d5bde6..fefae672b9 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/use-the-reduce-method-to-analyze-data.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/use-the-reduce-method-to-analyze-data.md @@ -93,7 +93,7 @@ assert(getRating(watchList.filter((_, i) => i < 1 || i > 2)) === 8.55); ```js // The global variable -var watchList = [ +const watchList = [ { "Title": "Inception", "Year": "2010", @@ -206,22 +206,22 @@ var watchList = [ } ]; -function getRating(watchList){ +function getRating(watchList) { // Only change code below this line - var averageRating; + let averageRating; // Only change code above this line return averageRating; } + console.log(getRating(watchList)); ``` # --solutions-- ```js -// The global variable -var watchList = [ +const watchList = [ { "Title": "Inception", "Year": "2010", @@ -334,8 +334,8 @@ var watchList = [ } ]; -function getRating(watchList){ - var averageRating; +function getRating(watchList) { + let averageRating; const rating = watchList .filter(obj => obj.Director === "Christopher Nolan") .map(obj => Number(obj.imdbRating)); diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/use-the-some-method-to-check-that-any-elements-in-an-array-meet-a-criteria.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/use-the-some-method-to-check-that-any-elements-in-an-array-meet-a-criteria.md index 4463777602..6e40098e44 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/use-the-some-method-to-check-that-any-elements-in-an-array-meet-a-criteria.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/functional-programming/use-the-some-method-to-check-that-any-elements-in-an-array-meet-a-criteria.md @@ -13,7 +13,8 @@ Il metodo `some` funziona con gli array per verificare se *un qualunque* element Ad esempio, il seguente codice controllerà se almeno un elemento nell'array `numbers` è inferiore a 10: ```js -var numbers = [10, 50, 8, 220, 110, 11]; +const numbers = [10, 50, 8, 220, 110, 11]; + numbers.some(function(currentValue) { return currentValue < 10; }); @@ -62,6 +63,7 @@ function checkPositive(arr) { // Only change code above this line } + checkPositive([1, 2, 3, -4, 5]); ``` @@ -69,9 +71,6 @@ checkPositive([1, 2, 3, -4, 5]); ```js function checkPositive(arr) { - // Only change code below this line return arr.some(elem => elem > 0); - // Only change code above this line } -checkPositive([1, 2, 3, -4, 5]); ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays.md index 5d6f36636e..8c51c56de1 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays.md @@ -157,7 +157,7 @@ assert(diffArray([1, 'calf', 3, 'piglet'], [7, 'filly']).length === 6); ```js function diffArray(arr1, arr2) { - var newArr = []; + const newArr = []; return newArr; } @@ -168,13 +168,12 @@ diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]); ```js function diffArray(arr1, arr2) { - var newArr = []; - var h1 = Object.create(null); + const newArr = []; + const h1 = Object.create(null); arr1.forEach(function(e) { h1[e] = e; }); - - var h2 = Object.create(null); + const h2 = Object.create(null); arr2.forEach(function(e) { h2[e] = e; }); diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/make-a-person.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/make-a-person.md index 63db2d40aa..29d39ca009 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/make-a-person.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/make-a-person.md @@ -23,10 +23,19 @@ Esegui i test per vedere l'output atteso per ogni metodo. I metodi che prendono # --hints-- -`Object.keys(bob).length` dovrebbe restituire 6. +Nessuna proprietà dovrebbe essere aggiunta. `Object.keys(bob).length` dovrebbe sempre restituire 6. ```js -assert.deepEqual(Object.keys(bob).length, 6); +assert.strictEqual( + Object.keys((function () { + let bob = new Person('Bob Ross'); + bob.setFirstName('Haskell'); + bob.setLastName('Curry'); + bob.setFullName('John Smith'); + return bob; + })()).length, + 6 + ); ``` `bob instanceof Person` dovrebbe restituire `true`. @@ -139,7 +148,7 @@ if(bob){ ## --seed-contents-- ```js -var Person = function(firstAndLast) { +const Person = function(firstAndLast) { // Only change code below this line // Complete the method below and implement the others similarly this.getFullName = function() { @@ -148,16 +157,16 @@ var Person = function(firstAndLast) { return firstAndLast; }; -var bob = new Person('Bob Ross'); +const bob = new Person('Bob Ross'); bob.getFullName(); ``` # --solutions-- ```js -var Person = function(firstAndLast) { +const Person = function(firstAndLast) { - var firstName, lastName; + let firstName, lastName; function updateName(str) { firstName = str.split(" ")[0]; @@ -192,6 +201,6 @@ var Person = function(firstAndLast) { }; }; -var bob = new Person('Bob Ross'); +const bob = new Person('Bob Ross'); bob.getFullName(); ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/map-the-debris.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/map-the-debris.md index 001fc277e2..5aafa241b3 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/map-the-debris.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/map-the-debris.md @@ -51,8 +51,8 @@ assert.deepEqual( ```js function orbitalPeriod(arr) { - var GM = 398600.4418; - var earthRadius = 6367.4447; + const GM = 398600.4418; + const earthRadius = 6367.4447; return arr; } @@ -63,9 +63,9 @@ orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]); ```js function orbitalPeriod(arr) { - var GM = 398600.4418; - var earthRadius = 6367.4447; - var TAU = 2 * Math.PI; + const GM = 398600.4418; + const earthRadius = 6367.4447; + const TAU = 2 * Math.PI; return arr.map(function(obj) { return { name: obj.name, @@ -73,6 +73,4 @@ function orbitalPeriod(arr) { }; }); } - -orbitalPeriod([{name : "sputkin", avgAlt : 35873.5553}]); ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple.md index 03879b19f4..5a26b6e01b 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple.md @@ -61,7 +61,6 @@ function smallestCommons(arr) { return arr; } - smallestCommons([1,5]); ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou.md index c74446657e..9064b93e5d 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou.md @@ -103,7 +103,7 @@ assert.deepEqual( ```js function whatIsInAName(collection, source) { - var arr = []; + const arr = []; // Only change code below this line @@ -118,8 +118,8 @@ whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: ```js function whatIsInAName(collection, source) { - var arr = []; - var keys = Object.keys(source); + const arr = []; + const keys = Object.keys(source); collection.forEach(function(e) { if(keys.every(function(key) {return e[key] === source[key];})) { arr.push(e); diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/caesars-cipher.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/caesars-cipher.md index aee75cf077..788ac0d982 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/caesars-cipher.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/caesars-cipher.md @@ -51,7 +51,6 @@ assert( ```js function rot13(str) { - return str; } diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/cash-register.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/cash-register.md index 1910e938ac..8896cc86f4 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/cash-register.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/cash-register.md @@ -186,7 +186,7 @@ assert.deepEqual( ```js function checkCashRegister(price, cash, cid) { - var change; + let change; return change; } @@ -196,54 +196,57 @@ checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], [ # --solutions-- ```js -var denom = [ - { name: 'ONE HUNDRED', val: 100}, - { name: 'TWENTY', val: 20}, - { name: 'TEN', val: 10}, - { name: 'FIVE', val: 5}, - { name: 'ONE', val: 1}, - { name: 'QUARTER', val: 0.25}, - { name: 'DIME', val: 0.1}, - { name: 'NICKEL', val: 0.05}, - { name: 'PENNY', val: 0.01} +const denom = [ + { name: "ONE HUNDRED", val: 100 }, + { name: "TWENTY", val: 20 }, + { name: "TEN", val: 10 }, + { name: "FIVE", val: 5 }, + { name: "ONE", val: 1 }, + { name: "QUARTER", val: 0.25 }, + { name: "DIME", val: 0.1 }, + { name: "NICKEL", val: 0.05 }, + { name: "PENNY", val: 0.01 }, ]; function checkCashRegister(price, cash, cid) { - var output = {status: null, change: []}; - var change = cash - price; - var register = cid.reduce(function(acc, curr) { - acc.total += curr[1]; - acc[curr[0]] = curr[1]; - return acc; - }, {total: 0}); - if(register.total === change) { - output.status = 'CLOSED'; - output.change = cid; - return output; - } - if(register.total < change) { - output.status = 'INSUFFICIENT_FUNDS'; - return output; - } - var change_arr = denom.reduce(function(acc, curr) { - var value = 0; - while(register[curr.name] > 0 && change >= curr.val) { - change -= curr.val; - register[curr.name] -= curr.val; - value += curr.val; - change = Math.round(change * 100) / 100; - } - if(value > 0) { - acc.push([ curr.name, value ]); - } - return acc; - }, []); - if(change_arr.length < 1 || change > 0) { - output.status = 'INSUFFICIENT_FUNDS'; - return output; - } - output.status = 'OPEN'; - output.change = change_arr; - return output; + const output = { status: null, change: [] }; + let change = cash - price; + const register = cid.reduce( + function (acc, curr) { + acc.total += curr[1]; + acc[curr[0]] = curr[1]; + return acc; + }, + { total: 0 } + ); + if (register.total === change) { + output.status = "CLOSED"; + output.change = cid; + return output; + } + if (register.total < change) { + output.status = "INSUFFICIENT_FUNDS"; + return output; + } + const change_arr = denom.reduce(function (acc, curr) { + let value = 0; + while (register[curr.name] > 0 && change >= curr.val) { + change -= curr.val; + register[curr.name] -= curr.val; + value += curr.val; + change = Math.round(change * 100) / 100; + } + if (value > 0) { + acc.push([curr.name, value]); + } + return acc; + }, []); + if (change_arr.length < 1 || change > 0) { + output.status = "INSUFFICIENT_FUNDS"; + return output; + } + output.status = "OPEN"; + output.change = change_arr; + return output; } ``` diff --git a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/palindrome-checker.md b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/palindrome-checker.md index 6d4161dd77..61b1c1ab41 100644 --- a/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/palindrome-checker.md +++ b/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/palindrome-checker.md @@ -107,8 +107,6 @@ function palindrome(str) { return true; } - - palindrome("eye"); ``` diff --git a/curriculum/challenges/italian/03-front-end-development-libraries/front-end-development-libraries-projects/build-a-markdown-previewer.md b/curriculum/challenges/italian/03-front-end-development-libraries/front-end-development-libraries-projects/build-a-markdown-previewer.md index 12727866b5..85f1049c60 100644 --- a/curriculum/challenges/italian/03-front-end-development-libraries/front-end-development-libraries-projects/build-a-markdown-previewer.md +++ b/curriculum/challenges/italian/03-front-end-development-libraries/front-end-development-libraries-projects/build-a-markdown-previewer.md @@ -22,7 +22,7 @@ Puoi utilizzare qualsiasi mix di HTML, JavaScript, CSS, Bootstrap, SASS, React, **User Story #4:** Quando inserisco markdown in stile GitHub nell'elemento `#editor`, il testo viene presentato come HTML nell'elemento `#preview` mentre digito (SUGGERIMENTO: Non è necessario che analizzi tu stesso il Markdown - puoi importare la libreria Marked per questo: [https://cdnjs. om/libraries/marked](https://cdnjs.com/libraries/marked)). -**User Story #5:** Quando il mio visualizzatore di markdown viene caricato inizialmente, il testo predefinito nel campo `#editor` dovrebbe contenere markdown valido che rappresenti almeno uno dei seguenti elementi: un'intestazione (dimensione H1), una sotto-intestazione (formato H2), un collegamento, del codice in linea, un blocco di codice, un elemento lista, un blockquote, un'immagine e un testo in grassetto. +**User Story #5:** Quando il mio visualizzatore di markdown viene caricato inizialmente, il testo predefinito nel campo `#editor` dovrebbe contenere del markdown valido che rappresenti almeno uno dei seguenti elementi: un'intestazione (dimensione H1), una sotto-intestazione (formato H2), un collegamento, del codice in linea, un blocco di codice, un elemento di lista, un blockquote, un'immagine e un testo in grassetto. **User Story #6:** Quando il mio visualizzatore di markdown viene caricato inizialmente, il markdown predefinito nel campo `#editor` dovrebbe essere presentato come HTML nell'elemento `#preview`. diff --git a/curriculum/challenges/italian/03-front-end-development-libraries/react/access-props-using-this.props.md b/curriculum/challenges/italian/03-front-end-development-libraries/react/access-props-using-this.props.md index 941b8bf6a0..6e06494d7d 100644 --- a/curriculum/challenges/italian/03-front-end-development-libraries/react/access-props-using-this.props.md +++ b/curriculum/challenges/italian/03-front-end-development-libraries/react/access-props-using-this.props.md @@ -14,67 +14,54 @@ Ogni volta che fai riferimento a un componente di classe all'interno di sé stes # --instructions-- -Mostra un'istanza del componente `ReturnTempPassword` nel componente genitore `ResetPassword`. Qui, dai a `ReturnTempPassword` una prop di `tempPassword` e assegnale un valore stringa di almeno 8 caratteri. All'interno del figlio, `ReturnTempPassword`, accedi alla prop `tempPassword` all'interno dei tag `strong` per assicurarti che l'utente veda la password temporanea. +Mostra un'istanza del componente `Welcome` nel componente genitore `App`. Qui, dai a `Welcome` una proprietà di `name` e assegnale il valore di una stringa. Dentro il componente figlio, `Welcome`, accedi alla proprietà `name` dentro le tag `strong`. # --hints-- -Il componente `ResetPassword` dovrebbe restituire un singolo elemento `div`. +Il componente `App` dovrebbe restituire un singolo elemento `div`. ```js assert( (function () { - const mockedComponent = Enzyme.mount(React.createElement(ResetPassword)); + const mockedComponent = Enzyme.mount(React.createElement(App)); return mockedComponent.children().type() === 'div'; })() ); ``` -Il quarto figlio di `ResetPassword` dovrebbe essere il componente `ReturnTempPassword`. +Il figlio di `App` dovrebbe essere il componente `Welcome`. ```js assert( (function () { - const mockedComponent = Enzyme.mount(React.createElement(ResetPassword)); + const mockedComponent = Enzyme.mount(React.createElement(App)); return ( - mockedComponent.children().childAt(3).name() === 'ReturnTempPassword' + mockedComponent.children().childAt(0).name() === 'Welcome' ); })() ); ``` -Il componente `ReturnTempPassword` dovrebbe avere una prop chiamata `tempPassword`. +Il componente `Welcome` dovrebbe avere una prop chiamata `name`. ```js assert( (function () { - const mockedComponent = Enzyme.mount(React.createElement(ResetPassword)); - return mockedComponent.find('ReturnTempPassword').props().tempPassword; + const mockedComponent = Enzyme.mount(React.createElement(App)); + return mockedComponent.find('Welcome').props().name; })() ); ``` -L'elemento `tempPassword` di `ReturnTempPassword` dovrebbe essere uguale a una stringa di almeno 8 caratteri. +Il componente `Welcome` dovrebbe visualizzare la stringa che crei come prop `name` all'interno dei tag `strong`. ```js assert( (function () { - const mockedComponent = Enzyme.mount(React.createElement(ResetPassword)); - const temp = mockedComponent.find('ReturnTempPassword').props() - .tempPassword; - return typeof temp === 'string' && temp.length >= 8; - })() -); -``` - -Il componente `ReturnTempPassword` dovrebbe visualizzare la password che crei come prop `tempPassword` all'interno dei tag `strong`. - -```js -assert( - (function () { - const mockedComponent = Enzyme.mount(React.createElement(ResetPassword)); + const mockedComponent = Enzyme.mount(React.createElement(App)); return ( mockedComponent.find('strong').text() === - mockedComponent.find('ReturnTempPassword').props().tempPassword + mockedComponent.find('Welcome').props().name ); })() ); @@ -85,13 +72,13 @@ assert( ## --after-user-code-- ```jsx -ReactDOM.render(, document.getElementById('root')) +ReactDOM.render(, document.getElementById('root')) ``` ## --seed-contents-- ```jsx -class ReturnTempPassword extends React.Component { +class App extends React.Component { constructor(props) { super(props); @@ -100,14 +87,14 @@ class ReturnTempPassword extends React.Component { return (
{ /* Change code below this line */ } -

Your temporary password is:

+ { /* Change code above this line */ }
); } }; -class ResetPassword extends React.Component { +class Welcome extends React.Component { constructor(props) { super(props); @@ -115,11 +102,8 @@ class ResetPassword extends React.Component { render() { return (
-

Reset Password

-

We've generated a new temporary password for you.

-

Please reset this password from your account settings ASAP.

{ /* Change code below this line */ } - +

Hello, !

{ /* Change code above this line */ }
); @@ -130,7 +114,7 @@ class ResetPassword extends React.Component { # --solutions-- ```jsx -class ReturnTempPassword extends React.Component { +class Welcome extends React.Component { constructor(props) { super(props); @@ -138,28 +122,27 @@ class ReturnTempPassword extends React.Component { render() { return (
-

Your temporary password is: {this.props.tempPassword}

-
- ); - } -}; - -class ResetPassword extends React.Component { - constructor(props) { - super(props); - - } - render() { - return ( -
-

Reset Password

-

We've generated a new temporary password for you.

-

Please reset this password from your account settings ASAP.

{ /* Change code below this line */ } - +

Hello, {this.props.name}!

{ /* Change code above this line */ }
); } }; + +class App extends React.Component { + constructor(props) { + super(props); + + } + render() { + return ( +
+ { /* Change code below this line */ } + + { /* Change code above this line */ } +
+ ); + } +}; ``` diff --git a/curriculum/challenges/italian/03-front-end-development-libraries/react/create-a-controlled-form.md b/curriculum/challenges/italian/03-front-end-development-libraries/react/create-a-controlled-form.md index fb7db4bdf3..80dce6a868 100644 --- a/curriculum/challenges/italian/03-front-end-development-libraries/react/create-a-controlled-form.md +++ b/curriculum/challenges/italian/03-front-end-development-libraries/react/create-a-controlled-form.md @@ -109,7 +109,7 @@ assert( ); ``` -L'intestazione `h1` dovrebbe fare il render del valore del campo `submit` prendendolo dallo stato del componente. +L'elemento di intestazione `h1` dovrebbe fare il render del valore del campo `submit` prendendolo dallo stato del componente. ```js (() => { diff --git a/curriculum/challenges/italian/03-front-end-development-libraries/react/create-a-react-component.md b/curriculum/challenges/italian/03-front-end-development-libraries/react/create-a-react-component.md index 94c7c82f24..dc591f40f6 100644 --- a/curriculum/challenges/italian/03-front-end-development-libraries/react/create-a-react-component.md +++ b/curriculum/challenges/italian/03-front-end-development-libraries/react/create-a-react-component.md @@ -38,7 +38,7 @@ Il componente React dovrebbe restituire un elemento `div`. assert(Enzyme.shallow(React.createElement(MyComponent)).type() === 'div'); ``` -Il `div` restituito dovrebbe fare il render di un header `h1` al suo interno. +Il `div` restituito dovrebbe fare il render di un elemento di intestazione `h1` al suo interno. ```js assert( diff --git a/curriculum/challenges/italian/03-front-end-development-libraries/react/render-state-in-the-user-interface-another-way.md b/curriculum/challenges/italian/03-front-end-development-libraries/react/render-state-in-the-user-interface-another-way.md index f23ecdd208..2026018671 100644 --- a/curriculum/challenges/italian/03-front-end-development-libraries/react/render-state-in-the-user-interface-another-way.md +++ b/curriculum/challenges/italian/03-front-end-development-libraries/react/render-state-in-the-user-interface-another-way.md @@ -27,7 +27,7 @@ assert( ); ``` -`MyComponent` dovrebbe presentare un'intestazione `h1` racchiusa in un singolo `div`. +`MyComponent` dovrebbe presentare un elemento di intestazione `h1` racchiusa in un singolo `div`. ```js assert( diff --git a/curriculum/challenges/italian/03-front-end-development-libraries/react/render-state-in-the-user-interface.md b/curriculum/challenges/italian/03-front-end-development-libraries/react/render-state-in-the-user-interface.md index 9ff712bae4..6913dd27e0 100644 --- a/curriculum/challenges/italian/03-front-end-development-libraries/react/render-state-in-the-user-interface.md +++ b/curriculum/challenges/italian/03-front-end-development-libraries/react/render-state-in-the-user-interface.md @@ -33,7 +33,7 @@ assert( ); ``` -`MyComponent` dovrebbe presentare un'intestazione `h1` racchiusa in un singolo `div`. +`MyComponent` dovrebbe presentare un elemento di intestazione `h1` racchiusa in un singolo `div`. ```js assert( diff --git a/curriculum/challenges/italian/05-back-end-development-and-apis/basic-node-and-express/use-the-.env-file.md b/curriculum/challenges/italian/05-back-end-development-and-apis/basic-node-and-express/use-the-.env-file.md index 35036315de..11ce41eb97 100644 --- a/curriculum/challenges/italian/05-back-end-development-and-apis/basic-node-and-express/use-the-.env-file.md +++ b/curriculum/challenges/italian/05-back-end-development-and-apis/basic-node-and-express/use-the-.env-file.md @@ -22,6 +22,8 @@ Poi, nel gestore della rotta GET `/json` che hai creato nell'ultima sfida, trasf **Nota:** Se stai usando Replit, non puoi creare un file `.env`. Utilizza invece la scheda SECRETS integrata per aggiungere la variabile. +Se stai lavorando in locale, avrai bisogno del pacchetto `dotenv`. Carica le variabili ambientali dal tuo file `.env` in `process.env`. Installalo con `npm install dotenv`. Quindi, in cima al tuo file `myApp.js`, importa e carica le variabili con `require('dotenv').config()`. + # --hints-- La risposta dell'endpoint `/json` dovrebbe cambiare in base alla variabile d'ambiente `MESSAGE_STYLE` diff --git a/curriculum/challenges/italian/09-information-security/information-security-projects/stock-price-checker.md b/curriculum/challenges/italian/09-information-security/information-security-projects/stock-price-checker.md index d3ca92e390..6d919bad07 100644 --- a/curriculum/challenges/italian/09-information-security/information-security-projects/stock-price-checker.md +++ b/curriculum/challenges/italian/09-information-security/information-security-projects/stock-price-checker.md @@ -27,6 +27,8 @@ Quando hai finito, assicurati che una demo funzionante del tuo progetto sia ospi 3. Aggiungerai tutte le funzionalità di sicurezza a `server.js` 4. Creerai tutti i test funzionali in `tests/2_functional-tests.js` +**Nota** Considerazioni sulla privacy: a causa del requisito che solo 1 like per IP dovrebbe essere accettato, è necessario salvare gli indirizzi IP. È importante mantenere il rispetto delle leggi sulla privacy dei dati come il General Data Protection Regulation. Una opzione è quella di ottenere il permesso di salvare i dati dell'utente, ma è molto più semplice anonimizzarlo. Per questa sfida, ricordati di anonimizzare gli indirizzi IP prima di salvarli nel database. Se hai bisogno di idee su come farlo, puoi scegliere di fare l'hash dei dati, troncare l'IP, o impostare parte dell'indirizzo IP a 0. + Scrivi i seguenti test in `tests/2_functional-tests.js`: - Visualizzazione di un'azione: richiesta GET a `/api/stock-prices/` @@ -37,7 +39,7 @@ Scrivi i seguenti test in `tests/2_functional-tests.js`: # --hints-- -Puoi fornire il tuo progetto e non l'URL di esempio. +È necessario fornire il proprio progetto, non l'URL di esempio. ```js (getUserInput) => { @@ -110,7 +112,7 @@ async (getUserInput) => { }; ``` -Tutti i 5 test funzionali sono completi e superati. +Tutti i 5 test funzionali richiesti sono completi e superati. ```js async (getUserInput) => { diff --git a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/breadth-first-search.md b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/breadth-first-search.md index 1207024135..e6840ccd56 100644 --- a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/breadth-first-search.md +++ b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/breadth-first-search.md @@ -8,31 +8,31 @@ dashedName: breadth-first-search # --description-- -So far, we've learned different ways of creating representations of graphs. What now? One natural question to have is what are the distances between any two nodes in the graph? Enter graph traversal algorithms. +Finora, abbiamo imparato diversi modi per creare rappresentazioni di grafi. E adesso? Una domanda naturale da porsi è quali sono le distanze tra due nodi qualsiasi nel grafo? Qui entrano in gioco gli algoritmi di attraversamento di grafi. -Traversal algorithms are algorithms to traverse or visit nodes in a graph. One type of traversal algorithm is the breadth-first search algorithm. +Gli algoritmi di attraversamento sono algoritmi per attraversare o visitare nodi in un grafo. Un tipo di algoritmo di attraversamento è l'algoritmo Breadth-first Search (di ricerca in ampiezza). -This algorithm starts at one node and visits all its neighbors that are one edge away. It then goes on to visit each of their neighbors and so on until all nodes have been reached. +Questo algoritmo inizia da un nodo e visita tutti i suoi vicini che sono ad un arco di distanza. Poi continua a visitare ciascuno dei loro vicini e così via fino a quando tutti i nodi sono stati raggiunti. -An important data structure that will help implement the breadth-first search algorithm is the queue. This is an array where you can add elements to one end and remove elements from the other end. This is also known as a FIFO or First-In-First-Out data structure. +Una struttura dati importante che aiuterà ad implementare l'algoritmo di ricerca in ampiezza è la coda. Questa è un array dove è possibile aggiungere elementi ad una estremità e rimuovere elementi dall'altra estremità. Essa è nota anche come una struttura di dati FIFO o First-In-First-Out (NdT: il primo a entrare è il primo a uscire). -Visually, this is what the algorithm is doing. ![Breadth first search algorithm moving through a tree](https://camo.githubusercontent.com/2f57e6239884a1a03402912f13c49555dec76d06/68747470733a2f2f75706c6f61642e77696b696d656469612e6f72672f77696b6970656469612f636f6d6d6f6e732f342f34362f416e696d617465645f4246532e676966) +Visualmente, questo è ciò che l'algoritmo sta facendo. ![Algoritmo Breadth-first Search che si muove attraverso un albero](https://camo.githubusercontent.com/2f57e6239884a1a03402912f13c49555dec76d06/68747470733a2f2f75706c6f61642e77696b696d656469612e6f72672f77696b6970656469612f636f6d6d6f6e732f342f34362f416e696d617465645f4246532e676966) -The grey shading represents a node getting added into the queue and the black shading represents a node getting removed from the queue. See how every time a node gets removed from the queue (node turns black), all their neighbors get added into the queue (node turns grey). +L'ombreggiatura grigia rappresenta un nodo che viene aggiunto alla coda e l'ombreggiatura nera rappresenta un nodo che viene rimosso dalla coda. Vedi come ogni volta che un nodo viene rimosso dalla coda (il nodo diventa nero), tutti i vicini vengono aggiunti alla coda (il nodo diventa grigio). -To implement this algorithm, you'll need to input a graph structure and a node you want to start at. +Per implementare questo algoritmo, dovrai inserire una struttura grafo e un nodo da cui vuoi iniziare. -First, you'll want to be aware of the distances from, or number of edges away from, the start node. You'll want to start all your distances with some large number, like `Infinity`. This prevents counting issues for when a node may not be reachable from your start node. Next, you'll want to go from the start node to its neighbors. These neighbors are one edge away and at this point you should add one unit of distance to the distances you're keeping track of. +Innanzitutto, dovrai essere consapevole delle distanze (o del numero di archi di distanza) dal nodo iniziale. Ti consigliamo di inizializzare tutte le distanze con un numero elevato, come `Infinity`. Questo impedisce problemi di conteggio per quando un nodo potrebbe non essere raggiungibile dal nodo iniziale. Successivamente, vorrai andare dal nodo iniziale ai suoi vicini. Questi vicini sono a un arco di distanza e a questo punto dovresti aggiungere un'unità di distanza alle distanze di cui stai tenendo traccia. # --instructions-- -Write a function `bfs()` that takes an adjacency matrix graph (a two-dimensional array) and a node label root as parameters. The node label will just be the integer value of the node between `0` and `n - 1`, where `n` is the total number of nodes in the graph. +Scrivi una funzione `bfs()` che prende un grafo a matrice di adiacenza (un array bidimensionale) e l'etichetta di un nodo radice come parametri. L'etichetta del nodo sarà solo il valore intero del nodo tra `0` e `n - 1`, dove `n` è il numero totale di nodi nel grafico. -Your function will output a JavaScript object key-value pairs with the node and its distance from the root. If the node could not be reached, it should have a distance of `Infinity`. +La tua funzione produrrà coppie chiave-valore di un oggetto JavaScript con il nodo e la sua distanza dalla radice. Se il nodo non può essere raggiunto, dovrebbe avere una distanza di `Infinity`. # --hints-- -The input graph `[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0]]` with a start node of `1` should return `{0: 1, 1: 0, 2: 1, 3: 2}` +Il grafico in ingresso `[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0]]` con un nodo iniziale di `1` dovrebbe restituire `{0: 1, 1: 0, 2: 1, 3: 2}` ```js assert( @@ -49,7 +49,7 @@ assert( ); ``` -The input graph `[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 0]]` with a start node of `1` should return `{0: 1, 1: 0, 2: 1, 3: Infinity}` +Il grafico in ingresso `[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 0]]` con un nodo iniziale di `1` dovrebbe restituire `{0: 1, 1: 0, 2: 1, 3: Infinity}` ```js assert( @@ -66,7 +66,7 @@ assert( ); ``` -The input graph `[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0]]` with a start node of `0` should return `{0: 0, 1: 1, 2: 2, 3: 3}` +Il grafico in ingresso `[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0]]` con un nodo iniziale di `0` dovrebbe restituire `{0: 0, 1: 1, 2: 2, 3: 3}` ```js assert( @@ -83,7 +83,7 @@ assert( ); ``` -The input graph `[[0, 1], [1, 0]]` with a start node of `0` should return `{0: 0, 1: 1}` +Il grafo in ingresso `[[0, 1], [1, 0]]` con un nodo iniziale di `0` dovrebbe restituire `{0: 0, 1: 1}` ```js assert( diff --git a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/create-a-circular-queue.md b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/create-a-circular-queue.md index 16ff688fab..70828ff286 100644 --- a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/create-a-circular-queue.md +++ b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/create-a-circular-queue.md @@ -1,6 +1,6 @@ --- id: 587d8255367417b2b2512c75 -title: Create a Circular Queue +title: Creare una coda circolare challengeType: 1 forumTopicId: 301625 dashedName: create-a-circular-queue @@ -8,9 +8,9 @@ dashedName: create-a-circular-queue # --description-- -In this challenge you will be creating a Circular Queue. A circular queue is a queue that writes to the end of a collection then begins overwriting itself at the beginning of the collection. This type of data structure is useful in certain situations. For example, a circular queue can be used for streaming media. Once the queue is full, new media data will overwrite old data. +In questa sfida creerai una coda circolare. Una coda circolare è una coda che scrive alla fine di una collezione, poi inizia a sovrascrivere sè stessa all'inizio della collezione. Questo tipo di struttura dati è utile in determinate situazioni. Ad esempio, una coda circolare può essere utilizzata per lo streaming media. Una volta che la coda è piena, i nuovi dati multimediali sovrascriveranno i vecchi dati. -A good way to illustrate this concept is with an array of length `5`: +Un buon modo per illustrare questo concetto è con un array di lunghezza `5`: ```js [null, null, null, null, null] @@ -18,7 +18,7 @@ A good way to illustrate this concept is with an array of length `5`: ^Write @ 0 ``` -Here the read and write are both at position `0`. Now the queue gets 3 new records `a`, `b`, and `c`. Our queue now looks like: +Qui la lettura e la scrittura sono entrambe in posizione `0`. Ora la coda ottiene 3 nuovi record `a`, `b`e `c`. La nostra coda ora assomiglia a: ```js [a, b, c, null, null] @@ -26,7 +26,7 @@ Here the read and write are both at position `0`. Now the queue gets 3 new recor ^Write @ 3 ``` -As the read head reads, it can remove values or keep them: +Come la testa di lettura legge, può remove valori o conservarli: ```js [null, null, null, null, null] @@ -34,7 +34,7 @@ As the read head reads, it can remove values or keep them: ^Write @ 3 ``` -Now we write the values `d`, `e`, and `f` to the queue. Once the write reaches the end of the array it loops back to the beginning: +Ora scriviamo i valori `d`, `e` e `f` nella coda. Una volta che la scrittura raggiunge la fine dell'array si riprende dall'inizio: ```js [f, null, null, d, e] @@ -42,21 +42,21 @@ Now we write the values `d`, `e`, and `f` to the queue. Once the write reaches t ^Write @ 1 ``` -This approach requires a constant amount of memory but allows files of a much larger size to be processed. +Questo approccio richiede una quantità costante di memoria, ma consente di elaborare file di dimensioni molto più grandi. # --instructions-- -In this challenge we will implement a circular queue. The circular queue should provide `enqueue` and `dequeue` methods which allow you to read from and write to the queue. The class itself should also accept an integer argument which you can use to specify the size of the queue when created. We've written the starting version of this class for you in the code editor. +In questa sfida implementeremo una coda circolare. La coda circolare dovrebbe fornire i metodi `enqueue` e `dequeue` che ti consentono di leggere e scrivere nella coda. La classe stessa dovrebbe anche accettare un argomento intero che puoi usare per specificare la dimensione della coda quando viene creata. Abbiamo scritto per te la versione iniziale di questa classe nell'editor di codice. -When you enqueue items to the queue, the write pointer should advance forward and loop back to the beginning once it reaches the end of the queue. The `enqueue` method should return the item you enqueued if it is successful; otherwise it will return `null`. +Quando accodi gli elementi alla coda, il puntatore di scrittura dovrebbe andare in avanti e tornare all'inizio una volta che ha raggiunto la fine della coda. Il metodo `enqueue` dovrebbe restituire l'elemento che hai accodato se ha avuto successo; altrimenti restituirà `null`. -Likewise, the read pointer should advance forward as you dequeue items. When you dequeue an item, that item should be returned. If you cannot dequeue an item, you should return `null`. +Allo stesso modo, il puntatore di lettura dovrebbe avanzare come rimuovi oggetti dalla coda. Quando rimuovi un oggetto dalla coda, quell'oggetto dovrebbe essere restituito. Se non puoi rimuovere un oggetto dalla coda, dovresti restituire `null`. -The write pointer should not be allowed to move past the read pointer (our class won't let you overwrite data you haven't read yet) and the read pointer should not be able to advance past data you have written. +Al puntatore di scrittura non dovrebbe essere permesso di muovere oltre il puntatore di lettura (la nostra classe non ti permetterà di sovrascrivere dati che non sono ancora stati letti) e il puntatore di lettura non dovrebbe eessere in grado di andare oltre i dati che hai scritto. # --hints-- -The `enqueue` method should add items to the circular queue. +Il metodo `enqueue` dovrebbe aggiungere elementi alla coda circolare. ```js assert( @@ -71,7 +71,7 @@ assert( ); ``` -You should not enqueue items past the read pointer. +Non dovresti accodare gli elementi oltre il puntatore di lettura. ```js assert( @@ -89,7 +89,7 @@ assert( ); ``` -The `dequeue` method should dequeue items from the queue. +Il metodo `dequeue` dovrebbe rimuovere elementi dalla coda. ```js assert( @@ -105,7 +105,7 @@ assert( ); ``` -After an item is dequeued, its position in the queue should be reset to `null`. +Dopo che un elemento è stato rimosso dalla coda, la sua posizione nella coda dovrebbe essere resettata su `null`. ```js assert( @@ -122,7 +122,7 @@ assert( ); ``` -Trying to dequeue past the write pointer should return `null` and does not advance the write pointer. +Tentare di rimuovere oggetti dalla coda oltre il puntatore di scrittura dovrebbe restituire `null` e non far avanzare il puntatore di scrittura. ```js assert( diff --git a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/create-a-hash-table.md b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/create-a-hash-table.md index a33c3d5178..fdbabbfa61 100644 --- a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/create-a-hash-table.md +++ b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/create-a-hash-table.md @@ -1,6 +1,6 @@ --- id: 587d825b367417b2b2512c8e -title: Create a Hash Table +title: Creare una tabella hash challengeType: 1 forumTopicId: 301627 dashedName: create-a-hash-table @@ -8,23 +8,23 @@ dashedName: create-a-hash-table # --description-- -In this challenge we will learn about hash tables. A Hash table is used to implement associative arrays, or mappings of key-value pairs, like the objects and Maps we have just been studying. A JavaScript object could be implemented as a hash table, for instance (its actual implementation will depend on the environment it's running in). The way a hash table works is that it takes a key input and hashes this key in a deterministic way to some numerical value. This numerical value is then used as the actual key the associated value is stored by. Then, if you try to access the same key again, the hashing function will process the key, return the same numerical result, which will then be used to look up the associated value. This provides very efficient O(1) lookup time on average. +In questa sfida conosceremo le tabelle hash. Una tabella hash viene utilizzata per implementare array associativi, o mappature di coppie chiave-valore, come gli oggetti e le mappe che abbiamo appena studiato. Un oggetto JavaScript ad esempio potrebbe essere implementato come una tabella hash (la sua effettiva implementazione dipenderà dall'ambiente in esecuzione). Il modo in cui funziona una tabella di hash è che richiede un input chiave e fa hash di questa chiave in modo deterministico ad un certo valore numerico. Questo valore numerico viene quindi utilizzato come chiave reale con cui viene memorizzato il valore associato. Quindi, se si tenta di accedere di nuovo alla stessa chiave, la funzione di hash elaborerà la chiave, restituirà lo stesso risultato numerico, che verrà poi utilizzato per cercare il valore associato. Questo fornisce un tempo di ricerca O(1) molto efficiente in media. -Hash tables can be implemented as arrays with hash functions producing array indices within a specified range. In this method, the choice of the array size is important, as is the hashing function. For instance, what if the hashing function produces the same value for two different keys? This is called a collision. One way to handle collisions is to just store both key-value pairs at that index. Then, upon lookup of either, you would have to iterate through the bucket of items to find the key you are looking for. A good hashing function will minimize collisions to maintain efficient search time. +Le tabelle di hash possono essere implementate come array con funzioni di hash che producono indici array all'interno di un intervallo specificato. In questo metodo, la scelta della dimensione dell'array è importante, così come la funzione di hashing. Per esempio, cosa succede se la funzione di hashing produce lo stesso valore per due chiavi diverse? Questa si chiama collisione. Un modo per gestire le collisioni è quello di semplicemente memorizzare entrambe le coppie chiave-valore in quell'indice. Poi, alla ricerca di entrambi, si dovrebbe iterare attraverso il gruppo di oggetti per trovare la chiave che stai cercando. Una buona funzione di hashing minimizzerà le collisioni per mantenere il tempo di ricerca efficiente. -Here, we won't be concerned with the details of hashing or hash table implementation, we will just try to get a general sense of how they work. +Risultati della traduzione Qui non ci occuperemo dei dettagli dell'hashing o dell'implementazione della tabella hash, cercheremo solo di avere un'idea generale di come funzionano. # --instructions-- -Let's create the basic functionality of a hash table. We've created a naive hashing function for you to use. You can pass a string value to the function `hash` and it will return a hashed value you can use as a key for storage. Store items based on this hashed value in the `this.collection` object. Create these three methods: `add`, `remove`, and `lookup`. The first should accept a key value pair to add to the hash table. The second should remove a key-value pair when passed a key. The third should accept a key and return the associated value or `null` if the key is not present. +Creiamo la funzionalità di base di una tabella di hash. Abbiamo creato una funzione di hashing ingenua da usare. Puoi passare un valore di stringa alla funzione `hash` e restituirà un valore hashed che puoi usare come chiave per l'archiviazione. Memorizza gli oggetti in base a questo valore hashed nell'oggetto `this.collection`. Crea questi tre metodi: `add`, `remove` e `lookup`. Il primo dovrebbe accettare una coppia di valori chiave da aggiungere alla tabella hash. Il secondo dovrebbe rimuovere una coppia chiave-valore quando riceve una chiave. Il terzo dovrebbe accettare una chiave e restituire il valore associato o `null` se la chiave non è presente. -Be sure to write your code to account for collisions! +Assicurati di scrivere il tuo codice per gestire le collisioni! -**Note:** The `remove` method tests won't pass until the `add` and `lookup` methods are correctly implemented. +**Nota:** I test del metodo `remove` non passeranno fino a quando i metodi `add` e `lookup` non saranno correttamente implementati. # --hints-- -The HashTable data structure should exist. +La struttura di dati HashTable dovrebbe esistere. ```js assert( @@ -38,7 +38,7 @@ assert( ); ``` -The HashTable should have an add method. +L'HashTable dovrebbe avere un metodo add. ```js assert( @@ -52,7 +52,7 @@ assert( ); ``` -The HashTable should have a lookup method. +L'HashTable dovrebbe avere un metodo lookup. ```js assert( @@ -66,7 +66,7 @@ assert( ); ``` -The HashTable should have a remove method. +L'HashTable dovrebbe avere un metodo remove. ```js assert( @@ -80,7 +80,7 @@ assert( ); ``` -The add method should add key value pairs and the lookup method should return the values associated with a given key. +Il metodo add dovrebbe aggiungere coppie chiave-valore e il metodo di ricerca dovrebbe restituire i valori associati a una determinata chiave. ```js assert( @@ -95,7 +95,7 @@ assert( ); ``` -The remove method should accept a key as input and should remove the associated key value pair. +Il metodo di rimozione dovrebbe accettare una chiave come input e dovrebbe rimuovere la coppia chiave-valore associata. ```js assert( @@ -113,7 +113,7 @@ assert( ); ``` -The remove method should only remove the correct key value pair. +Il metodo di rimozione dovrebbe rimuovere solo la coppia chiave-valore corretta. ```js assert( @@ -139,7 +139,7 @@ assert( ); ``` -Items should be added using the hash function. +Gli elementi devono essere aggiunti usando la funzione hash. ```js assert( @@ -157,7 +157,7 @@ assert( ); ``` -The hash table should handle collisions. +La tabella di hash dovrebbe gestire le collisioni. ```js assert( diff --git a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/create-a-queue-class.md b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/create-a-queue-class.md index b167ebfcdf..6f60804427 100644 --- a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/create-a-queue-class.md +++ b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/create-a-queue-class.md @@ -1,6 +1,6 @@ --- id: 587d8250367417b2b2512c60 -title: Creare una classe Coda +title: Creare una classe Queue challengeType: 1 forumTopicId: 301631 dashedName: create-a-queue-class diff --git a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/create-a-trie-search-tree.md b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/create-a-trie-search-tree.md index fb838c883e..4afbd6a370 100644 --- a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/create-a-trie-search-tree.md +++ b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/create-a-trie-search-tree.md @@ -1,6 +1,6 @@ --- id: 587d8259367417b2b2512c84 -title: Create a Trie Search Tree +title: Crea un albero di ricerca Trie challengeType: 1 forumTopicId: 301634 dashedName: create-a-trie-search-tree @@ -8,15 +8,15 @@ dashedName: create-a-trie-search-tree # --description-- -Here we will move on from binary search trees and take a look at another type of tree structure called a trie. A trie is an ordered search tree commonly used to hold strings, or more generically associative arrays or dynamic datasets in which the keys are strings. They are very good at storing sets of data when many keys will have overlapping prefixes, for example, all the words in a dictionary. Unlike a binary tree, nodes are not associated with actual values. Instead, the path to a node represents a specific key. For instance, if we wanted to store the string code in a trie, we would have four nodes, one for each letter: c — o — d — e. Following that path through all these nodes will then create code as a string — that path is the key we stored. Then, if we wanted to add the string coding, it would share the first three nodes of code before branching away after the d. In this way, large datasets can be stored very compactly. In addition, search can be very quick because it is effectively limited to the length of the string you are storing. Furthermore, unlike binary trees a node can store any number of child nodes. As you might have guessed from the above example, some metadata is commonly stored at nodes that hold the end of a key so that on later traversals that key can still be retrieved. For instance, if we added codes in our example above we would need some way to know that the e in code represents the end of a key that was previously entered. Otherwise, this information would effectively be lost when we add codes. +Qui ci muoveremo dagli alberi di ricerca binari e daremo un'occhiata ad un altro tipo di struttura ad albero chiamato trie. Un trie è un albero di ricerca ordinato comunemente usato per contenere stringhe, o più generamente array associativi o dataset dinamici in cui le chiavi sono stringhe. Sono un ottimo modo per immagazzinare set di dati quando molte chiavi hanno prefissi che si sovrappongono, per esempio, tutte le parole in un dizionario. A differenza di un albero binario, i nodi non sono associati con valori. Invece, il percorso verso un nodo rappresenta una chiave specifica. Per esempio, se vogliamo salvare la stringa "code" in un trie, avremmo quattri nodi, uno per ogni lettera: c — o — d — e. Seguendo il percorso attraverso tutti questi nodi creerà la stringa "code" — quel percorso è la chiave che abbiamo immagazzinato. Quindi, se vogliamo aggiungere la stringa "coding", avrebbe in comune i primi tre nodi di "code" prima di seguire un altro ramo dopo la d. In questo modo, dataset ampi possono essere immagazzinati in maniera compatta. In aggiunta, una ricerca può essere molto veloce perché è effettivamente limitata alla lunghezza della stringa che stai immagazinnando. Inoltre, a differenza degli alberi binari un nodo può avere qualsiasi numero di nodi figli. Come potresti avere indovinato dall'esempio precedente, alcuni metadata sono comunemente salvati come nodi che contengono la fine della chiave cossicché in traversamenti succestivi la chiave può essere ancora recuperata. Per esempio, se avessimo aggiunto "codes" nell'esempio precedente, avremmo avuto bisogno di qualche modo per sapere che la e in "code" rappresenta la fine di una chiave che era stata inserita precedentemente. Altrimenti, questa informazione andrebbe persa quando aggiungiamo "codes". # --instructions-- -Let's create a trie to store words. It will accept words through an `add` method and store these in a trie data structure. It will also allow us to query if a given string is a word with an `isWord` method, and retrieve all the words entered into the trie with a `print` method. `isWord` should return a boolean value and print should return an array of all these words as string values. In order for us to verify that this data structure is implemented correctly, we've provided a `Node` structure for each node in the tree. Each node will be an object with a `keys` property which is a JavaScript Map object. This will hold the individual letters that are valid keys of each node. We've also created an `end` property on the nodes that can be set to `true` if the node represents the termination of a word. +Creiamo un trie per memorizzare parole. Accetterà parole attraverso un metodo `add` e salverà queste parole in una struttura dati trie. Permetterà anche di chiedere se una certa stringa è una parola con un metodo `isWord`, e estrarre tutte le parole inserite nel trie con un metodo `print`. `isWord` dovrebbe restituire un valore booleano e print dovrebbe restituire un array di tutte queste parole come stringhe. Per poter verificare che la struttura dati è implementata correttamente, abbiamo provveduto una struttura `Node` per ogni nodo dell'albero. Ogni nodo sarà un oggetto con una proprietà `keys` che è un oggetto Map JavaScript. Questo conterrà le lettere individuali che sono chiavi valide per ogni nodo. Abbiamo anche creato una proprietà `end` nel nodo che può essere messa su `true` se il nodo rappresenta la terminazione di una parola. # --hints-- -The Trie should have an add method. +Il Trie dovrebbe avere un metodo add. ```js assert( @@ -32,7 +32,7 @@ assert( ); ``` -The Trie should have a print method. +Il Trie dovrebbe avere un metodo print. ```js assert( @@ -48,7 +48,7 @@ assert( ); ``` -The Trie should have an isWord method. +Il Trie dovrebbe avere un metodo isWord. ```js assert( @@ -64,7 +64,7 @@ assert( ); ``` -The print method should return all items added to the trie as strings in an array. +Il metodo print dovrebbe restituire tutti gli elementi aggiunti al trie come stringhe in un array. ```js assert( @@ -93,7 +93,7 @@ assert( ); ``` -The isWord method should return true only for words added to the trie and false for all other words. +Il metodo isWord dovrebbe restituire vero solo per le parole aggiunte al trie e falso per tutte le altre parole. ```js assert( diff --git a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/create-an-es6-javascript-map.md b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/create-an-es6-javascript-map.md index 7e6822ef67..1a6ec608b3 100644 --- a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/create-an-es6-javascript-map.md +++ b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/create-an-es6-javascript-map.md @@ -1,6 +1,6 @@ --- id: 587d825b367417b2b2512c8d -title: Create an ES6 JavaScript Map +title: Creare una mappa JavaScript ES6 challengeType: 1 forumTopicId: 301635 dashedName: create-an-es6-javascript-map @@ -8,21 +8,21 @@ dashedName: create-an-es6-javascript-map # --description-- -The new version of JavaScript provides us with a built-in Map object which provides much of the functionality we wrote by hand in the last challenge. This Map object, although similar to regular JavaScript objects, provides some useful functionality that normal objects lack. For example, an ES6 Map tracks the insertion order of items that are added to it. Here is a more complete overview of its methods: `.has(key)` returns true or false based on the presence of a key `.get(key)` returns the value associated with a key `.set(key, value)` sets a new key, value pair `.delete(key)` removes a key, value pair `.clear()` removes all key, value pairs `.entries()` returns an array of all the keys in insertion order `.values()` returns an array of all the values in insertion order +La nuova versione di JavaScript ci fornisce un oggetto Map incorporato che fornisce gran parte delle funzionalità che abbiamo scritto a mano nell'ultima sfida. Questo oggetto Map, anche se simile a oggetti JavaScript regolari, fornisce alcune funzionalità utili che agli oggetti normali mancano. Ad esempio, una Map ES6 tiene in memoria l'ordine di inserimento degli elementi che vengono aggiunti. Ecco una panoramica più completa dei suoi metodi: `.has(key)` restituisce true o false in base alla presenza di una chiave `.get(key)` restituisce il valore associato con una chiave `.set(key, value)` aggiunge una nuova coppia chiave-valore `.delete(key)` rimuove una coppia chiave-valore `.clear()` rimuove tutte le coppie chiave-valore `.entries()` restituisce un array con tutte le chiavi in ordine di inserimento `.values()` restituisce un array con tutti i valori in ordine di inserzione # --instructions-- -Define a JavaScript Map object and assign to it a variable called myMap. Add the key, value pair `freeCodeCamp`, `Awesome!` to it. +Definisci un oggetto Map JavaScript e assegna ad esso una variabile chiamata myMap. Aggiungi la coppia chiave-valore `freeCodeCamp`, `Awesome!` ad esso. # --hints-- -The myMap object should exist. +L'oggetto myMap dovrebbe esistere. ```js assert(typeof myMap === 'object'); ``` -myMap should contain the key value pair `freeCodeCamp`, `Awesome!`. +myMap dovrebbe contenere la coppia chiave-valore `freeCodeCamp`, `Awesome!`. ```js assert(myMap.get('freeCodeCamp') === 'Awesome!'); @@ -39,5 +39,7 @@ assert(myMap.get('freeCodeCamp') === 'Awesome!'); # --solutions-- ```js -// solution required +const myMap = new Map(); + +myMap.set("freeCodeCamp", "Awesome!"); ``` diff --git a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/create-and-add-to-sets-in-es6.md b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/create-and-add-to-sets-in-es6.md index 1727a24ed0..04ff67a6d8 100644 --- a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/create-and-add-to-sets-in-es6.md +++ b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/create-and-add-to-sets-in-es6.md @@ -1,6 +1,6 @@ --- id: 587d8254367417b2b2512c70 -title: Create and Add to Sets in ES6 +title: Creare e aggiungere ai set in ES6 challengeType: 1 forumTopicId: 301636 dashedName: create-and-add-to-sets-in-es6 @@ -8,34 +8,34 @@ dashedName: create-and-add-to-sets-in-es6 # --description-- -Now that you have worked through ES5, you are going to perform something similar in ES6. This will be considerably easier. ES6 contains a built-in data structure `Set` so many of the operations you wrote by hand are now included for you. Let's take a look: +Ora che avete lavorato su ES5, state per eseguire qualcosa di simile in ES6. Questo sarà molto più facile. ES6 contiene una struttura di dati integrata `Set` quindi molte delle operazioni che hai scritto a mano sono ora incluse per te. Diamo un'occhiata: -To create a new empty set: +Per creare un nuovo set vuoto: ```js var set = new Set(); ``` -You can create a set with a value: +È possibile creare un set con un valore: ```js var set = new Set(1); ``` -You can create a set with an array: +È possibile creare un set con un array: ```js var set = new Set([1, 2, 3]); ``` -Once you have created a set, you can add the values you wish using the `add` method: +Una volta creato un set, puoi aggiungere i valori che desideri utilizzando il metodo `add`: ```js var set = new Set([1, 2, 3]); set.add([4, 5, 6]); ``` -As a reminder, a set is a data structure that cannot contain duplicate values: +Come promemoria, un insieme è una struttura di dati che non può contenere valori duplicati: ```js var set = new Set([1, 2, 3, 1, 2, 3]); @@ -44,11 +44,11 @@ var set = new Set([1, 2, 3, 1, 2, 3]); # --instructions-- -For this exercise, return a set with the following values: `1, 2, 3, 'Taco', 'Cat', 'Awesome'` +Per questo esercizio, restituisci un set con i seguenti valori: `1, 2, 3, 'Taco', 'Cat', 'Awesome'` # --hints-- -Your `Set` should only contain the values `1, 2, 3, Taco, Cat, Awesome`. +Il tuo `Set` deve contenere solo i valori `1, 2, 3, Taco, Cat, Awesome`. ```js assert( diff --git a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/delete-a-leaf-node-in-a-binary-search-tree.md b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/delete-a-leaf-node-in-a-binary-search-tree.md index 7aa19f4c83..1a422ae4b2 100644 --- a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/delete-a-leaf-node-in-a-binary-search-tree.md +++ b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/delete-a-leaf-node-in-a-binary-search-tree.md @@ -46,6 +46,25 @@ assert( ); ``` +Tentare di rimuovere un elemento da un albero vuoto dovrebbe restituire `null`. + +```js +assert( + (function () { + var test = false; + if (typeof BinarySearchTree !== 'undefined') { + test = new BinarySearchTree(); + } else { + return false; + } + if (typeof test.remove !== 'function') { + return false; + } + return test.remove(100) == null; + })() +); +``` + Tentare di rimuovere un elemento che non esiste dovrebbe restituire `null`. ```js @@ -60,6 +79,8 @@ assert( if (typeof test.remove !== 'function') { return false; } + test.add(15); + test.add(30); return test.remove(100) == null; })() ); diff --git a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/find-the-minimum-and-maximum-height-of-a-binary-search-tree.md b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/find-the-minimum-and-maximum-height-of-a-binary-search-tree.md index eb71f5ea47..8e7556d350 100644 --- a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/find-the-minimum-and-maximum-height-of-a-binary-search-tree.md +++ b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/find-the-minimum-and-maximum-height-of-a-binary-search-tree.md @@ -1,6 +1,6 @@ --- id: 587d8257367417b2b2512c7d -title: Find the Minimum and Maximum Height of a Binary Search Tree +title: Trovare l'altezza minima e massima di un albero binario di ricerca challengeType: 1 forumTopicId: 301641 dashedName: find-the-minimum-and-maximum-height-of-a-binary-search-tree @@ -8,19 +8,19 @@ dashedName: find-the-minimum-and-maximum-height-of-a-binary-search-tree # --description-- -In the last challenge we described a scenario in which a tree could become unbalanced. To understand the concept of balance, let's take a look at another tree property: height. Height in a tree represents the distance from the root node to any given leaf node. Different paths in a highly branched tree structure may have different heights, but for a given tree there will be a minimum and maximum height. If the tree is balanced, these values will differ at most by one. This means that in a balanced tree, all the leaf nodes exist within the same level, or if they are not within the same level they are at most one level apart. +Nell'ultima sfida abbiamo descritto uno scenario in cui un albero potrebbe diventare squilibrato. Per capire il concetto di equilibrio, diamo un'occhiata ad un'altra proprietà dell'albero: l'altezza. L'altezza in un albero rappresenta la distanza dal nodo radice a qualsiasi nodo foglia. Percorsi diversi in una struttura ad albero altamente ramificato possono avere altezze diverse, ma per un dato albero ci sarà un'altezza minima e una massima. Se l'albero è bilanciato, questi valori differiranno al massimo di uno. Ciò significa che in un albero bilanciato, tutti i nodi delle foglie sono allo stesso livello, o al massimo a un livello di distanza. -The property of balance is important for trees because it is what determines the efficiency of tree operations. As we explained in the last challenge, we face worst case time complexity for heavily unbalanced trees. Self-balancing trees are commonly used to account for this issue in trees with dynamic data sets. Common examples of these include AVL trees, red-black trees, and B-trees. These trees all contain additional internal logic which re-balance the tree when insertions or deletions create a state of imbalance. +La proprietà dell'equilibrio è importante per gli alberi perché è ciò che determina l'efficienza delle operazioni su di essi. Come abbiamo spiegato nell'ultima sfida, per alberi fortemente squilibrati ci troviamo di fronte alla peggiore complessità temporale. Gli alberi auto-bilancianti sono comunemente utilizzati per tenere conto di questo problema in alberi con serie di dati dinamici. Esempi comuni di questi includono gli alberi AVL, gli alberi rosso-neri e gli alberi B. Tutti questi alberi contengono una logica interna aggiuntiva che riequilibra l'albero quando inserzioni o cancellazioni creano uno stato di squilibrio. -**Note:** A similar property to height is depth, which refers to how far a given node is from the root node. +**Nota:** Una proprietà simile all'altezza è la profondità, che si riferisce a quanto un dato nodo è lontano dal nodo radice. # --instructions-- -Write two methods for our binary tree: `findMinHeight` and `findMaxHeight`. These methods should return an integer value for the minimum and maximum height within a given binary tree, respectively. If the node is empty let's assign it a height of `-1` (that's the base case). Finally, add a third method `isBalanced` which returns `true` or `false` depending on whether the tree is balanced or not. You can use the first two methods you just wrote to determine this. +Scrivi due metodi per il nostro albero binario: `findMinHeight` e `findMaxHeight`. Questi metodi dovrebbero restituire un valore intero per l'altezza minima e massima all'interno di un dato albero binario, rispettivamente. Se il nodo è vuoto, assegniamogli un'altezza di `-1` (questo è il caso di base). Infine, aggiungi un terzo metodo `isBalanced` che restituisce `true` o `false` a seconda che l'albero sia bilanciato o meno. È possibile utilizzare i primi due metodi che hai appena scritto per determinarlo. # --hints-- -The `BinarySearchTree` data structure should exist. +La struttura di dati `BinarySearchTree` dovrebbe esistere. ```js assert( @@ -34,7 +34,7 @@ assert( ); ``` -The binary search tree should have a method called `findMinHeight`. +L'albero binario di ricerca dovrebbe avere un metodo chiamato `findMinHeight`. ```js assert( @@ -50,7 +50,7 @@ assert( ); ``` -The binary search tree should have a method called `findMaxHeight`. +L'albero binario di ricerca dovrebbe avere un metodo chiamato `findMaxHeight`. ```js assert( @@ -66,7 +66,7 @@ assert( ); ``` -The binary search tree should have a method called `isBalanced`. +L'albero binario di ricerca dovrebbe avere un metodo chiamato `isBalanced`. ```js assert( @@ -82,7 +82,7 @@ assert( ); ``` -The `findMinHeight` method should return the minimum height of the tree. +Il metodo `findMinHeight` deve restituire l'altezza minima dell'albero. ```js assert( @@ -109,7 +109,7 @@ assert( ); ``` -The `findMaxHeight` method should return the maximum height of the tree. +Il metodo `findMaxHeight` deve restituire l'altezza massima dell'albero. ```js assert( @@ -136,7 +136,7 @@ assert( ); ``` -An empty tree should return a height of `-1`. +Un albero vuoto dovrebbe restituire un'altezza di `-1`. ```js assert( @@ -155,7 +155,7 @@ assert( ); ``` -The `isBalanced` method should return `false` if the tree is an unbalanced binary search tree. +Il metodo `isBalanced` dovrebbe restituire `false` se l'albero è un albero binario di ricerca sbilanciato. ```js assert( @@ -182,7 +182,7 @@ assert( ); ``` -The `isBalanced` method should return `true` if the tree is a balanced binary search tree. +Il metodo `isBalanced` dovrebbe restituire `true` se l'albero è un albero binario di ricerca equilibrato. ```js assert( diff --git a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/find-the-minimum-and-maximum-value-in-a-binary-search-tree.md b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/find-the-minimum-and-maximum-value-in-a-binary-search-tree.md index 23077f9d93..127b719edc 100644 --- a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/find-the-minimum-and-maximum-value-in-a-binary-search-tree.md +++ b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/find-the-minimum-and-maximum-value-in-a-binary-search-tree.md @@ -1,6 +1,6 @@ --- id: 587d8256367417b2b2512c7a -title: Find the Minimum and Maximum Value in a Binary Search Tree +title: Trovare i valori minimo e massimo di un albero binario di ricerca challengeType: 1 forumTopicId: 301642 dashedName: find-the-minimum-and-maximum-value-in-a-binary-search-tree @@ -8,11 +8,11 @@ dashedName: find-the-minimum-and-maximum-value-in-a-binary-search-tree # --description-- -In this challenge you will define two methods, `findMin` and `findMax`. These methods should return the minimum and maximum value held in the binary search tree (don't worry about adding values to the tree for now, we have added some in the background). If you get stuck, reflect on the invariant that must be true for binary search trees: each left subtree is less than or equal to its parent and each right subtree is greater than or equal to its parent. Let's also say that our tree can only store integer values. If the tree is empty, either method should return `null`. +In questa sfida definirai due metodi, `findMin` e `findMax`. Questi metodi dovrebbero restituire il valore minimo e massimo contenuto nell'albero binario di ricerca (non preoccuparti di aggiungere valori all'albero per ora, ne abbiamo aggiunti alcuni in background). Se si rimani bloccato, rifletti sull'invariante che deve essere vera per gli alberi di ricerca binari: ogni sottoalbero sinistro è inferiore o uguale al suo genitore e ogni sottoalbero destro è maggiore o uguale al suo genitore. Diciamo anche che il nostro albero può memorizzare solo valori interi. Se l'albero è vuoto, uno dei due metodi dovrebbe restituire `null`. # --hints-- -The `BinarySearchTree` data structure should exist. +La struttura di dati `BinarySearchTree` dovrebbe esistere. ```js assert( @@ -26,7 +26,7 @@ assert( ); ``` -The binary search tree should have a method called `findMin`. +L'albero binario di ricerca dovrebbe avere un metodo chiamato `findMin`. ```js assert( @@ -42,7 +42,7 @@ assert( ); ``` -The binary search tree should have a method called `findMax`. +L'albero di ricerca binario dovrebbe avere un metodo chiamato `findMax`. ```js assert( @@ -58,7 +58,7 @@ assert( ); ``` -The `findMin` method should return the minimum value in the binary search tree. +Il metodo `findMin` dovrebbe restituire il valore minimo nell'albero binario di ricerca. ```js assert( @@ -85,7 +85,7 @@ assert( ); ``` -The `findMax` method should return the maximum value in the binary search tree. +Il metodo `findMax` dovrebbe restituire il valore massimo nell'albero binario di ricerca. ```js assert( @@ -112,7 +112,7 @@ assert( ); ``` -The `findMin` and `findMax` methods should return `null` for an empty tree. +I metodi `findMin` e `findMax` dovrebbero restituire `null` per un albero vuoto. ```js assert( diff --git a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/implement-heap-sort-with-a-min-heap.md b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/implement-heap-sort-with-a-min-heap.md index 158817a64d..317d7da3ec 100644 --- a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/implement-heap-sort-with-a-min-heap.md +++ b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/implement-heap-sort-with-a-min-heap.md @@ -1,6 +1,6 @@ --- id: 587d825b367417b2b2512c8c -title: Implement Heap Sort with a Min Heap +title: Implementa un Heap Sort con un Min Heap challengeType: 1 forumTopicId: 301643 dashedName: implement-heap-sort-with-a-min-heap @@ -8,17 +8,17 @@ dashedName: implement-heap-sort-with-a-min-heap # --description-- -Now that we can add and remove elements let's see some of the applications heaps can be used for. Heaps are commonly used to implement priority queues because they always store an item of greatest or least value in first position. In addition, they are used to implement a sorting algorithm called heap sort. We'll see how to do this here. Heap sort uses a min heap, the reverse of a max heap. A min heap always stores the element of least value in the root position. +Ora che possiamo aggiungere e rimuovere elementi vediamo alcune applicazioni per cui gli heap possono essere usati. Gli heap sono comunemente usati per implementare file di priorità perché immagazzinano sempre un elemento di valore massimo o minimo nella prima posizione. In aggiunta, sono usati per implementare un algoritmo di ordinamento chiamato heap sort. Vedremo come farlo qui. Heap sort usa un min heap, l'opposto di un max heap. Un min heap ha sempre l'elemento di valore minore nella posizione root. -Heap sort works by taking an unsorted array, adding each item in the array into a min heap, and then extracting every item out of the min heap into a new array. The min heap structure ensures that the new array will contain the original items in least to greatest order. This is one of the most efficient sorting algorithms with average and worst case performance of O(nlog(n)). +Heap sort funziona prendendo un array non ordinato, aggiungendo ogni elemento dell'array in un min heap, e poi estraendo ogni elemento dal min heap in un array. La struttura min heap assicura che il nuovo array conterra gli elementi originali in ordine dal più piccolo al più grande. Questo è uno degli algoritmi per ordinare più efficienti con una performance media e nel peggiore dei casi di O(nlog(n)). # --instructions-- -Let's implement heap sort with a min heap. Feel free to adapt your max heap code here. Create an object `MinHeap` with `insert`, `remove`, and `sort` methods. The `sort` method should return an array of all the elements in the min heap sorted from smallest to largest. +Implementa un heap sort con un min heap. Adatta liberamente il codice del tuo max heap qui. Crea un oggetto `MinHeap` con metodi `insert`, `remove`, e `sort`. Il metodo `sort` dovrebbe restituire un array degli elementi nel min heap ordinati dal più piccolo al più grande. # --hints-- -The MinHeap data structure should exist. +La struttura dati MinHeap dovrebbe esistere. ```js assert( @@ -32,7 +32,7 @@ assert( ); ``` -MinHeap should have a method called insert. +MinHeap dovrebbe avere un metodo chiamato insert. ```js assert( @@ -48,7 +48,7 @@ assert( ); ``` -MinHeap should have a method called remove. +MinHeap dovrebbe avere un metodo chiamato remove. ```js assert( @@ -64,7 +64,7 @@ assert( ); ``` -MinHeap should have a method called sort. +MinHeap dovrebbe avere un metodo chiamato sort. ```js assert( @@ -80,7 +80,7 @@ assert( ); ``` -The sort method should return an array containing all items added to the min heap in sorted order. +Il metodo sort dovrebbe restituire un array che continuete tutto gli elementi aggiunti al min heap ordinati. ```js assert( diff --git a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/insert-an-element-into-a-max-heap.md b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/insert-an-element-into-a-max-heap.md index e20657a87c..ff09080e2a 100644 --- a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/insert-an-element-into-a-max-heap.md +++ b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/insert-an-element-into-a-max-heap.md @@ -1,6 +1,6 @@ --- id: 587d825a367417b2b2512c8a -title: Insert an Element into a Max Heap +title: Inserisci un elemento in un max heap challengeType: 1 forumTopicId: 301703 dashedName: insert-an-element-into-a-max-heap @@ -8,47 +8,47 @@ dashedName: insert-an-element-into-a-max-heap # --description-- -Now we will move on to another tree data structure, the binary heap. A binary heap is a partially ordered binary tree which satisfies the heap property. The heap property specifies a relationship between parent and child nodes. You may have a max heap, in which all parent nodes are greater than or equal to their child nodes, or a min heap, in which the reverse is true. Binary heaps are also complete binary trees. This means that all levels of the tree are fully filled and if the last level is partially filled it is filled from left to right. +Ora passeremo ad un'altra struttura di dati ad albero, l'heap binario. Un heap binario è un albero binario parzialmente ordinato che soddisfa la proprietà heap. La proprietà heap specifica una relazione tra nodi genitore e figlio. Potresti avere un max heap, in cui tutti i nodi genitori sono maggiori o uguali ai loro nodi figli, o un min heap, in cui il contrario è vero. Gli heap binari sono anche alberi binari completi. Questo significa che tutti i livelli dell'ablero sono completamente pieni e se l'ultimo livello è completo solo parzialmente è riempido da sinistra a destra. -While binary heaps may be implemented as tree structures with nodes that contain left and right references, the partial ordering according to the heap property allows us to represent the heap with an array. The parent-children relationship is what we're interested in and with simple arithmetic we can compute the children of any parent and the parent of any child node. +Anche se gli heap binari possono essere implementati come strutture ad albero con nodi che contengono riferimenti di sinistra e destra, l'ordine parziale in base alla proprietà heap ci permette di rappresentare l'heap con un array. Il rapporto genitore-figlio è quello a cui siamo interessati e con semplice aritmetica possiamo calcolare i figli di qualsiasi genitore e genitore di qualsiasi nodo figlio. -For instance, consider this array representation of a binary min heap: +Per esempio, considera questa rappresentazione array di un min heap binario: ```js [ 6, 22, 30, 37, 63, 48, 42, 76 ] ``` -The root node is the first element, `6`. Its children are `22` and `30`. If we look at the relationship between the array indices of these values, for index `i` the children are `2 * i + 1` and `2 * i + 2`. Similarly, the element at index `0` is the parent of these two children at indices `1` and `2`. More generally, we can find the parent of a node at any index with the following: `Math.floor((i - 1) / 2)`. These patterns will hold true as the binary tree grows to any size. Finally, we can make a slight adjustment to make this arithmetic even easier by skipping the first element in the array. Doing this creates the following relationship for any element at a given index `i`: +Il nodo radice è il primo elemento, `6`. I suoi figli sono `22` e `30`. Se consideriamo il rapporto tra gli indici di questi valori, per indice `i` i figli sono `2 * i + 1` e `2 * i + 2`. Analogamente, l'elemento all'indice `0` è il genitore di questi due figli agli indici `1` e `2`. Più in generale, possiamo trovare il genitore di un nodo in qualsiasi indice con il seguente: `Math.floor((i - 1) / 2)`. Questi pattern resteranno veri come l'albero cresce ad ogni dimensione. Infine, possiamo fare alcuni piccoli aggiustamenti per fare questa aritmetica ancora più semplice saltando il primo elemento dell'array. Facendo ciò si crea la seguente relazione per ogni elemento ad un dato indice `i`: -Example array representation: +Esempio di rappresentazione come array: ```js [ null, 6, 22, 30, 37, 63, 48, 42, 76 ] ``` -An element's left child: `i * 2` +Il figlio sinistro di un elemento: `i * 2` -An element's right child: `i * 2 + 1` +Il figlio destro di un elemento: `i * 2 + 1` -An element's parent: `Math.floor(i / 2)` +Il genitore di un elemento: `Math.floor(i / 2)` -Once you wrap your head around the math, using an array representation is very useful because node locations can be quickly determined with this arithmetic and memory usage is diminished because you don't need to maintain references to child nodes. +Una volta che prendi familiarità con la matematica, usare una rappresentazione ad array è molto utile perché la posizione dei nodi può essere determinata con questa artimetica e l'uso della memoria è diminuito perché non devi mantenere i riferimenti ai nodi figli. # --instructions-- -Instructions: Here we will create a max heap. Start by just creating an `insert` method which adds elements to our heap. During insertion, it is important to always maintain the heap property. For a max heap this means the root element should always have the greatest value in the tree and all parent nodes should be greater than their children. For an array implementation of a heap, this is typically accomplished in three steps: +Istruzioni: qui creeremo un max heap. Inizia creando semplicemente un metodo `insert` che aggiunge elementi al nostro heap. Durante l'inserzione, è importante mantenere sempre la proprietà heap. Per un max heap questo significa che l'elemento root deve sempre avere il valore maggiore nell'albero e tutti i nodi genitori devono essere più grandi dei loro figli. Per una rappresentazione ad array di un heap questo è tipicamente fatto in tre step:
    -
  1. Add the new element to the end of the array.
  2. -
  3. If the element is larger than its parent, switch them.
  4. -
  5. Continue switching until the new element is either smaller than its parent or you reach the root of the tree.
  6. +
  7. Aggiungi il nuovo elemento alla fine dell'array.
  8. +
  9. Se l'elemento è maggiore del suo genitore, scambiali.
  10. +
  11. Continua a scambiare finché il nuovo elemento è più piccolo del genitore o raggiungi l'elemento root.
-Finally, add a `print` method which returns an array of all the items that have been added to the heap. +Alla fine, aggiungi un metodo `print` che restituire un array di tutti gli elementi che sono stati aggiunti al heap. # --hints-- -The MaxHeap data structure should exist. +La struttura dati MaxHeap dovrebbe esistere. ```js assert( @@ -62,7 +62,7 @@ assert( ); ``` -MaxHeap should have a method called insert. +MaxHeap dovrebbe avere un metodo chiamato insert. ```js assert( @@ -78,7 +78,7 @@ assert( ); ``` -MaxHeap should have a method called print. +MaxHeap dovrebbe avere un metodo chiamato print. ```js assert( @@ -94,7 +94,7 @@ assert( ); ``` -The insert method should add elements according to the max heap property. +Il metodo insert dovrebbe aggiungere elementi rispettando la proprietà max heap. ```js assert( @@ -133,20 +133,28 @@ var MaxHeap = function() { ```js var MaxHeap = function() { // Only change code below this line - this.heap = [null]; - this.insert = (ele) => { - var index = this.heap.length; - var arr = [...this.heap]; - arr.push(ele); - while (ele > arr[Math.floor(index / 2)] && index > 1) { - arr[index] = arr[Math.floor(index / 2)]; - arr[Math.floor(index / 2)] = ele; - index = arr[Math.floor(index / 2)]; - } - this.heap = arr; + this.heap = []; + this.parent = index => { + return Math.floor((index - 1) / 2); + } + this.insert = element => { + this.heap.push(element); + this.heapifyUp(this.heap.length - 1); + } + this.heapifyUp = index => { + let currentIndex = index, + parentIndex = this.parent(currentIndex); + while (currentIndex > 0 && this.heap[currentIndex] > this.heap[parentIndex]) { + this.swap(currentIndex, parentIndex); + currentIndex = parentIndex; + parentIndex = this.parent(parentIndex); + } + } + this.swap = (index1, index2) => { + [this.heap[index1], this.heap[index2]] = [this.heap[index2], this.heap[index1]]; } this.print = () => { - return this.heap.slice(1); + return this.heap; } // Only change code above this line }; diff --git a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/invert-a-binary-tree.md b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/invert-a-binary-tree.md index 8be38b0d5d..aa8f95560e 100644 --- a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/invert-a-binary-tree.md +++ b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/invert-a-binary-tree.md @@ -1,6 +1,6 @@ --- id: 587d8259367417b2b2512c83 -title: Invert a Binary Tree +title: Invertire un albero binario challengeType: 1 forumTopicId: 301704 dashedName: invert-a-binary-tree @@ -8,11 +8,11 @@ dashedName: invert-a-binary-tree # --description-- -Here will we create a function to invert a binary tree. Given a binary tree, we want to produce a new tree that is equivalently the mirror image of this tree. Running an inorder traversal on an inverted tree will explore the nodes in reverse order when compared to the inorder traversal of the original tree. Write a method to do this called `invert` on our binary tree. Calling this method should invert the current tree structure. Ideally, we would like to do this in-place in linear time. That is, we only visit each node once and we modify the existing tree structure as we go, without using any additional memory. Good luck! +Qui creeremo una funzione per invertire un albero binario. Dato un albero binario, vogliamo produrre un nuovo albero che sia equivalente all'immagine speculare di questo albero. Eseguire un traversamento inorder su un albero invertito esplora i nodi in ordine inverso rispetto a un traversamento inorder sull'albero originale. Scrivi un metodo per farlo, chiamato `invert` sul nostro albero binario. Chiamare questo metodo dovrebbe invertire la struttura attuale dell'albero. Idealmente, vorremmo fare questo "in-place" (NdT: lavorando sull'array originale, senza crearne una copia) e in tempo lineare. Cioè, visitiamo ogni nodo solo una volta e modifichiamo la struttura di albero esistente mentre procediamo, senza usare memoria aggiuntiva. Buona fortuna! # --hints-- -The `BinarySearchTree` data structure should exist. +La struttura di dati `BinarySearchTree` dovrebbe esistere. ```js assert( @@ -26,7 +26,7 @@ assert( ); ``` -The binary search tree should have a method called `invert`. +L'albero binario di ricerca dovrebbe avere un metodo chiamato `invert`. ```js assert( @@ -42,7 +42,7 @@ assert( ); ``` -The `invert` method should correctly invert the tree structure. +Il metodo `invert` dovrebbe invertire correttamente la struttura dell'albero. ```js assert( @@ -70,7 +70,7 @@ assert( ); ``` -Inverting an empty tree should return `null`. +Invertire un albero vuoto dovrebbe restituire `null`. ```js assert( diff --git a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/remove-an-element-from-a-max-heap.md b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/remove-an-element-from-a-max-heap.md index 858073f211..cff5e8f7a8 100644 --- a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/remove-an-element-from-a-max-heap.md +++ b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/remove-an-element-from-a-max-heap.md @@ -1,6 +1,6 @@ --- id: 587d825b367417b2b2512c8b -title: Remove an Element from a Max Heap +title: Rimuovere un elemento da una max-heap challengeType: 1 forumTopicId: 301710 dashedName: remove-an-element-from-a-max-heap @@ -8,21 +8,21 @@ dashedName: remove-an-element-from-a-max-heap # --description-- -Now that we can add elements to our heap let's see how we can remove elements. Removing and inserting elements both require similar logic. In a max heap you will usually want to remove the greatest value, so this involves simply extracting it from the root of our tree. This will break the heap property of our tree, so we must reestablish it in some way. Typically, for a max heap this is done in the following way: +Ora che possiamo aggiungere elementi al nostro heap vediamo come possiamo rimuovere gli elementi. La rimozione e l'inserimento di elementi richiedono una logica simile. In un max-heap di solito si vuole rimuovere il valore maggiore, quindi questo implica semplicemente estrarlo dalla radice del nostro albero. Questo negherà la proprietà heap del nostro albero, quindi dovremo ristabilirla in qualche modo. Tipicamente, per un max-heap questo viene fatto nel modo seguente:
    -
  1. Move the last element in the heap into the root position.
  2. -
  3. If either child of the root is greater than it, swap the root with the child of greater value.
  4. -
  5. Continue swapping until the parent is greater than both children or you reach the last level in the tree.
  6. +
  7. Sposta l'ultimo elemento nell'heap alla posizione root.
  8. +
  9. Se uno dei figli della radice è maggiore di essa, scambiare la radice con il figlio di valore maggiore.
  10. +
  11. Continuare a scambiare fino a quando il genitore è maggiore di entrambi i figli o si raggiunge l'ultimo livello nell'albero.
# --instructions-- -Instructions: Add a method to our max heap called `remove`. This method should return the greatest value that has been added to our max heap and remove it from the heap. It should also reorder the heap so the heap property is maintained. After removing an element, the next greatest element remaining in the heap should become the root. +Istruzioni: Aggiungere un metodo al nostro max-heap chiamato `remove`. Questo metodo dovrebbe restituire il massimo valore che è stato aggiunto al nostro max heap e rimuoverlo dal mucchio. Dovrebbe anche riordinare il mucchio in modo che la proprietà heap sia mantenuta. Dopo aver rimosso un elemento, il prossimo elemento più grande che rimane nel heap dovrebbe diventare la radice. # --hints-- -The MaxHeap data structure should exist. +La struttura dati MaxHeap dovrebbe esistere. ```js assert( @@ -36,7 +36,7 @@ assert( ); ``` -MaxHeap should have a method called print. +MaxHeap dovrebbe avere un metodo chiamato print. ```js assert( @@ -52,7 +52,7 @@ assert( ); ``` -MaxHeap should have a method called insert. +MaxHeap dovrebbe avere un metodo chiamato insert. ```js assert( @@ -68,7 +68,7 @@ assert( ); ``` -MaxHeap should have a method called remove. +MaxHeap dovrebbe avere un metodo chiamato remove. ```js assert( @@ -84,7 +84,7 @@ assert( ); ``` -The remove method should remove the greatest element from the max heap while maintaining the max heap property. +Il metodo remove dovrebbe rimuovere l'elemento più grande dal max heap mantenendo la proprietà max heap. ```js assert( @@ -114,21 +114,29 @@ assert( ## --seed-contents-- ```js -var MaxHeap = function() { - this.heap = [null]; - this.insert = (ele) => { - var index = this.heap.length; - var arr = [...this.heap]; - arr.push(ele); - while (ele > arr[Math.floor(index / 2)] && index > 1) { - arr[index] = arr[Math.floor(index / 2)]; - arr[Math.floor(index / 2)] = ele; - index = arr[Math.floor(index / 2)]; +var MaxHeap = function () { + this.heap = []; + this.parent = index => { + return Math.floor((index - 1) / 2); + } + this.insert = element => { + this.heap.push(element); + this.heapifyUp(this.heap.length - 1); + } + this.heapifyUp = index => { + let currentIndex = index, + parentIndex = this.parent(currentIndex); + while (currentIndex > 0 && this.heap[currentIndex] > this.heap[parentIndex]) { + this.swap(currentIndex, parentIndex); + currentIndex = parentIndex; + parentIndex = this.parent(parentIndex); } - this.heap = arr; + } + this.swap = (index1, index2) => { + [this.heap[index1], this.heap[index2]] = [this.heap[index2], this.heap[index1]]; } this.print = () => { - return this.heap.slice(1); + return this.heap; } // Only change code below this line diff --git a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/remove-elements-from-a-linked-list-by-index.md b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/remove-elements-from-a-linked-list-by-index.md index 9a8e59f77f..7c17dd9917 100644 --- a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/remove-elements-from-a-linked-list-by-index.md +++ b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/remove-elements-from-a-linked-list-by-index.md @@ -1,6 +1,6 @@ --- id: 587d8251367417b2b2512c65 -title: Remove Elements from a Linked List by Index +title: Rimuovere gli elementi da una lista concatenata usando l'indice challengeType: 1 forumTopicId: 301711 dashedName: remove-elements-from-a-linked-list-by-index @@ -8,23 +8,23 @@ dashedName: remove-elements-from-a-linked-list-by-index # --description-- -Before we move on to another data structure, let's get a couple of last bits of practice with linked lists. +Prima di passare ad un'altra struttura di dati, otteniamo un altro po' di pratica con liste concatenate. -Let's write a `removeAt` method that removes the `element` at a given `index`. The method should be called `removeAt(index)`. To remove an `element` at a certain `index`, we'll need to keep a running count of each node as we move along the linked list. +Scriviamo un metodo `removeAt` che rimuove l'elemento `element` in un dato `index`. Il metodo dovrebbe essere chiamato `removeAt(index)`. Per rimuovere un `element` a un certo `index`, avremo bisogno di mantenere un conteggio in esecuzione di ogni nodo mentre ci muoviamo lungo la lista concatenata. -A common technique used to iterate through the elements of a linked list involves a 'runner', or sentinel, that 'points' at the nodes that your code is comparing. In our case, starting at the `head` of our list, we start with a `currentIndex` variable that starts at `0`. The `currentIndex` should increment by one for each node we pass. +Una tecnica comune utilizzata per iterare attraverso gli elementi di una lista concatenata comporta un 'runner', o sentinella, che 'punti' ai nodi che il tuo codice sta confrontando. Nel nostro caso, a partire dalla `head` della nostra lista, iniziamo con una variabile `currentIndex` che inizia da `0`. Il `currentIndex` dovrebbe aumentare di uno per ogni nodo che passiamo. -Just like our `remove(element)` method, which [we covered in a previous lesson](/learn/coding-interview-prep/data-structures/remove-elements-from-a-linked-list), we need to be careful not to orphan the rest of our list when we remove the node in our `removeAt(index)` method. We keep our nodes contiguous by making sure that the node that has reference to the removed node has a reference to the next node. +Proprio come il nostro metodo `remove(element)`, che [abbiamo coperto in una lezione precedente](/italian/learn/coding-interview-prep/data-structures/remove-elements-from-a-linked-list), dobbiamo stare attenti a non rendere orfano il resto della nostra lista quando rimuoviamo il nodo nel nostro metodo `removeAt(index)`. Manteniamo i nostri nodi contigui assicurandoci che il nodo che fa riferimento al nodo rimosso abbia un riferimento al nodo successivo. # --instructions-- -Write a `removeAt(index)` method that removes and returns a node at a given `index`. The method should return `null` if the given `index` is either negative, or greater than or equal to the `length` of the linked list. +Scrivi un metodo `removeAt(index)` che rimuove e restituisce un nodo a un certo `index`. Il metodo dovrebbe restituire `null` se l'`index` dato è o negativo, o superiore o uguale alla `length` della lista concatenata. -**Note:** Remember to keep count of the `currentIndex`. +**Nota:** Ricordati di mantenere il conteggio del `currentIndex`. # --hints-- -Your `LinkedList` class should have a `removeAt` method. +La tua classe `LinkedList` dovrebbe avere un metodo `removeAt`. ```js assert( @@ -35,7 +35,7 @@ assert( ); ``` -Your `removeAt` method should reduce the `length` of the linked list by one. +Il tuo metodo `removeAt` dovrebbe ridurre `length` della lista collegata di uno. ```js assert( @@ -50,7 +50,7 @@ assert( ); ``` -Your `removeAt` method should remove the element at the specified index from the linked list. +Il tuo metodo `removeAt` dovrebbe rimuovere l'elemento all'indice specificato dalla lista collegata. ```js assert( @@ -69,7 +69,7 @@ assert( ); ``` -When only one element is present in the linked list, your `removeAt` method should remove and return the element at specified index, and reduce the length of the linked list. +Quando un solo elemento è presente nell'elenco collegato, il tuo metodo `removeAt` dovrebbe rimuovere e restituire l'elemento all'indice specificato e ridurre la lunghezza della lista concatenata. ```js assert( @@ -82,7 +82,7 @@ assert( ); ``` -Your `removeAt` method should return the element of the removed node. +Il metodo `removeAt` dovrebbe restituire l'elemento del nodo rimosso. ```js assert( @@ -96,7 +96,7 @@ assert( ); ``` -Your `removeAt` method should return `null` and the linked list should not change if the given index is less than `0`. +Il tuo metodo `removeAt` dovrebbe restituire `null` e la lista concatenata non dovrebbe cambiare se l'indice dato è inferiore a `0`. ```js assert( @@ -115,7 +115,7 @@ assert( ); ``` -Your `removeAt` method should return `null` and the linked list should not change if the given index is greater than or equal to the `length` of the list. +Il tuo metodo `removeAt` dovrebbe restituire `null` e la lista concatenata non dovrebbe cambiare se l'indice dato è maggiore o uguale a `length` dell'elenco. ```js assert( diff --git a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/remove-elements-from-a-linked-list.md b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/remove-elements-from-a-linked-list.md index a202036ff0..af03773649 100644 --- a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/remove-elements-from-a-linked-list.md +++ b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/remove-elements-from-a-linked-list.md @@ -1,6 +1,6 @@ --- id: 587d8251367417b2b2512c63 -title: Remove Elements from a Linked List +title: Rimuovi gli elementi da una lista concatenata challengeType: 1 forumTopicId: 301712 dashedName: remove-elements-from-a-linked-list @@ -8,23 +8,23 @@ dashedName: remove-elements-from-a-linked-list # --description-- -The next important method that any implementation of a linked list will need is a `remove` method. This method should take the element we want to remove as an argument, and then search the list to find and remove the node that contains that element. +Il metodo successivo importante che ogni implementazione di una lista concatenata avrà bisogno è un metodo `remove`. Questo metodo dovrebbe prendere l'elemento che vogliamo rimuovere come un argomento, e quindi cercare l'elenco per trovare e rimuovere il nodo che contiene quell'elemento. -Whenever we remove a node from a linked list, it's important that we don't accidentally orphan the rest of the list in doing so. Recall that every node's `next` property points to the node that follows it in the list. If we're removing the middle element, say, we'll want to make sure that we have a connection from that element's previous node's `next` property to the middle element's `next` property (which is the next node in the list!) +Ogni volta che rimuovi un nodo da una lista collegata, è importante che non orfani accidentalmente il resto della lista nel farlo. Ricorda che la proprietà `next` di ogni nodo punta al nodo che lo segue nella lista. Se stiamo rimuovendo l'elemento di mezzo, vogliamo fare in modo che c'è una connessione tra la proprietà `next` dell'elemento precedente e la proprietà `next` dell'elemento di mezzo (che è il nodo seguente nella lista!) -This might sound really confusing, so let's return to the conga line example so we have a good conceptual model. Picture yourself in a conga line, and the person directly in front of you leaves the line. The person who just left the line no longer has her hands on anyone in line--and you no longer have your hands on the person that left. You step forward and put your hands on next person you see. +Questo può essere davvero confusionario, quindi ritornaimo all'esempio del trenino così abbiamo un buon modello concettuale. Immaginati in un trenino, e la persona direttamente davanti a te lascia la fila. La persona che ha appena lasciato la fina non ha più le mani sulle spalle di nessuno, e tu non hai più le mani sulle spalle della persona che se ne è andata. Fai un passo avanti e metti le mani sulle spalle della persona davanti a te. -If the element we wish to remove is the `head` element, we reassign the `head` to the second node of the linked list. +Se l'elemento che vogliamo rimuovere è l'elemento `head`, assegniamo `head` al secondo nodo della lista concatenata. # --instructions-- -Write a `remove` method that takes an element and removes it from the linked list. +Scrivi un metodo `remove` che prende un elemento e lo rimuove dalla lista collegata. -**Note:** The `length` of the list should decrease by one every time an element is removed from the linked list. +**Nota:** La lunghezza della lista dovrebbe diminuire di uno ogni volta che un elemento viene rimosso dalla lista collegata. # --hints-- -Your `LinkedList` class should have a `remove` method. +La tua classe `LinkedList` dovrebbe avere un metodo `remove`. ```js assert( @@ -35,7 +35,7 @@ assert( ); ``` -Your `remove` method should reassign `head` to the second node when the first node is removed. +Il tuo metodo `remove` dovrebbe riassegnare `head` al secondo nodo quando il primo nodo è rimosso. ```js assert( @@ -49,7 +49,7 @@ assert( ); ``` -Your `remove` method should decrease the `length` of the linked list by one for every node removed. +Il tuo metodo `remove` dovrebbe diminuire `length` della lista concatenata di uno per ogni nodo rimosso. ```js assert( @@ -65,7 +65,7 @@ assert( ); ``` -Your `remove` method should reassign the reference of the previous node of the removed node to the removed node's `next` reference. +Il tuo metodo `remove` dovrebbe riassegnara il riferimento del nodo precedente del nodo rimosso al rifermento `next` del nodo rimosso. ```js assert( @@ -81,7 +81,7 @@ assert( ); ``` -Your `remove` method should not change the linked list if the element does not exist in the linked list. +Il tuo metodo `remove` non dovrebbe cambiare la lista concatenata se l'elemento non esiste nella lista concatenata. ```js assert( diff --git a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/search-within-a-linked-list.md b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/search-within-a-linked-list.md index 03361689fe..e17f29b048 100644 --- a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/search-within-a-linked-list.md +++ b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/search-within-a-linked-list.md @@ -1,6 +1,6 @@ --- id: 587d8251367417b2b2512c64 -title: Search within a Linked List +title: Cercare in una lista concatenata challengeType: 1 forumTopicId: 301715 dashedName: search-within-a-linked-list @@ -8,19 +8,19 @@ dashedName: search-within-a-linked-list # --description-- -Let's add a few more useful methods to our linked list class. Wouldn't it be useful if we could tell if our list was empty or not, as with our `Stack` and `Queue` classes? +Aggiungiamo alcuni altri metodi utili alla nostra classe di lista concatenata. Non sarebbe utile se potessimo dire se la nostra lista sia vuota o no, come con le nostre classi `Stack` e `Queue`? -We should also be able to find specific elements in our linked list. Traversing through data structures is something you'll want to get a lot of practice with! Let's create an `indexOf` method that takes an `element` as an argument, and returns that element's `index` in the linked list. If the element is not found in the linked list, return `-1`. +Dovremmo anche essere in grado di trovare elementi specifici nella nostra lista concatenata. Traversare strutture di dati è qualcosa con cui vorrai fare un sacco di pratica! Creiamo un metodo `indexOf` che prende `element` coem argomento, e restituisce l'`index` di quell'elemento nella lista concatenata. Se l'elemento non è trovato nella lista collegata, restituisci `-1`. -Let's also implement a method that does the opposite: an `elementAt` method that takes an `index` as an argument and returns the `element` at the given `index`. If no `element` is found, return `undefined`. +Implementiamo pure un metodo che fa l'opposto: un metodo `elementAt` che accetta un `index` come argomento e restituisce `element` al dato `index`. Se nessun elemento `element` è trovato, restituisci `undefined`. # --instructions-- -Write an `isEmpty` method that checks if the linked list is empty, an `indexOf` method that returns the `index` of a given element, and an `elementAt` that returns an `element` at a given `index.` +Scrivi un metodo `isEmpty` che verifica se la lista concatenata è vuota, un metodo `indexOf` che restituisce l'`index` di un dato elemento, e un metodo `elementAt` che restituisce l'`element` al dato `index.` # --hints-- -Your `LinkedList` class should have an `isEmpty` method. +La tua classe `LinkedList` dovrebbe avere un metodo `isEmpty`. ```js assert( @@ -31,7 +31,7 @@ assert( ); ``` -Your `isEmpty` method should return `false` when there is at least one element in linked list. +Il tuo metodo `isEmpty` dovrebbe restituire `false` quando c'è almeno un elemento nella lista concatenata. ```js assert( @@ -45,7 +45,7 @@ assert( ); ``` -Your `isEmpty` method should return `true` when there are no elements in linked list. +Il tuo metodo `isEmpty` dovrebbe restituire `true` quando non ci sono elementi nella lista concatenata. ```js assert( @@ -56,7 +56,7 @@ assert( ); ``` -Your `LinkedList` class should have an `indexOf` method. +La tua classe `LinkedList` dovrebbe avere un metodo `indexOf`. ```js assert( @@ -67,7 +67,7 @@ assert( ); ``` -Your `indexOf` method should return the index of a given element found in linked list. +Il tuo metodo `indexOf` dovrebbe restituire l'indice di un dato elemento trovato nella lista concatenata. ```js assert( @@ -81,7 +81,7 @@ assert( ); ``` -Your `indexOf` method should return `-1` if the given element is not found in linked list +Il tuo metodo `indexOf` dovrebbe restituire `-1` se l'elemento dato non è trovato nella lista concatenata ```js assert( @@ -95,7 +95,7 @@ assert( ); ``` -Your `LinkedList` class should have an `elementAt` method. +La tua classe `LinkedList` dovrebbe avere un metodo `elementAt`. ```js assert( @@ -106,7 +106,7 @@ assert( ); ``` -Your `elementAt` method should return the element found at a given index in linked list. +Il tuo metodo `elementAt` dovrebbe restituire l'elemento trovato in un dato indice nella lista concatenata. ```js assert( @@ -120,7 +120,7 @@ assert( ); ``` -Your `elementAt` method should return `undefined` if the given element is not found at a given index in linked list. +Il tuo `elementAt` metodo dovrebbe restituire `undefined` se l'elemento dato non è trovato in un dato indice nella lista concatenata. ```js assert( diff --git a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/typed-arrays.md b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/typed-arrays.md index b992af729a..23a3b80b1d 100644 --- a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/typed-arrays.md +++ b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/typed-arrays.md @@ -1,6 +1,6 @@ --- id: 587d8253367417b2b2512c6a -title: Typed Arrays +title: Array Digitati challengeType: 1 forumTopicId: 301716 dashedName: typed-arrays @@ -8,21 +8,21 @@ dashedName: typed-arrays # --description-- -Arrays are JavaScript objects that can hold a lot of different elements. +Gli array sono oggetti JavaScript che possono contenere molti elementi diversi. ```js var complexArr = [1, 5, "2", "Word", {"name": "James"}]; ``` -Basically what happens in the background is that your browser will automatically give the right amount of memory space for that array. It will also change as needed if you add or remove data. +Fondamentalmente ciò che accade in background è che il browser darà automaticamente la giusta quantità di spazio di memoria per quell'array. Cambierà anche al bisogno se si aggiungono o rimuovono i dati. -However, in the world of high performance and different element types, sometimes you need to be more specific on how much memory is given to an array. +Tuttavia, nel mondo delle alte prestazioni e dei diversi tipi di elementi, a volte è necessario essere più specifici su quanto memoria viene dato a un array. -Typed arrays are the answer to this problem. You are now able to say how much memory you want to give an array. Below is a basic overview of the different types of arrays available and the size in bytes for each element in that array. +Gli array digitati sono la risposta a questo problema. Ora sei in grado di dire quanta memoria vuoi allocare per un dato array. Di seguito una panoramica di base dei diversi tipi di array disponibili e la dimensione in byte per ogni elemento in quell'array. -
TypeEach element size in bytes
Int8Array1
Uint8Array1
Uint8ClampedArray1
Int16Array2
Uint16Array2
Int32Array4
Uint32Array4
Float32Array4
Float64Array8
+
TipoLa dimensione di ogni elemento in byte
Int8Array1
Uint8Array1
Uint8ClampedArray1
Int16Array2
Uint16Array2
Int32Array4
Uint32Array4
Float32Array4
Float64Array8
-There are two ways in creating these kind of arrays. One way is to create it directly. Below is how to create a 3 length `Int16Array`. +Ci sono due modi per creare questi tipi di array. Un modo è di crearli direttamente. Di seguito è riportato come creare un `Int16Array` di lunghezza 3. ```js var i8 = new Int16Array(3); @@ -30,8 +30,8 @@ console.log(i8); // Returns [0, 0, 0] ``` -You can also create a buffer to assign how much data (in bytes) you want the array to take up. **Note** -To create typed arrays using buffers, you need to assign the number of bytes to be a multiple of the bytes listed above. +Puoi ache creare un buffer per assegnare quanti dati (in byte) vuoi che il tuo array occupi. **Nota** +Per creare array digitat usando buffer, devi assegnare il numero di byte come multiple dei byte elencati precedentemente. ```js // Create same Int16Array array differently @@ -43,35 +43,35 @@ i8View.byteLength; // Returns 6 console.log(i8View); // Returns [0, 0, 0] ``` -Buffers are general purpose objects that just carry data. You cannot access them normally. To access them, you need to first create a view. +I buffer sono oggetti a scopo generico che contengono solo dati. Non puoi accedervi normalmente. Per accederci devi prima creare una view. ```js i8View[0] = 42; console.log(i8View); // Returns [42, 0, 0] ``` -**Note** -Typed arrays do not have some of the methods traditional arrays have such as `.pop()` or `.push()`. Typed arrays also fail `Array.isArray()` that checks if something is an array. Although simpler, this can be an advantage for less-sophisticated JavaScript engines to implement them. +**Nota** +Array digitati non hanno alcuni dei metodi degli array tradizioni come `.pop()` o `.push()`. Gli array digitati fanno restituire false ad `Array.isArray()` che controlla se qualcosa è un array. Anche se più semplice, questo può essere un vantaggio per i motori JavaScript meno sofisticati per implementarli. # --instructions-- -First create a `buffer` that is 64-bytes. Then create a `Int32Array` typed array with a view of it called `i32View`. +Come prima cosa crea un `buffer` che è 64 byte. Quindi crea un array digitato `Int32Array` con una view chiamata `i32View`. # --hints-- -Your `buffer` should be 64 bytes large. +Il tuo `buffer` dovrebbe occupare 64 byte. ```js assert(buffer.byteLength === 64); ``` -Your `i32View` view of your buffer should be 64 bytes large. +La tua view `i32View` del tuo buffer dovrebbe occupare 64 byte. ```js assert(i32View.byteLength === 64); ``` -Your `i32View` view of your buffer should be 16 elements long. +La tua view `i32View` del tuo buffer dovrebbe avere 16 elementi. ```js assert(i32View.length === 16); diff --git a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/use-.has-and-.size-on-an-es6-set.md b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/use-.has-and-.size-on-an-es6-set.md index 55d4ac67de..de0ebdcc95 100644 --- a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/use-.has-and-.size-on-an-es6-set.md +++ b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/use-.has-and-.size-on-an-es6-set.md @@ -1,6 +1,6 @@ --- id: 587d8255367417b2b2512c72 -title: Use .has and .size on an ES6 Set +title: Usare .has e .size su un set ES6 challengeType: 1 forumTopicId: 301717 dashedName: use--has-and--size-on-an-es6-set @@ -8,21 +8,21 @@ dashedName: use--has-and--size-on-an-es6-set # --description-- -Let's look at the .has and .size methods available on the ES6 Set object. +Diamo un'occhiata ai metodi .has e .size disponibili sull'oggetto Set ES6. -First, create an ES6 Set +Per prima cosa, crea un Set ES6 ```js var set = new Set([1,2,3]); ``` -The .has method will check if the value is contained within the set. +Il metodo .has controllerà se il valore è contenuto all'interno del set. ```js var hasTwo = set.has(2); ``` -The .size method will return an integer representing the size of the Set +Il metodo .size restituirà un numero intero rappresentante la dimensione del Set ```js var howBig = set.size; @@ -30,11 +30,11 @@ var howBig = set.size; # --instructions-- -In this exercise we will pass an array and a value to the checkSet() function. Your function should create an ES6 set from the array argument. Find if the set contains the value argument. Find the size of the set. And return those two values in an array. +In questo esercizio passeremo un array e un valore alla funzione checkSet(). La tua funzione dovrebbe creare un set ES& dall'argomento array. Scopri se il set contiene il valore argomento. Trova la dimensione del set. E restituire questi due valori in un array. # --hints-- -`checkSet([4, 5, 6], 3)` should return [ false, 3 ] +`checkSet([4, 5, 6], 3)` dovrebbe restituire [ false, 3 ] ```js assert( diff --git a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/use-breadth-first-search-in-a-binary-search-tree.md b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/use-breadth-first-search-in-a-binary-search-tree.md index b02f10043d..74b6bdd7ee 100644 --- a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/use-breadth-first-search-in-a-binary-search-tree.md +++ b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/use-breadth-first-search-in-a-binary-search-tree.md @@ -1,6 +1,6 @@ --- id: 587d8258367417b2b2512c7f -title: Use Breadth First Search in a Binary Search Tree +title: Una la ricerca in ampiezza nella ricerca binaria in un albero challengeType: 1 forumTopicId: 301718 dashedName: use-breadth-first-search-in-a-binary-search-tree @@ -8,17 +8,17 @@ dashedName: use-breadth-first-search-in-a-binary-search-tree # --description-- -Here we will introduce another tree traversal method: breadth-first search. In contrast to the depth-first search methods from the last challenge, breadth-first search explores all the nodes in a given level within a tree before continuing on to the next level. Typically, queues are utilized as helper data structures in the design of breadth-first search algorithms. +Qui introdurremo un altro metodo traversale di albero: la ricerca in ampiezza. In contrasto con il metodo di ricerca in profondità dell'ultima sfida, La ricerca in ampiezza esplora tutti i nodi in un dato livello all'interno di un albero prima di continuare al livello successivo. Tipicamente, le code sono utilizzate come strutture di dati helper nella progettazione di algoritmi di ricerca in ampiezza. -In this method, we start by adding the root node to a queue. Then we begin a loop where we dequeue the first item in the queue, add it to a new array, and then inspect both its child subtrees. If its children are not null, they are each enqueued. This process continues until the queue is empty. +In questo metodo, iniziamo aggiungendo il nodo radice alla coda. Poi iniziamo un ciclo in cui decodiamo il primo elemento nella coda, aggiungerlo a un nuovo array, e quindi ispezionare entrambi i suoi sottalberi. Se i suoi figli non sono nulli, sono ciascuno messo in coda. Questo processo continua fino a quando la coda non è vuota. # --instructions-- -Let's create a breadth-first search method in our tree called `levelOrder`. This method should return an array containing the values of all the tree nodes, explored in a breadth-first manner. Be sure to return the values in the array, not the nodes themselves. A level should be traversed from left to right. Next, let's write a similar method called `reverseLevelOrder` which performs the same search but in the reverse direction (right to left) at each level. +Creiamo un metodo di ricerca in ampiezza nel nostro albero chiamato `levelOrder`. Questo metodo dovrebbe restituire un array contenente i valori di tutti i nodi degli alberi, esplorati con la ricerca in ampiezza. Assicurati di restituire i valori nell'array, non i nodi stessi. Un livello dovrebbe essere attraversato da sinistra a destra. Poi scriviamo un metodo simile chiamato `reverseLevelOrder` che esegue la stessa ricerca ma nella direzione inversa (da destra a sinistra) ad ogni livello. # --hints-- -The `BinarySearchTree` data structure should exist. +La struttura di dati `BinarySearchTree` dovrebbe esistere. ```js assert( @@ -32,7 +32,7 @@ assert( ); ``` -The binary search tree should have a method called `levelOrder`. +L'albero di ricerca binario dovrebbe avere un metodo chiamato `levelOrder`. ```js assert( @@ -48,7 +48,7 @@ assert( ); ``` -The binary search tree should have a method called `reverseLevelOrder`. +L'albero di ricerca binario dovrebbe avere un metodo chiamato `reverseLevelOrder`. ```js assert( @@ -64,7 +64,7 @@ assert( ); ``` -The `levelOrder` method should return an array of the tree node values explored in level order. +Il metodo `levelOrder` dovrebbe restituire un array dei valori del nodo albero esplorati in ordine di livello. ```js assert( @@ -94,7 +94,7 @@ assert( ); ``` -The `reverseLevelOrder` method should return an array of the tree node values explored in reverse level order. +Il metodo `reverseLevelOrder` dovrebbe restituire un array dei valori del nodo albero esplorati in ordine di livello inverso. ```js assert( @@ -124,7 +124,7 @@ assert( ); ``` -The `levelOrder` method should return `null` for an empty tree. +Il metodo `levelOrder` dovrebbe restituire `null` per un albero vuoto. ```js assert( @@ -143,7 +143,7 @@ assert( ); ``` -The `reverseLevelOrder` method should return `null` for an empty tree. +Il metodo `reverseLevelOrder` dovrebbe restituire `null` per un albero vuoto. ```js assert( diff --git a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/use-depth-first-search-in-a-binary-search-tree.md b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/use-depth-first-search-in-a-binary-search-tree.md index c03fb75077..10ac9046c9 100644 --- a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/use-depth-first-search-in-a-binary-search-tree.md +++ b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/use-depth-first-search-in-a-binary-search-tree.md @@ -1,6 +1,6 @@ --- id: 587d8257367417b2b2512c7e -title: Use Depth First Search in a Binary Search Tree +title: Usa la ricerca in profondità in un alvero di ricerca binario challengeType: 1 forumTopicId: 301719 dashedName: use-depth-first-search-in-a-binary-search-tree @@ -8,15 +8,15 @@ dashedName: use-depth-first-search-in-a-binary-search-tree # --description-- -We know how to search a binary search tree for a specific value. But what if we just want to explore the entire tree? Or what if we don't have an ordered tree and we need to just search for a value? Here we will introduce some tree traversal methods which can be used to explore tree data structures. First up is depth-first search. In depth-first search, a given subtree is explored as deeply as possible before the search continues on to another subtree. There are three ways this can be done: In-order: Begin the search at the left-most node and end at the right-most node. Pre-order: Explore all the roots before the leaves. Post-order: Explore all the leaves before the roots. As you may guess, you may choose different search methods depending on what type of data your tree is storing and what you are looking for. For a binary search tree, an inorder traversal returns the nodes in sorted order. +Sappiamo come cercare un albero di ricerca binario per un valore specifico. Ma cosa succede se vogliamo solo esplorare l'intero albero? O cosa succede se non abbiamo un albero ordinato e dobbiamo solo cercare un valore? Qui introdurremo alcuni metodi di per traversare l'alvero che possono essere utilizzati per esplorare strutture dati ad albero. Il primo è la prima ricerca in profondità. Nella ricerca in profondità, un dato sotto-albero è esplorato il più profondamente possibile prima che la ricerca continui su un altro sotto-albero. Ci sono tre modi per farlo: In ordine: Iniziare la ricerca al nodo più a sinistra e terminare al nodo più a destra. Pre-ordine: Esplora tutte le radici prima delle foglie. Post-order: Esplora tutte le foglie prima delle radici. Come si può immaginare, è possibile scegliere diversi metodi di ricerca a seconda del tipo di dati che l'albero sta memorizzando e quello che stai cercando. Per un albero di ricerca binario, un attraversamento in ordine restituisce i nodi ordinati. # --instructions-- -Here we will create these three search methods on our binary search tree. Depth-first search is an inherently recursive operation which continues to explore further subtrees so long as child nodes are present. Once you understand this basic concept, you can simply rearrange the order in which you explore the nodes and subtrees to produce any of the three searches above. For example, in post-order search we would want to recurse all the way to a leaf node before we begin to return any of the nodes themselves, whereas in pre-order search we would want to return the nodes first, and then continue recursing down the tree. Define `inorder`, `preorder`, and `postorder` methods on our tree. Each of these methods should return an array of items which represent the tree traversal. Be sure to return the integer values at each node in the array, not the nodes themselves. Finally, return `null` if the tree is empty. +Qui creeremo questi tre metodi di ricerca sul nostro albero di ricerca binario. La ricerca di profondità prima è un'operazione intrinsecamente ricorsiva che continua ad esplorare ulteriori sottalberi, a condizione che siano presenti nodi figli. Una volta che capisci questo concetto fondamentale, si può semplicemente riorganizzare l'ordine in cui si esplorano i nodi e sotto-alberi per produrre una delle tre ricerche sopra. Ad esempio, nella ricerca post-ordine vorremmo arrivare ad un nodo foglia prima di iniziare a restituire uno dei nodi stessi, mentre in pre-ordine di ricerca vorremmo restituire i nodi prima, e poi continuare a ricorsare giù l'albero. Definisci i metodi `inorder`, `preorder`e `postorder` sul nostro albero. Ognuno di questi metodi dovrebbe restituire una serie di oggetti che rappresentano il traversale ad albero. Assicurati di restituire i valori interi ad ogni nodo dell'array, non i nodi stessi. Infine, restituisci `null` se l'albero è vuoto. # --hints-- -The `BinarySearchTree` data structure should exist. +La struttura dati `BinarySearchTree` dovrebbe esistere. ```js assert( @@ -30,7 +30,7 @@ assert( ); ``` -The binary search tree should have a method called `inorder`. +L'albero di ricerca binario dovrebbe avere un metodo chiamato `inorder`. ```js assert( @@ -46,7 +46,7 @@ assert( ); ``` -The binary search tree should have a method called `preorder`. +L'albero di ricerca binario dovrebbe avere un metodo chiamato `preorder`. ```js assert( @@ -62,7 +62,7 @@ assert( ); ``` -The binary search tree should have a method called `postorder`. +L'albero di ricerca binario dovrebbe avere un metodo chiamato `postorder`. ```js assert( @@ -78,7 +78,7 @@ assert( ); ``` -The `inorder` method should return an array of the node values that result from an inorder traversal. +Il metodo `inorder` dovrebbe restituire un array dei valori del nodo che risultano da un traversamento inorder. ```js assert( @@ -108,7 +108,7 @@ assert( ); ``` -The `preorder` method should return an array of the node values that result from a preorder traversal. +Il metodo `preorder` dovrebbe restituire un array dei valori del nodo che risultano da un attraversamento preorder. ```js assert( @@ -138,7 +138,7 @@ assert( ); ``` -The `postorder` method should return an array of the node values that result from a postorder traversal. +Il metodo `postorder` dovrebbe restituire un array dei valori del nodo che risultano da un traversamento postordine. ```js assert( @@ -168,7 +168,7 @@ assert( ); ``` -The `inorder` method should return `null` for an empty tree. +Il metodo `inorder` dovrebbe restituire `null` per un albero vuoto. ```js assert( @@ -187,7 +187,7 @@ assert( ); ``` -The `preorder` method should return `null` for an empty tree. +Il metodo `preorder` dovrebbe restituire `null` per un albero vuoto. ```js assert( @@ -206,7 +206,7 @@ assert( ); ``` -The `postorder` method should return `null` for an empty tree. +Il metodo `postorder` dovrebbe restituire `null` per un albero vuoto. ```js assert( diff --git a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/use-spread-and-notes-for-es5-set-integration.md b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/use-spread-and-notes-for-es5-set-integration.md index 79ba7313b8..42690e7ac7 100644 --- a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/use-spread-and-notes-for-es5-set-integration.md +++ b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/use-spread-and-notes-for-es5-set-integration.md @@ -1,6 +1,6 @@ --- id: 587d8255367417b2b2512c73 -title: Use Spread and Notes for ES5 Set() Integration +title: Usare sprea e notes per integrazione del Set() ES5 challengeType: 1 forumTopicId: 301720 dashedName: use-spread-and-notes-for-es5-set-integration @@ -8,11 +8,11 @@ dashedName: use-spread-and-notes-for-es5-set-integration # --description-- -Do you remember the ES6 spread operator `...`? +Ricordi l'operatore di diffusione in ES6 `...`? -`...` can take iterable objects in ES6 and turn them into arrays. +`...` può prendere oggetti iterabili in ES6 e trasformarli in array. -Let's create a Set, and check out the spread function. +Creiamo un Set e controlliamo la funzione di diffusione. ```js var set = new Set([1,2,3]); @@ -22,13 +22,13 @@ console.log(setToArr) // returns [ 1, 2, 3 ] # --instructions-- -In this exercise we will pass a set object to the `checkSet` function. It should return an array containing the values of the Set. +In questo esercizio passeremo un oggetto set alla funzione `checkSet`. Dovrebbe restituire un array contenente i valori del Set. -Now you've successfully learned how to use the ES6 `Set()` object, good job! +Ora hai imparato con successo come usare l'oggetto ES6 `Set()`, buon lavoro! # --hints-- -`checkSet(new Set([1,2,3,4,5,6,7])` should return `[1, 2, 3, 4, 5, 6, 7]`. +`checkSet(new Set([1,2,3,4,5,6,7])` dovrebbe restituire `[1, 2, 3, 4, 5, 6, 7]`. ```js assert( diff --git a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/work-with-nodes-in-a-linked-list.md b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/work-with-nodes-in-a-linked-list.md index c746995d5d..56bd0ae14c 100644 --- a/curriculum/challenges/italian/10-coding-interview-prep/data-structures/work-with-nodes-in-a-linked-list.md +++ b/curriculum/challenges/italian/10-coding-interview-prep/data-structures/work-with-nodes-in-a-linked-list.md @@ -1,6 +1,6 @@ --- id: 587d8251367417b2b2512c61 -title: Work with Nodes in a Linked List +title: Lavorare con i nodi in una lista concatenata challengeType: 1 forumTopicId: 301721 dashedName: work-with-nodes-in-a-linked-list @@ -8,25 +8,25 @@ dashedName: work-with-nodes-in-a-linked-list # --description-- -Another common data structure you'll run into in computer science is the linked list. A linked list is a linear collection of data elements, called 'nodes', each of which points to the next. Each node in a linked list contains two key pieces of information: the `element` itself, and a reference to the next `node`. +Un'altra struttura dati che incontrerai in computer science è la lista concatenata. Una lista concatenata è una collezione lineare di elementi di dati, chiamati nodi, ognuno dei quali fa riferimento al successivo. Ogni nodo in una lista concatenata contiene due informazioni fondamentali: l'elemento stesso, e un riferimento al nodo successivo. -Imagine that you are in a conga line. You have your hands on the next person in the line, and the person behind you has their hands on you. You can see the person straight ahead of you, but they are blocking the view of the other people ahead in line. A node is just like a person in a conga line: they know who they are and they can only see the next person in line, but they are not aware of the other people ahead or behind them. +Immagina di essere in un trenino. Hai le mani sulle spalle della persona davanti a te in fila, e la persona dietro di te ha le mani sulle tue spalle. Puoi vedere la persona direttamente di fronte a te, ma stanno bloccando la vista delle altre persone più in la nel trenino. Un nodo è proprio come una persona in un trenino: sanno chi sono e possono vedere solo la persona successiva nella fila, ma non sono a conoscenza delle altre persone davanti o dietro di loro. # --instructions-- -In our code editor, we've created two nodes, `Kitten` and `Puppy`, and we've manually connected the `Kitten` node to the `Puppy` node. +Nel nostro editor di codice, abbiamo creato due noti, `Kitten` e `Puppy`, e abbiamo connesso il nodo `Kitten` al nodo`Puppy`. -Create a `Cat` and `Dog` node and manually add them to the line. +Crea dei nodi `Cat` e `Dog` e aggiungili manualmente alla lista. # --hints-- -Your `Puppy` node should have a reference to a `Cat` node. +Il tuo nodo `Puppy` dovrebbe avere un riferimento a un nodo `Cat`. ```js assert(Puppy.next.element === 'Cat'); ``` -Your `Cat` node should have a reference to a `Dog` node. +Il tuo nodo `Cat` dovrebbe avere un riferimento a un nodo `Dog`. ```js assert(Cat.next.element === 'Dog'); diff --git a/curriculum/challenges/portuguese/01-responsive-web-design/applied-accessibility/use-headings-to-show-hierarchical-relationships-of-content.md b/curriculum/challenges/portuguese/01-responsive-web-design/applied-accessibility/use-headings-to-show-hierarchical-relationships-of-content.md index 46c696b850..ccdad503aa 100644 --- a/curriculum/challenges/portuguese/01-responsive-web-design/applied-accessibility/use-headings-to-show-hierarchical-relationships-of-content.md +++ b/curriculum/challenges/portuguese/01-responsive-web-design/applied-accessibility/use-headings-to-show-hierarchical-relationships-of-content.md @@ -17,7 +17,7 @@ Se você estivesse escrevendo um artigo com uma introdução, um corpo e uma con Títulos com classificação igual (ou superior) iniciam novas seções, títulos com classificação inferior começam subseções dentro da seção pai. -Por exemplo: uma página com um elemento `h2` seguido por várias subseções rotuladas com tags `h4` confundiria um usuário de leitor de tela. Como o HTML5 oferece 6 opções de títulos, pode ser tentador usar uma dessas tags apenas pelo tamanho da fonte que elas oferecem, mas você pode usar o CSS para alterar estes tamanhos. +Por exemplo: uma página com um elemento `h2` seguido por várias subseções rotuladas com elementos `h4` confundiria um usuário de leitor de tela. Como o HTML5 oferece 6 opções de títulos, pode ser tentador usar uma dessas tags apenas pelo tamanho da fonte que elas oferecem, mas você pode usar o CSS para alterar estes tamanhos. Uma última observação, cada página deve sempre ter um (e apenas um) elemento `h1`, que é o assunto principal do seu conteúdo. Este e outros cabeçalhos são usados ​​em parte pelos mecanismos de pesquisa para entender o tópico da página. @@ -27,7 +27,7 @@ O Camper Cat quer uma página no site dedicada a como se tornar um ninja. Ajude- # --hints-- -O código deve ter 6 tags `h3`. +O código deve ter 6 elementos `h3`. ```js assert($('h3').length === 6); @@ -39,7 +39,7 @@ O código deve ter 6 tags de fechamento `h3`. assert((code.match(/\/h3/g) || []).length === 6); ``` -O código não deve ter nenhuma tag `h5`. +O código não deve ter nenhum elemento `h5`. ```js assert($('h5').length === 0); diff --git a/curriculum/challenges/portuguese/01-responsive-web-design/applied-visual-design/adjust-the-size-of-a-heading-element-versus-a-paragraph-element.md b/curriculum/challenges/portuguese/01-responsive-web-design/applied-visual-design/adjust-the-size-of-a-heading-element-versus-a-paragraph-element.md index 9191d7cdec..60d1c320b7 100644 --- a/curriculum/challenges/portuguese/01-responsive-web-design/applied-visual-design/adjust-the-size-of-a-heading-element-versus-a-paragraph-element.md +++ b/curriculum/challenges/portuguese/01-responsive-web-design/applied-visual-design/adjust-the-size-of-a-heading-element-versus-a-paragraph-element.md @@ -1,6 +1,6 @@ --- id: 587d781b367417b2b2512abd -title: Contrastar o tamanho de um título com o de um parágrafo +title: Contrastar o tamanho de um elemento de título com o de um parágrafo challengeType: 0 videoUrl: 'https://scrimba.com/c/c3bRPTz' forumTopicId: 301037 @@ -9,11 +9,11 @@ dashedName: adjust-the-size-of-a-heading-element-versus-a-paragraph-element # --description-- -O tamanho da tipografia das tags de títulos (`h1` a `h6`) geralmente deve ser maior do que o tamanho da tipografia das tags de parágrafo. Isso torna mais fácil para o usuário entender visualmente o layout e o nível de importância de tudo na página. Você pode usar a propriedade `font-size` para ajustar o tamanho do texto de um elemento. +O tamanho da tipografia dos elementos de título (`h1` a `h6`) geralmente deve ser maior do que o tamanho da tipografia dos elementos de parágrafo. Isso torna mais fácil para o usuário entender visualmente o layout e o nível de importância de tudo na página. Você pode usar a propriedade `font-size` para ajustar o tamanho do texto de um elemento. # --instructions-- -Para tornar o título significativamente maior do que o parágrafo, altere a propriedade `font-size` da tag `h4` para 27 pixels. +Para tornar o título significativamente maior do que o parágrafo, altere a propriedade `font-size` do elemento `h4` para 27 pixels. # --hints-- @@ -116,3 +116,4 @@ assert($('h4').css('font-size') == '27px'); ``` + diff --git a/curriculum/challenges/portuguese/01-responsive-web-design/applied-visual-design/create-visual-balance-using-the-text-align-property.md b/curriculum/challenges/portuguese/01-responsive-web-design/applied-visual-design/create-visual-balance-using-the-text-align-property.md index 753a7fbe10..0934b187da 100644 --- a/curriculum/challenges/portuguese/01-responsive-web-design/applied-visual-design/create-visual-balance-using-the-text-align-property.md +++ b/curriculum/challenges/portuguese/01-responsive-web-design/applied-visual-design/create-visual-balance-using-the-text-align-property.md @@ -13,7 +13,7 @@ Esta seção do currículo se concentra no Design Visual Aplicado. O primeiro gr O texto costuma ser uma grande parte do conteúdo na web. O CSS possui várias opções de como alinhá-lo com a propriedade `text-align`. -`text-align: justify;` faz com que todas as linhas de texto, exceto a última linha, encostem nas bordas esquerda e direita da caixa em que o texto está. +`text-align: justify;` espaça o texto para que cada linha tenha a mesma largura. `text-align: center;` centraliza o texto diff --git a/curriculum/challenges/portuguese/01-responsive-web-design/applied-visual-design/use-the-s-tag-to-strikethrough-text.md b/curriculum/challenges/portuguese/01-responsive-web-design/applied-visual-design/use-the-s-tag-to-strikethrough-text.md index c0b5dfaf56..f6e39e902b 100644 --- a/curriculum/challenges/portuguese/01-responsive-web-design/applied-visual-design/use-the-s-tag-to-strikethrough-text.md +++ b/curriculum/challenges/portuguese/01-responsive-web-design/applied-visual-design/use-the-s-tag-to-strikethrough-text.md @@ -13,7 +13,7 @@ Para deixar o texto tachado, ou seja, para que uma linha horizontal corte os car # --instructions-- -Envolva a tag `s` em torno da palavra `Google` que está dentro da tag `h4` e, em seguida, adicione a palavra `Alphabet` ao lado dela. Essa segunda palavra não deverá estar tachada. +Envolva a tag `s` em torno da palavra `Google` que está dentro da tag `h4` e, em seguida, adicione a palavra `Alphabet` ao lado dela sem a formatação tachada. # --hints-- diff --git a/curriculum/challenges/portuguese/01-responsive-web-design/basic-html-and-html5/link-to-internal-sections-of-a-page-with-anchor-elements.md b/curriculum/challenges/portuguese/01-responsive-web-design/basic-html-and-html5/link-to-internal-sections-of-a-page-with-anchor-elements.md index ed9593d27d..338d88dd2e 100644 --- a/curriculum/challenges/portuguese/01-responsive-web-design/basic-html-and-html5/link-to-internal-sections-of-a-page-with-anchor-elements.md +++ b/curriculum/challenges/portuguese/01-responsive-web-design/basic-html-and-html5/link-to-internal-sections-of-a-page-with-anchor-elements.md @@ -21,7 +21,7 @@ Abaixo, vemos um exemplo de um link vinculado a um elemento interno da página:

Contacts

``` -Quando os usuários clicam no link `Contacts`, eles são levados à seção da página que contem o texto **Contacts**. +Quando os usuários clicam no link `Contacts`, eles são levados à seção da página que contem o elemento de título **Contacts**. # --instructions-- diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/access-array-data-with-indexes.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/access-array-data-with-indexes.md index 889331b47a..07b2f13da1 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/access-array-data-with-indexes.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/access-array-data-with-indexes.md @@ -18,9 +18,9 @@ Os índices de um array são escritos na mesma notação com colchetes que as st **Exemplo** ```js -var array = [50,60,70]; +const array = [50, 60, 70]; array[0]; -var data = array[1]; +const data = array[1]; ``` `array[0]` agora é `50` e `data` tem o valor `60`. @@ -76,7 +76,7 @@ if(typeof myArray !== "undefined" && typeof myData !== "undefined"){(function(y, ## --seed-contents-- ```js -var myArray = [50,60,70]; +const myArray = [50, 60, 70]; ``` @@ -84,6 +84,6 @@ var myArray = [50,60,70]; # --solutions-- ```js -var myArray = [50,60,70]; -var myData = myArray[0]; +const myArray = [50, 60, 70]; +const myData = myArray[0]; ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/access-multi-dimensional-arrays-with-indexes.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/access-multi-dimensional-arrays-with-indexes.md index 841e497941..60d8694b95 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/access-multi-dimensional-arrays-with-indexes.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/access-multi-dimensional-arrays-with-indexes.md @@ -14,12 +14,13 @@ Uma maneira de pensar em um array multidimensional é como um *array **Exemplo** ```js -var arr = [ - [1,2,3], - [4,5,6], - [7,8,9], - [[10,11,12], 13, 14] +const arr = [ + [1, 2, 3], + [4, 5, 6], + [7, 8, 9], + [[10, 11, 12], 13, 14] ]; + arr[3]; arr[3][0]; arr[3][0][1]; @@ -58,14 +59,19 @@ if(typeof myArray !== "undefined"){(function(){return "myData: " + myData + " my ## --seed-contents-- ```js -var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]]; +const myArray = [ + [1, 2, 3], + [4, 5, 6], + [7, 8, 9], + [[10, 11, 12], 13, 14], +]; -var myData = myArray[0][0]; +const myData = myArray[0][0]; ``` # --solutions-- ```js -var myArray = [[1,2,3],[4,5,6], [7,8,9], [[10,11,12], 13, 14]]; -var myData = myArray[2][1]; +const myArray = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [[10, 11, 12], 13, 14]]; +const myData = myArray[2][1]; ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-arrays.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-arrays.md index d403cac91f..e8b7c5e3c9 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-arrays.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-arrays.md @@ -14,7 +14,7 @@ Como vimos em exemplos anteriores, objetos podem conter tanto objetos aninhados Aqui está um exemplo de como se acessar um array aninhado: ```js -var ourPets = [ +const ourPets = [ { animalType: "cat", names: [ @@ -32,6 +32,7 @@ var ourPets = [ ] } ]; + ourPets[0].names[1]; ourPets[1].names[0]; ``` @@ -72,7 +73,7 @@ assert(/=\s*myPlants\[1\].list\[1\]/.test(code)); ## --seed-contents-- ```js -var myPlants = [ +const myPlants = [ { type: "flowers", list: [ @@ -91,13 +92,13 @@ var myPlants = [ } ]; -var secondTree = ""; +const secondTree = ""; ``` # --solutions-- ```js -var myPlants = [ +const myPlants = [ { type: "flowers", list: [ @@ -116,5 +117,5 @@ var myPlants = [ } ]; -var secondTree = myPlants[1].list[1]; +const secondTree = myPlants[1].list[1]; ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-objects.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-objects.md index 26dc990f75..1cab5c2811 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-objects.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-objects.md @@ -14,7 +14,7 @@ As subpropriedades de objetos podem ser acessadas ao encadear a notação de pon Aqui está um objeto aninhado: ```js -var ourStorage = { +const ourStorage = { "desk": { "drawer": "stapler" }, @@ -26,6 +26,7 @@ var ourStorage = { "bottom drawer": "soda" } }; + ourStorage.cabinet["top drawer"].folder2; ourStorage.desk.drawer; ``` @@ -66,7 +67,7 @@ assert(/=\s*myStorage\.car\.inside\[\s*("|')glove box\1\s*\]/g.test(code)); ## --seed-contents-- ```js -var myStorage = { +const myStorage = { "car": { "inside": { "glove box": "maps", @@ -78,13 +79,13 @@ var myStorage = { } }; -var gloveBoxContents = undefined; +const gloveBoxContents = undefined; ``` # --solutions-- ```js -var myStorage = { +const myStorage = { "car":{ "inside":{ "glove box":"maps", @@ -95,5 +96,5 @@ var myStorage = { } } }; -var gloveBoxContents = myStorage.car.inside["glove box"]; +const gloveBoxContents = myStorage.car.inside["glove box"]; ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-bracket-notation.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-bracket-notation.md index a906f8fc95..5986eb8a2e 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-bracket-notation.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-bracket-notation.md @@ -16,11 +16,12 @@ No entanto, você ainda pode usar a notação de colchetes nas propriedades dos Aqui está um exemplo usando a notação de colchetes para ler uma propriedade de um objeto: ```js -var myObj = { +const myObj = { "Space Name": "Kirk", "More Space": "Spock", "NoSpace": "USS Enterprise" }; + myObj["Space Name"]; myObj['More Space']; myObj["NoSpace"]; @@ -78,26 +79,25 @@ assert(code.match(/testObj\s*?\[('|")[^'"]+\1\]/g).length > 1); ```js // Setup -var testObj = { +const testObj = { "an entree": "hamburger", "my side": "veggies", "the drink": "water" }; // Only change code below this line - -var entreeValue = testObj; // Change this line -var drinkValue = testObj; // Change this line +const entreeValue = testObj; // Change this line +const drinkValue = testObj; // Change this line ``` # --solutions-- ```js -var testObj = { +const testObj = { "an entree": "hamburger", "my side": "veggies", "the drink": "water" }; -var entreeValue = testObj["an entree"]; -var drinkValue = testObj['the drink']; +const entreeValue = testObj["an entree"]; +const drinkValue = testObj['the drink']; ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-dot-notation.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-dot-notation.md index e9f70fe6ea..2b02189601 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-dot-notation.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-dot-notation.md @@ -16,15 +16,17 @@ Notação de ponto é o que você utiliza quando você sabe o nome da propriedad Aqui está um exemplo usando notação de ponto (`.`) para ler uma propriedade do objeto: ```js -var myObj = { +const myObj = { prop1: "val1", prop2: "val2" }; -var prop1val = myObj.prop1; -var prop2val = myObj.prop2; + +const prop1val = myObj.prop1; +const prop2val = myObj.prop2; ``` `prop1val` teria o valor `val1` e `prop2val` teria o valor `val2`. + # --instructions-- Leia os valores de propriedade de `testObj` usando a notação de ponto. Defina a variável `hatValue` igual à propriedade `hat` do objeto e defina a variável `shirtValue` igual à propriedade `shirt` do objeto. @@ -73,27 +75,26 @@ assert(code.match(/testObj\.\w+/g).length > 1); ```js // Setup -var testObj = { +const testObj = { "hat": "ballcap", "shirt": "jersey", "shoes": "cleats" }; // Only change code below this line - -var hatValue = testObj; // Change this line -var shirtValue = testObj; // Change this line +const hatValue = testObj; // Change this line +const shirtValue = testObj; // Change this line ``` # --solutions-- ```js -var testObj = { +const testObj = { "hat": "ballcap", "shirt": "jersey", "shoes": "cleats" }; -var hatValue = testObj.hat; -var shirtValue = testObj.shirt; +const hatValue = testObj.hat; +const shirtValue = testObj.shirt; ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-variables.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-variables.md index cd5cfc3d58..80ef872b15 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-variables.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-variables.md @@ -14,11 +14,14 @@ Outro uso de notação de colchetes em objetos é para acessar a propriedade a q Aqui está um exemplo de usar uma variável para acessar uma propriedade: ```js -var dogs = { - Fido: "Mutt", Hunter: "Doberman", Snoopie: "Beagle" +const dogs = { + Fido: "Mutt", + Hunter: "Doberman", + Snoopie: "Beagle" }; -var myDog = "Hunter"; -var myBreed = dogs[myDog]; + +const myDog = "Hunter"; +const myBreed = dogs[myDog]; console.log(myBreed); ``` @@ -27,14 +30,16 @@ A string `Doberman` seria exibida no console. Outra forma de você usar esse conceito é quando o nome da propriedade é coletado dinamicamente, durante a execução do programa, da seguinte forma: ```js -var someObj = { +const someObj = { propName: "John" }; + function propPrefix(str) { - var s = "prop"; + const s = "prop"; return s + str; } -var someProp = propPrefix("Name"); + +const someProp = propPrefix("Name"); console.log(someObj[someProp]); ``` @@ -96,26 +101,25 @@ if(typeof player !== "undefined"){(function(v){return v;})(player);} ```js // Setup -var testObj = { +const testObj = { 12: "Namath", 16: "Montana", 19: "Unitas" }; // Only change code below this line - -var playerNumber; // Change this line -var player = testObj; // Change this line +const playerNumber = 42; // Change this line +const player = testObj; // Change this line ``` # --solutions-- ```js -var testObj = { +const testObj = { 12: "Namath", 16: "Montana", 19: "Unitas" }; -var playerNumber = 16; -var player = testObj[playerNumber]; +const playerNumber = 16; +const player = testObj[playerNumber]; ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/add-new-properties-to-a-javascript-object.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/add-new-properties-to-a-javascript-object.md index 536482c962..7c321d33e3 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/add-new-properties-to-a-javascript-object.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/add-new-properties-to-a-javascript-object.md @@ -28,7 +28,7 @@ Agora, quando acessamos `ourDog.bark`, nós teremos o seu latido, `bow-wow`. Exemplo: ```js -var ourDog = { +const ourDog = { "name": "Camper", "legs": 4, "tails": 1, @@ -67,7 +67,7 @@ assert(!/bark[^\n]:/.test(code)); ## --seed-contents-- ```js -var myDog = { +const myDog = { "name": "Happy Coder", "legs": 4, "tails": 1, @@ -80,7 +80,7 @@ var myDog = { # --solutions-- ```js -var myDog = { +const myDog = { "name": "Happy Coder", "legs": 4, "tails": 1, diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/add-two-numbers-with-javascript.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/add-two-numbers-with-javascript.md index 5b432e15a4..d9d0552b85 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/add-two-numbers-with-javascript.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/add-two-numbers-with-javascript.md @@ -18,7 +18,7 @@ JavaScript utiliza o símbolo `+` como um operador de adição quando colocado e **Exemplo:** ```js -myVar = 5 + 10; +const myVar = 5 + 10; ``` `myVar` agora tem o valor de `15`. @@ -52,11 +52,11 @@ assert(/\+/.test(code)); ## --seed-contents-- ```js -var sum = 10 + 0; +const sum = 10 + 0; ``` # --solutions-- ```js -var sum = 10 + 10; +const sum = 10 + 10; ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/adding-a-default-option-in-switch-statements.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/adding-a-default-option-in-switch-statements.md index cf93fe09a4..beffc0750b 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/adding-a-default-option-in-switch-statements.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/adding-a-default-option-in-switch-statements.md @@ -92,7 +92,7 @@ assert(code.match(/break/g).length > 2); ```js function switchOfStuff(val) { - var answer = ""; + let answer = ""; // Only change code below this line @@ -108,7 +108,7 @@ switchOfStuff(1); ```js function switchOfStuff(val) { - var answer = ""; + let answer = ""; switch(val) { case "a": diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/appending-variables-to-strings.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/appending-variables-to-strings.md index 987a2387a1..06d6a5f57a 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/appending-variables-to-strings.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/appending-variables-to-strings.md @@ -14,8 +14,8 @@ Assim como podemos construir uma string em várias linhas através das strings < Exemplo: ```js -var anAdjective = "awesome!"; -var ourStr = "freeCodeCamp is "; +const anAdjective = "awesome!"; +let ourStr = "freeCodeCamp is "; ourStr += anAdjective; ``` @@ -64,15 +64,14 @@ assert(code.match(/myStr\s*\+=\s*someAdjective\s*/).length > 0); ```js // Change code below this line - -var someAdjective; -var myStr = "Learning to code is "; +const someAdjective = ""; +let myStr = "Learning to code is "; ``` # --solutions-- ```js -var someAdjective = "neat"; -var myStr = "Learning to code is "; +const someAdjective = "neat"; +let myStr = "Learning to code is "; myStr += someAdjective; ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/build-javascript-objects.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/build-javascript-objects.md index fb9682c4d6..5032a5a25f 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/build-javascript-objects.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/build-javascript-objects.md @@ -18,7 +18,7 @@ Objetos são úteis para armazenar dados de forma estruturada e podem representa Aqui está um exemplo de objeto gato: ```js -var cat = { +const cat = { "name": "Whiskers", "legs": 4, "tails": 1, @@ -29,7 +29,7 @@ var cat = { Neste exemplo, todas as propriedades são armazenadas como strings, como `name`, `legs` e `tails`. Porém, você também pode usar números como propriedades. Você pode até omitir as aspas para propriedades de string com uma única palavra, da seguinte forma: ```js -var anotherObject = { +const anotherObject = { make: "Ford", 5: "five", "model": "focus" @@ -139,18 +139,18 @@ assert( ## --seed-contents-- ```js -var myDog = { -// Only change code below this line +const myDog = { + // Only change code below this line -// Only change code above this line + // Only change code above this line }; ``` # --solutions-- ```js -var myDog = { +const myDog = { "name": "Camper", "legs": 4, "tails": 1, diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-equality-operator.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-equality-operator.md index 5dbedae385..94afde2001 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-equality-operator.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-equality-operator.md @@ -16,7 +16,7 @@ O operador mais básico é o operador de igualdade `==`. O operador de igualdade ```js function equalityTest(myVal) { if (myVal == 10) { - return "Equal"; + return "Equal"; } return "Not Equal"; } diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-addition.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-addition.md index 2c13e190d2..efb651fb17 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-addition.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-addition.md @@ -20,7 +20,7 @@ para adicionar `5` a `myVar`. Como este é um padrão tão comum, existem operad Um desses operadores é o operador `+=`. ```js -var myVar = 1; +let myVar = 1; myVar += 5; console.log(myVar); ``` @@ -61,9 +61,9 @@ Você não deve modificar o código acima do comentário especificado. ```js assert( - /var a = 3;/.test(code) && - /var b = 17;/.test(code) && - /var c = 12;/.test(code) + /let a = 3;/.test(code) && + /let b = 17;/.test(code) && + /let c = 12;/.test(code) ); ``` @@ -78,9 +78,9 @@ assert( ## --seed-contents-- ```js -var a = 3; -var b = 17; -var c = 12; +let a = 3; +let b = 17; +let c = 12; // Only change code below this line a = a + 12; @@ -91,9 +91,9 @@ c = c + 7; # --solutions-- ```js -var a = 3; -var b = 17; -var c = 12; +let a = 3; +let b = 17; +let c = 12; a += 12; b += 9; diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-division.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-division.md index bb4335d4e6..79574ac77d 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-division.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-division.md @@ -55,9 +55,9 @@ Você não deve modificar o código acima do comentário especificado. ```js assert( - /var a = 48;/.test(code) && - /var b = 108;/.test(code) && - /var c = 33;/.test(code) + /let a = 48;/.test(code) && + /let b = 108;/.test(code) && + /let c = 33;/.test(code) ); ``` @@ -72,9 +72,9 @@ assert( ## --seed-contents-- ```js -var a = 48; -var b = 108; -var c = 33; +let a = 48; +let b = 108; +let c = 33; // Only change code below this line a = a / 12; @@ -85,9 +85,9 @@ c = c / 11; # --solutions-- ```js -var a = 48; -var b = 108; -var c = 33; +let a = 48; +let b = 108; +let c = 33; a /= 12; b /= 4; diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-multiplication.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-multiplication.md index 7b1f7ada71..9ab507cf2c 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-multiplication.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-multiplication.md @@ -55,9 +55,9 @@ Você não deve modificar o código acima do comentário especificado. ```js assert( - /var a = 5;/.test(code) && - /var b = 12;/.test(code) && - /var c = 4\.6;/.test(code) + /let a = 5;/.test(code) && + /let b = 12;/.test(code) && + /let c = 4\.6;/.test(code) ); ``` @@ -72,9 +72,9 @@ assert( ## --seed-contents-- ```js -var a = 5; -var b = 12; -var c = 4.6; +let a = 5; +let b = 12; +let c = 4.6; // Only change code below this line a = a * 5; @@ -85,9 +85,9 @@ c = c * 10; # --solutions-- ```js -var a = 5; -var b = 12; -var c = 4.6; +let a = 5; +let b = 12; +let c = 4.6; a *= 5; b *= 3; diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-subtraction.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-subtraction.md index 627741cc1d..2dae4695cd 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-subtraction.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-subtraction.md @@ -55,7 +55,7 @@ Você não deve modificar o código acima do comentário especificado. ```js assert( - /var a = 11;/.test(code) && /var b = 9;/.test(code) && /var c = 3;/.test(code) + /let a = 11;/.test(code) && /let b = 9;/.test(code) && /let c = 3;/.test(code) ); ``` @@ -70,9 +70,9 @@ assert( ## --seed-contents-- ```js -var a = 11; -var b = 9; -var c = 3; +let a = 11; +let b = 9; +let c = 3; // Only change code below this line a = a - 6; @@ -83,9 +83,9 @@ c = c - 1; # --solutions-- ```js -var a = 11; -var b = 9; -var c = 3; +let a = 11; +let b = 9; +let c = 3; a -= 6; b -= 15; diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-the-plus-equals-operator.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-the-plus-equals-operator.md index 71904013f2..2c093f2f84 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-the-plus-equals-operator.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-the-plus-equals-operator.md @@ -16,7 +16,7 @@ Também podemos usar o operador `+=` para concatenar uma string no fi Exemplo: ```js -var ourStr = "I come first. "; +let ourStr = "I come first. "; ourStr += "I come second."; ``` @@ -57,14 +57,12 @@ assert(code.match(/myStr\s*\+=\s*(["']).*\1/g)); ## --seed-contents-- ```js -// Only change code below this line - -var myStr; +let myStr; ``` # --solutions-- ```js -var myStr = "This is the first sentence. "; +let myStr = "This is the first sentence. "; myStr += "This is the second sentence."; ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/constructing-strings-with-variables.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/constructing-strings-with-variables.md index 81f01b9312..82017bedc7 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/constructing-strings-with-variables.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/constructing-strings-with-variables.md @@ -14,8 +14,8 @@ dashedName: constructing-strings-with-variables Exemplo: ```js -var ourName = "freeCodeCamp"; -var ourStr = "Hello, our name is " + ourName + ", how are you?"; +const ourName = "freeCodeCamp"; +const ourStr = "Hello, our name is " + ourName + ", how are you?"; ``` `ourStr` teria o valor da string `Hello, our name is freeCodeCamp, how are you?`. @@ -63,13 +63,13 @@ assert(code.match(/["']\s*\+\s*myName\s*\+\s*["']/g).length > 0); ```js // Only change code below this line -var myName; -var myStr; +const myName = ""; +const myStr = ""; ``` # --solutions-- ```js -var myName = "Bob"; -var myStr = "My name is " + myName + " and I am well!"; +const myName = "Bob"; +const myStr = "My name is " + myName + " and I am well!"; ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/counting-cards.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/counting-cards.md index 0581beaa38..5e8fb5b8cd 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/counting-cards.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/counting-cards.md @@ -159,7 +159,7 @@ assert( ## --seed-contents-- ```js -var count = 0; +let count = 0; function cc(card) { // Only change code below this line @@ -175,7 +175,7 @@ cc(2); cc(3); cc(7); cc('K'); cc('A'); # --solutions-- ```js -var count = 0; +let count = 0; function cc(card) { switch(card) { case 2: diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/create-decimal-numbers-with-javascript.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/create-decimal-numbers-with-javascript.md index 748abf81d2..2690820cb7 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/create-decimal-numbers-with-javascript.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/create-decimal-numbers-with-javascript.md @@ -42,13 +42,14 @@ assert(myDecimal % 1 != 0); ## --seed-contents-- ```js -var ourDecimal = 5.7; +const ourDecimal = 5.7; // Only change code below this line + ``` # --solutions-- ```js -var myDecimal = 9.9; +const myDecimal = 9.9; ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/decrement-a-number-with-javascript.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/decrement-a-number-with-javascript.md index 29a3d15026..bed512835e 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/decrement-a-number-with-javascript.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/decrement-a-number-with-javascript.md @@ -39,7 +39,7 @@ assert(myVar === 10); ```js assert( - /var\s*myVar\s*=\s*11;\s*\/*.*\s*([-]{2}\s*myVar|myVar\s*[-]{2});/.test(code) + /let\s*myVar\s*=\s*11;\s*\/*.*\s*([-]{2}\s*myVar|myVar\s*[-]{2});/.test(code) ); ``` @@ -52,7 +52,7 @@ assert(/[-]{2}\s*myVar|myVar\s*[-]{2}/.test(code)); Você não deve alterar o código acima do comentário especificado. ```js -assert(/var myVar = 11;/.test(code)); +assert(/let myVar = 11;/.test(code)); ``` # --seed-- @@ -66,7 +66,7 @@ assert(/var myVar = 11;/.test(code)); ## --seed-contents-- ```js -var myVar = 11; +let myVar = 11; // Only change code below this line myVar = myVar - 1; @@ -75,6 +75,6 @@ myVar = myVar - 1; # --solutions-- ```js -var myVar = 11; +let myVar = 11; myVar--; ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/delete-properties-from-a-javascript-object.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/delete-properties-from-a-javascript-object.md index 45199937e1..0934dfc758 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/delete-properties-from-a-javascript-object.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/delete-properties-from-a-javascript-object.md @@ -18,7 +18,7 @@ delete ourDog.bark; Exemplo: ```js -var ourDog = { +const ourDog = { "name": "Camper", "legs": 4, "tails": 1, @@ -70,7 +70,7 @@ assert(code.match(/"tails": 1/g).length > 0); ```js // Setup -var myDog = { +const myDog = { "name": "Happy Coder", "legs": 4, "tails": 1, @@ -79,12 +79,13 @@ var myDog = { }; // Only change code below this line + ``` # --solutions-- ```js -var myDog = { +const myDog = { "name": "Happy Coder", "legs": 4, "tails": 1, diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-decimal-by-another-with-javascript.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-decimal-by-another-with-javascript.md index f08b9f39fe..67117d004f 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-decimal-by-another-with-javascript.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-decimal-by-another-with-javascript.md @@ -46,11 +46,11 @@ assert(code.match(/quotient/g).length === 1); ## --seed-contents-- ```js -var quotient = 0.0 / 2.0; // Change this line +const quotient = 0.0 / 2.0; // Change this line ``` # --solutions-- ```js -var quotient = 4.4 / 2.0; +const quotient = 4.4 / 2.0; ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-number-by-another-with-javascript.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-number-by-another-with-javascript.md index 2cc5327032..0fe66dbf7d 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-number-by-another-with-javascript.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-number-by-another-with-javascript.md @@ -16,7 +16,7 @@ JavaScript usa o símbolo `/` para divisão. **Exemplo** ```js -myVar = 16 / 2; +const myVar = 16 / 2; ``` `myVar` agora possui o valor `8`. @@ -49,11 +49,11 @@ assert(/\d+\s*\/\s*\d+/.test(code)); ## --seed-contents-- ```js -var quotient = 66 / 0; +const quotient = 66 / 0; ``` # --solutions-- ```js -var quotient = 66 / 33; +const quotient = 66 / 33; ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/escape-sequences-in-strings.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/escape-sequences-in-strings.md index c468fc1741..f808b75cb7 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/escape-sequences-in-strings.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/escape-sequences-in-strings.md @@ -89,11 +89,11 @@ console.log('myStr:\n' + myStr);}})(); ## --seed-contents-- ```js -var myStr; // Change this line +const myStr = ""; // Change this line ``` # --solutions-- ```js -var myStr = "FirstLine\n\t\\SecondLine\nThirdLine"; +const myStr = "FirstLine\n\t\\SecondLine\nThirdLine"; ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/escaping-literal-quotes-in-strings.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/escaping-literal-quotes-in-strings.md index 5558498f3e..f309410528 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/escaping-literal-quotes-in-strings.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/escaping-literal-quotes-in-strings.md @@ -14,7 +14,7 @@ Quando você estiver definindo uma sequência de caracteres você deve iniciar e Em JavaScript, você pode escapar uma aspa para que não seja considerada como o fim de uma string ao colocar a barra invertida (`\`) na frente da aspa. ```js -var sampleStr = "Alan said, \"Peter is learning JavaScript\"."; +const sampleStr = "Alan said, \"Peter is learning JavaScript\"."; ``` Isso sinaliza ao JavaScript que a aspa seguinte não é o fim de uma string, mas que deve aparecer dentro da string. Então, se você fosse imprimir isso no console, você obteria: @@ -62,11 +62,11 @@ assert(/I am a "double quoted" string inside "double quotes(\."|"\.)$/.test(mySt ## --seed-contents-- ```js -var myStr = ""; // Change this line +const myStr = ""; // Change this line ``` # --solutions-- ```js -var myStr = "I am a \"double quoted\" string inside \"double quotes\"."; +const myStr = "I am a \"double quoted\" string inside \"double quotes\"."; ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/finding-a-remainder-in-javascript.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/finding-a-remainder-in-javascript.md index e58e42c022..987b99767a 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/finding-a-remainder-in-javascript.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/finding-a-remainder-in-javascript.md @@ -31,7 +31,7 @@ Define o `resto` igual ao restante de `11` dividido por `3` usando o operador de A variável `remainder` deve ser inicializada ```js -assert(/var\s+?remainder/.test(code)); +assert(/(const|let|var)\s+?remainder/.test(code)); ``` O valor de `remainder` deve ser `2` @@ -57,13 +57,11 @@ assert(/\s+?remainder\s*?=\s*?.*%.*;?/.test(code)); ## --seed-contents-- ```js -// Only change code below this line - -var remainder; +const remainder = 0; ``` # --solutions-- ```js -var remainder = 11 % 3; +const remainder = 11 % 3; ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/global-vs.-local-scope-in-functions.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/global-vs.-local-scope-in-functions.md index 5da50dd0d2..d1a03237e6 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/global-vs.-local-scope-in-functions.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/global-vs.-local-scope-in-functions.md @@ -14,9 +14,10 @@ dashedName: global-vs--local-scope-in-functions Neste exemplo: ```js -var someVar = "Hat"; +const someVar = "Hat"; + function myFun() { - var someVar = "Head"; + const someVar = "Head"; return someVar; } ``` @@ -53,13 +54,11 @@ assert(/return outerWear/.test(code)); ```js // Setup -var outerWear = "T-Shirt"; +const outerWear = "T-Shirt"; function myOutfit() { // Only change code below this line - - // Only change code above this line return outerWear; } @@ -70,9 +69,9 @@ myOutfit(); # --solutions-- ```js -var outerWear = "T-Shirt"; +const outerWear = "T-Shirt"; function myOutfit() { - var outerWear = "sweater"; + const outerWear = "sweater"; return outerWear; } ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/golf-code.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/golf-code.md index 28bd619a55..bc401dc1d7 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/golf-code.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/golf-code.md @@ -90,7 +90,8 @@ assert(golfScore(5, 9) === 'Go Home!'); ## --seed-contents-- ```js -var names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"]; +const names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"]; + function golfScore(par, strokes) { // Only change code below this line diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/increment-a-number-with-javascript.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/increment-a-number-with-javascript.md index 21aa67e670..16b4f4f56f 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/increment-a-number-with-javascript.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/increment-a-number-with-javascript.md @@ -39,7 +39,7 @@ Você não deve usar o operador de atribuição. ```js assert( - /var\s*myVar\s*=\s*87;\s*\/*.*\s*([+]{2}\s*myVar|myVar\s*[+]{2});/.test(code) + /let\s*myVar\s*=\s*87;\s*\/*.*\s*([+]{2}\s*myVar|myVar\s*[+]{2});/.test(code) ); ``` @@ -52,7 +52,7 @@ assert(/[+]{2}\s*myVar|myVar\s*[+]{2}/.test(code)); Você não deve alterar o código acima do comentário especificado. ```js -assert(/var myVar = 87;/.test(code)); +assert(/let myVar = 87;/.test(code)); ``` # --seed-- @@ -66,7 +66,7 @@ assert(/var myVar = 87;/.test(code)); ## --seed-contents-- ```js -var myVar = 87; +let myVar = 87; // Only change code below this line myVar = myVar + 1; @@ -75,6 +75,6 @@ myVar = myVar + 1; # --solutions-- ```js -var myVar = 87; +let myVar = 87; myVar++; ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/introducing-else-statements.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/introducing-else-statements.md index 7d59459468..874d3ed9a3 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/introducing-else-statements.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/introducing-else-statements.md @@ -64,7 +64,7 @@ assert(testElse(10) === 'Bigger than 5'); Você não deve alterar o código acima ou abaixo dos comentários especificados. ```js -assert(/var result = "";/.test(code) && /return result;/.test(code)); +assert(/let result = "";/.test(code) && /return result;/.test(code)); ``` # --seed-- @@ -73,7 +73,7 @@ assert(/var result = "";/.test(code) && /return result;/.test(code)); ```js function testElse(val) { - var result = ""; + let result = ""; // Only change code below this line if (val > 5) { @@ -95,7 +95,7 @@ testElse(4); ```js function testElse(val) { - var result = ""; + let result = ""; if(val > 5) { result = "Bigger than 5"; } else { diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-through-an-array-with-a-for-loop.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-through-an-array-with-a-for-loop.md index a0d8ab56a2..4860c8cfde 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-through-an-array-with-a-for-loop.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-through-an-array-with-a-for-loop.md @@ -12,8 +12,9 @@ dashedName: iterate-through-an-array-with-a-for-loop Uma tarefa comum em JavaScript é para iterar através do conteúdo de um array. Uma forma de fazer isso é com um laço `for`. Esse código vai exibir cada elemento do array `arr` no console: ```js -var arr = [10, 9, 8, 7, 6]; -for (var i = 0; i < arr.length; i++) { +const arr = [10, 9, 8, 7, 6]; + +for (let i = 0; i < arr.length; i++) { console.log(arr[i]); } ``` @@ -62,18 +63,19 @@ assert(!__helpers.removeWhiteSpace(code).match(/total[=+-]0*[1-9]+/gm)); ```js // Setup -var myArr = [ 2, 3, 4, 5, 6]; +const myArr = [2, 3, 4, 5, 6]; // Only change code below this line + ``` # --solutions-- ```js -var myArr = [ 2, 3, 4, 5, 6]; -var total = 0; +const myArr = [2, 3, 4, 5, 6]; +let total = 0; -for (var i = 0; i < myArr.length; i++) { +for (let i = 0; i < myArr.length; i++) { total += myArr[i]; } ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-do...while-loops.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-do...while-loops.md index a83f89c0b0..d1d0271330 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-do...while-loops.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-do...while-loops.md @@ -12,8 +12,9 @@ dashedName: iterate-with-javascript-do---while-loops O próximo tipo de laço que você aprenderá é chamado de laço `do...while`. O laço `do...while` é chamado assim porque primeiro fará algo (`do`) ou executará algo uma vez dentro do bloco de código, não importando o que acontecer. Em seguida, continuará a executar o laço enquanto (`while`) a condição for `true`. ```js -var ourArray = []; -var i = 0; +const ourArray = []; +let i = 0; + do { ourArray.push(i); i++; @@ -23,8 +24,9 @@ do { O exemplo acima se comporta de forma similar a outros tipos de laços, e o array resultante se parecerá com `[0,1,2,3,4]`. No entanto, o que torna o laço `do...while` diferente de outros laços é como ele se comporta quando uma condição falha na primeira verificação. Vamos ver isso na prática: Aqui está um laço comum `while` que rodará o código no laço enquanto `i < 5`: ```js -var ourArray = []; -var i = 5; +const ourArray = []; +let i = 5; + while (i < 5) { ourArray.push(i); i++; @@ -34,8 +36,9 @@ while (i < 5) { Nesse exemplo, inicializamos o valor de `ourArray` como um array vazio e o valor de `i` sendo 5. Quando executamos o laço `while`, a condição é igual a `false` porque `i` não é menor que 5, portanto nós não executamos o código dentro do laço. O resultado é que `ourArray` terminará sem valores adicionados a ele, e ainda se parecerá com `[]` quando todas as linhas do código no exemplo acima forem completamente executadas. Agora, dê uma olhada no laço `do...while`: ```js -var ourArray = []; -var i = 5; +const ourArray = []; +let i = 5; + do { ourArray.push(i); i++; @@ -80,8 +83,8 @@ if(typeof myArray !== "undefined"){(function(){return myArray;})();} ```js // Setup -var myArray = []; -var i = 10; +const myArray = []; +let i = 10; // Only change code below this line while (i < 5) { @@ -93,8 +96,8 @@ while (i < 5) { # --solutions-- ```js -var myArray = []; -var i = 10; +const myArray = []; +let i = 10; do { myArray.push(i); i++; diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/local-scope-and-functions.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/local-scope-and-functions.md index 503ff92833..3b55efd09c 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/local-scope-and-functions.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/local-scope-and-functions.md @@ -15,9 +15,10 @@ Aqui está uma função `myTest` com uma variável local chamada `loc`. ```js function myTest() { - var loc = "foo"; + const loc = "foo"; console.log(loc); } + myTest(); console.log(loc); ``` @@ -38,6 +39,7 @@ O código não deve conter uma variável global `myVar`. function declared() { myVar; } + assert.throws(declared, ReferenceError); ``` @@ -57,7 +59,6 @@ assert( ```js function myLocalScope() { - // Only change code below this line console.log('inside myLocalScope', myVar); @@ -73,9 +74,8 @@ console.log('outside myLocalScope', myVar); ```js function myLocalScope() { - // Only change code below this line - var myVar; + let myVar; console.log('inside myLocalScope', myVar); } myLocalScope(); diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-push.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-push.md index 3f21578117..8db979418e 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-push.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-push.md @@ -16,10 +16,10 @@ Uma forma fácil de adicionar dados no final de um array é através da função Exemplos: ```js -var arr1 = [1,2,3]; +const arr1 = [1, 2, 3]; arr1.push(4); -var arr2 = ["Stimpson", "J", "cat"]; +const arr2 = ["Stimpson", "J", "cat"]; arr2.push(["happy", "joy"]); ``` @@ -64,14 +64,15 @@ assert( ```js // Setup -var myArray = [["John", 23], ["cat", 2]]; +const myArray = [["John", 23], ["cat", 2]]; // Only change code below this line + ``` # --solutions-- ```js -var myArray = [["John", 23], ["cat", 2]]; +const myArray = [["John", 23], ["cat", 2]]; myArray.push(["dog",3]); ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/manipulating-complex-objects.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/manipulating-complex-objects.md index 592972f211..3c7f958fc4 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/manipulating-complex-objects.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/manipulating-complex-objects.md @@ -14,7 +14,7 @@ dashedName: manipulating-complex-objects Aqui está um exemplo de estrutura de dados complexas: ```js -var ourMusic = [ +const ourMusic = [ { "artist": "Daft Punk", "title": "Homework", @@ -135,7 +135,7 @@ myMusic.forEach(object => { ## --seed-contents-- ```js -var myMusic = [ +const myMusic = [ { "artist": "Billy Joel", "title": "Piano Man", @@ -153,7 +153,7 @@ var myMusic = [ # --solutions-- ```js -var myMusic = [ +const myMusic = [ { "artist": "Billy Joel", "title": "Piano Man", diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/multiple-identical-options-in-switch-statements.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/multiple-identical-options-in-switch-statements.md index 2d725d17f7..b36c8a09da 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/multiple-identical-options-in-switch-statements.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/multiple-identical-options-in-switch-statements.md @@ -12,7 +12,7 @@ dashedName: multiple-identical-options-in-switch-statements Se a instrução `break` for omitida de uma instrução `case` de um `switch`, as instruções `case` seguintes serão executadas até que seja encontrado um `break`. Se você tem várias entradas com a mesma saída, você pode representá-las em uma instrução `switch` da seguinte forma: ```js -var result = ""; +let result = ""; switch(val) { case 1: case 2: @@ -109,7 +109,7 @@ assert(code.match(/case/g).length === 9); ```js function sequentialSizes(val) { - var answer = ""; + let answer = ""; // Only change code below this line @@ -125,7 +125,7 @@ sequentialSizes(1); ```js function sequentialSizes(val) { - var answer = ""; + let answer = ""; switch(val) { case 1: diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-decimals-with-javascript.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-decimals-with-javascript.md index 6c77e1e2a0..168604e8d1 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-decimals-with-javascript.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-decimals-with-javascript.md @@ -42,11 +42,11 @@ assert(/\*/.test(code)); ## --seed-contents-- ```js -var product = 2.0 * 0.0; +const product = 2.0 * 0.0; ``` # --solutions-- ```js -var product = 2.0 * 2.5; +const product = 2.0 * 2.5; ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-numbers-with-javascript.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-numbers-with-javascript.md index f4c7329ff0..1260f4b802 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-numbers-with-javascript.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-numbers-with-javascript.md @@ -16,7 +16,7 @@ JavaScript usa o símbolo `*` para multiplicação de dois números. **Exemplo** ```js -myVar = 13 * 13; +const myVar = 13 * 13; ``` `myVar` teria o valor `169`. @@ -50,11 +50,11 @@ assert(/\*/.test(code)); ## --seed-contents-- ```js -var product = 8 * 0; +const product = 8 * 0; ``` # --solutions-- ```js -var product = 8 * 10; +const product = 8 * 10; ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/nest-one-array-within-another-array.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/nest-one-array-within-another-array.md index 1d70732ef8..19d0687fe9 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/nest-one-array-within-another-array.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/nest-one-array-within-another-array.md @@ -12,7 +12,7 @@ dashedName: nest-one-array-within-another-array Você também pode aninhar arrays dentro de outros arrays, como abaixo: ```js -[["Bulls", 23], ["White Sox", 45]] +const teams = [["Bulls", 23], ["White Sox", 45]]; ``` Isso é chamado um array multidimensional. @@ -41,11 +41,11 @@ if(typeof myArray !== "undefined"){(function(){return myArray;})();} ```js // Only change code below this line -var myArray = []; +const myArray = []; ``` # --solutions-- ```js -var myArray = [[1,2,3]]; +const myArray = [[1, 2, 3]]; ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/profile-lookup.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/profile-lookup.md index 61b354601b..dab980a96c 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/profile-lookup.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/profile-lookup.md @@ -68,34 +68,33 @@ assert(lookUpProfile('Akira', 'address') === 'No such property'); ```js // Setup -var contacts = [ - { - "firstName": "Akira", - "lastName": "Laine", - "number": "0543236543", - "likes": ["Pizza", "Coding", "Brownie Points"] - }, - { - "firstName": "Harry", - "lastName": "Potter", - "number": "0994372684", - "likes": ["Hogwarts", "Magic", "Hagrid"] - }, - { - "firstName": "Sherlock", - "lastName": "Holmes", - "number": "0487345643", - "likes": ["Intriguing Cases", "Violin"] - }, - { - "firstName": "Kristian", - "lastName": "Vos", - "number": "unknown", - "likes": ["JavaScript", "Gaming", "Foxes"] - } +const contacts = [ + { + firstName: "Akira", + lastName: "Laine", + number: "0543236543", + likes: ["Pizza", "Coding", "Brownie Points"], + }, + { + firstName: "Harry", + lastName: "Potter", + number: "0994372684", + likes: ["Hogwarts", "Magic", "Hagrid"], + }, + { + firstName: "Sherlock", + lastName: "Holmes", + number: "0487345643", + likes: ["Intriguing Cases", "Violin"], + }, + { + firstName: "Kristian", + lastName: "Vos", + number: "unknown", + likes: ["JavaScript", "Gaming", "Foxes"], + }, ]; - function lookUpProfile(name, prop) { // Only change code below this line @@ -108,44 +107,38 @@ lookUpProfile("Akira", "likes"); # --solutions-- ```js -var contacts = [ - { - "firstName": "Akira", - "lastName": "Laine", - "number": "0543236543", - "likes": ["Pizza", "Coding", "Brownie Points"] - }, - { - "firstName": "Harry", - "lastName": "Potter", - "number": "0994372684", - "likes": ["Hogwarts", "Magic", "Hagrid"] - }, - { - "firstName": "Sherlock", - "lastName": "Holmes", - "number": "0487345643", - "likes": ["Intriguing Cases", "Violin"] - }, - { - "firstName": "Kristian", - "lastName": "Vos", - "number": "unknown", - "likes": ["JavaScript", "Gaming", "Foxes"] - }, +const contacts = [ + { + firstName: "Akira", + lastName: "Laine", + number: "0543236543", + likes: ["Pizza", "Coding", "Brownie Points"], + }, + { + firstName: "Harry", + lastName: "Potter", + number: "0994372684", + likes: ["Hogwarts", "Magic", "Hagrid"], + }, + { + firstName: "Sherlock", + lastName: "Holmes", + number: "0487345643", + likes: ["Intriguing Cases", "Violin"], + }, + { + firstName: "Kristian", + lastName: "Vos", + number: "unknown", + likes: ["JavaScript", "Gaming", "Foxes"], + }, ]; - - -//Write your function in between these comments -function lookUpProfile(name, prop){ - for(var i in contacts){ - if(contacts[i].firstName === name) { - return contacts[i][prop] || "No such property"; - } +function lookUpProfile(name, prop) { + for (let i in contacts) { + if (contacts[i].firstName === name) { + return contacts[i][prop] || "No such property"; } - return "No such contact"; + } + return "No such contact"; } -//Write your function in between these comments - -lookUpProfile("Akira", "likes"); ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/quoting-strings-with-single-quotes.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/quoting-strings-with-single-quotes.md index 872ea6e039..cbe779ce0b 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/quoting-strings-with-single-quotes.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/quoting-strings-with-single-quotes.md @@ -12,21 +12,21 @@ dashedName: quoting-strings-with-single-quotes Valores de string em JavaScript podem ser escritas com aspas simples ou duplas, desde que você comece e termine com o mesmo tipo de aspas. Diferente de outras linguagens de programação, aspas simples e duplas funcionam da mesma forma em JavaScript. ```js -doubleQuoteStr = "This is a string"; -singleQuoteStr = 'This is also a string'; +const doubleQuoteStr = "This is a string"; +const singleQuoteStr = 'This is also a string'; ``` O motivo pelo qual você pode querer usar um tipo de aspas no lugar da outra é se você vir a querer usar ambas em uma string. Isso pode acontecer se você quiser salvar uma conversa em uma string e ter a conversa entre aspas. Outro uso para isso seria salvar uma tag `` com vários atributos em aspas, tudo dentro de uma string. ```js -conversation = 'Finn exclaims to Jake, "Algebraic!"'; +const conversation = 'Finn exclaims to Jake, "Algebraic!"'; ``` Porém, isso se torna um problema se você precisar usar as aspas mais extremas dentro dela. Lembre-se, uma string tem o mesmo tipo de aspas no início e no final. Mas se você tem aquela mesma aspa em algum lugar no meio, a string vai terminar mais cedo e lançará um erro. ```js -goodStr = 'Jake asks Finn, "Hey, let\'s go on an adventure?"'; -badStr = 'Finn responds, "Let's go!"'; +const goodStr = 'Jake asks Finn, "Hey, let\'s go on an adventure?"'; +const badStr = 'Finn responds, "Let's go!"'; ``` Aqui `badStr` lançará um erro. @@ -71,11 +71,11 @@ assert(code.match(/"/g).length === 4 && code.match(/'/g).length === 2); ## --seed-contents-- ```js -var myStr = "Link"; +const myStr = "Link"; ``` # --solutions-- ```js -var myStr = 'Link'; +const myStr = 'Link'; ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/record-collection.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/record-collection.md index 256e6325f7..bec11f1f66 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/record-collection.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/record-collection.md @@ -115,7 +115,7 @@ const _recordCollection = { ```js // Setup -var recordCollection = { +const recordCollection = { 2548: { albumTitle: 'Slippery When Wet', artist: 'Bon Jovi', @@ -146,7 +146,7 @@ updateRecords(recordCollection, 5439, 'artist', 'ABBA'); # --solutions-- ```js -var recordCollection = { +const recordCollection = { 2548: { albumTitle: 'Slippery When Wet', artist: 'Bon Jovi', diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/replace-loops-using-recursion.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/replace-loops-using-recursion.md index 4dfb3c5a33..c15779f5e0 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/replace-loops-using-recursion.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/replace-loops-using-recursion.md @@ -14,9 +14,9 @@ Recursão é o conceito de que uma função pode ser chamada por ela mesma. Para ```js function multiply(arr, n) { - var product = 1; - for (var i = 0; i < n; i++) { - product *= arr[i]; + let product = 1; + for (let i = 0; i < n; i++) { + product *= arr[i]; } return product; } diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/replacing-if-else-chains-with-switch.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/replacing-if-else-chains-with-switch.md index 3d3f58f14e..c08b94c7c6 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/replacing-if-else-chains-with-switch.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/replacing-if-else-chains-with-switch.md @@ -108,7 +108,7 @@ assert(chainToSwitch(156) === ''); ```js function chainToSwitch(val) { - var answer = ""; + let answer = ""; // Only change code below this line if (val === "bob") { @@ -134,7 +134,7 @@ chainToSwitch(7); ```js function chainToSwitch(val) { - var answer = ""; + let answer = ""; switch(val) { case "bob": diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/return-a-value-from-a-function-with-return.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/return-a-value-from-a-function-with-return.md index 6015e33980..b084ca43d8 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/return-a-value-from-a-function-with-return.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/return-a-value-from-a-function-with-return.md @@ -17,7 +17,8 @@ Nós podemos passar valores para uma função com argumentos. Você p function plusThree(num) { return num + 3; } -var answer = plusThree(5); + +const answer = plusThree(5); ``` `answer` tem o valor de `8`. diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/selecting-from-many-options-with-switch-statements.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/selecting-from-many-options-with-switch-statements.md index 13e07afff8..82c837dbda 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/selecting-from-many-options-with-switch-statements.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/selecting-from-many-options-with-switch-statements.md @@ -78,7 +78,7 @@ assert(code.match(/break/g).length > 2); ```js function caseInSwitch(val) { - var answer = ""; + let answer = ""; // Only change code below this line @@ -94,7 +94,7 @@ caseInSwitch(1); ```js function caseInSwitch(val) { - var answer = ""; + let answer = ""; switch(val) { case 1: diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/shopping-list.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/shopping-list.md index 9c108ac14d..9b7bfd86ef 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/shopping-list.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/shopping-list.md @@ -81,13 +81,13 @@ var hasNumber = false; ## --seed-contents-- ```js -var myList = []; +const myList = []; ``` # --solutions-- ```js -var myList = [ +const myList = [ ["Candy", 10], ["Potatoes", 12], ["Eggs", 12], diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/stand-in-line.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/stand-in-line.md index ff6f79a9c7..ed2c450625 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/stand-in-line.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/stand-in-line.md @@ -93,12 +93,10 @@ function nextInLine(arr, item) { return item; // Only change code above this line - - } // Setup -var testArr = [1,2,3,4,5]; +const testArr = [1, 2, 3, 4, 5]; // Display code console.log("Before: " + JSON.stringify(testArr)); @@ -109,7 +107,7 @@ console.log("After: " + JSON.stringify(testArr)); # --solutions-- ```js -var testArr = [ 1,2,3,4,5]; +const testArr = [1, 2, 3, 4, 5]; function nextInLine(arr, item) { arr.push(item); diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/store-multiple-values-in-one-variable-using-javascript-arrays.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/store-multiple-values-in-one-variable-using-javascript-arrays.md index 079b028a3e..07196097e6 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/store-multiple-values-in-one-variable-using-javascript-arrays.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/store-multiple-values-in-one-variable-using-javascript-arrays.md @@ -14,7 +14,7 @@ Com as variáveis de `array` em JavaScript, podemos armazenar diversos dados em Você começa uma declaração de um array com a abertura de um colchetes, terminando com o fechamento do colchetes e colocando vírgulas entre cada entrada, dessa forma: ```js -var sandwich = ["peanut butter", "jelly", "bread"] +const sandwich = ["peanut butter", "jelly", "bread"]; ``` # --instructions-- @@ -53,11 +53,11 @@ assert(typeof myArray[1] !== 'undefined' && typeof myArray[1] == 'number'); ```js // Only change code below this line -var myArray = []; +const myArray = []; ``` # --solutions-- ```js -var myArray = ["The Answer", 42]; +const myArray = ["The Answer", 42]; ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/subtract-one-number-from-another-with-javascript.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/subtract-one-number-from-another-with-javascript.md index 763f26cb6c..3310676788 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/subtract-one-number-from-another-with-javascript.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/subtract-one-number-from-another-with-javascript.md @@ -16,7 +16,7 @@ JavaScript usa o símbolo `-` para subtração. **Exemplo** ```js -myVar = 12 - 6; +const myVar = 12 - 6; ``` `myVar` teria o valor `6`. @@ -49,11 +49,11 @@ assert(/difference=45-33;?/.test(__helpers.removeWhiteSpace(code))); ## --seed-contents-- ```js -var difference = 45 - 0; +const difference = 45 - 0; ``` # --solutions-- ```js -var difference = 45 - 33; +const difference = 45 - 33; ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties.md index 27ed80eec0..2c8af2b05e 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties.md @@ -13,10 +13,11 @@ dashedName: testing-objects-for-properties **Exemplo** ```js -var myObj = { +const myObj = { top: "hat", bottom: "pants" }; + myObj.hasOwnProperty("top"); myObj.hasOwnProperty("middle"); ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/understand-string-immutability.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/understand-string-immutability.md index 58b01d3748..0ad2fe93dc 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/understand-string-immutability.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/understand-string-immutability.md @@ -14,14 +14,14 @@ Em JavaScript, valores `String` são imutáveis, o que significa que Por exemplo, o código a seguir: ```js -var myStr = "Bob"; +let myStr = "Bob"; myStr[0] = "J"; ``` não permite alterar o valor de `myStr` para `Job`, porque o conteúdo de `myStr` não pode ser alterado. Note que isso *não* significa que `myStr` não pode ser alterado, apenas que os caracteres individuais de uma string literal não podem ser alterados. A única forma de alterar `myStr` seria atribuindo a ela uma nova string, dessa forma: ```js -var myStr = "Bob"; +let myStr = "Bob"; myStr = "Job"; ``` @@ -55,7 +55,7 @@ assert(/myStr = "Jello World"/.test(code)); ```js // Setup -var myStr = "Jello World"; +let myStr = "Jello World"; // Only change code below this line myStr[0] = "H"; // Change this line @@ -65,6 +65,6 @@ myStr[0] = "H"; // Change this line # --solutions-- ```js -var myStr = "Jello World"; +let myStr = "Jello World"; myStr = "Hello World"; ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-boolean-values.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-boolean-values.md index d1240f035f..0d45f0d6a3 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-boolean-values.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-boolean-values.md @@ -43,7 +43,6 @@ welcomeToBooleans(); ```js function welcomeToBooleans() { - // Only change code below this line return false; // Change this line diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-undefined-value-returned-from-a-function.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-undefined-value-returned-from-a-function.md index 5c0ee20a1b..3230b281fe 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-undefined-value-returned-from-a-function.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-undefined-value-returned-from-a-function.md @@ -14,10 +14,12 @@ Uma função pode incluir a instrução `return` mas ela não precisa fazer isso **Exemplo** ```js -var sum = 0; +let sum = 0; + function addSum(num) { sum = sum + num; } + addSum(3); ``` @@ -61,7 +63,7 @@ assert( ```js // Setup -var sum = 0; +let sum = 0; function addThree() { sum = sum + 3; @@ -79,7 +81,7 @@ addFive(); # --solutions-- ```js -var sum = 0; +let sum = 0; function addThree() { sum = sum + 3; diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/updating-object-properties.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/updating-object-properties.md index fcf5f4f160..27e558a6bf 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/updating-object-properties.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/updating-object-properties.md @@ -14,7 +14,7 @@ Depois de criar um objeto JavaScript, você pode atualizar suas propriedades a q Por exemplo, vamos dar uma olhada em `ourDog`: ```js -var ourDog = { +const ourDog = { "name": "Camper", "legs": 4, "tails": 1, @@ -54,7 +54,7 @@ assert(/"name": "Coder"/.test(code)); ```js // Setup -var myDog = { +const myDog = { "name": "Coder", "legs": 4, "tails": 1, @@ -62,12 +62,13 @@ var myDog = { }; // Only change code below this line + ``` # --solutions-- ```js -var myDog = { +const myDog = { "name": "Coder", "legs": 4, "tails": 1, diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-nth-character-in-a-string.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-nth-character-in-a-string.md index 49ac129577..5b7d55bc90 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-nth-character-in-a-string.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-nth-character-in-a-string.md @@ -16,8 +16,8 @@ Lembre-se de que computadores começam contando do `0`. Então, o primeiro carac Exemplo: ```js -var firstName = "Ada"; -var secondLetterOfFirstName = firstName[1]; +const firstName = "Ada"; +const secondLetterOfFirstName = firstName[1]; ``` `secondLetterOfFirstName` teria o valor da string `d`. @@ -54,15 +54,15 @@ assert(code.match(/thirdLetterOfLastName\s*?=\s*?lastName\[.*?\]/)); ```js // Setup -var lastName = "Lovelace"; +const lastName = "Lovelace"; // Only change code below this line -var thirdLetterOfLastName = lastName; // Change this line +const thirdLetterOfLastName = lastName; // Change this line ``` # --solutions-- ```js -var lastName = "Lovelace"; -var thirdLetterOfLastName = lastName[2]; +const lastName = "Lovelace"; +const thirdLetterOfLastName = lastName[2]; ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/use-recursion-to-create-a-range-of-numbers.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/use-recursion-to-create-a-range-of-numbers.md index 8d4f0948e2..bea00af748 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/use-recursion-to-create-a-range-of-numbers.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/use-recursion-to-create-a-range-of-numbers.md @@ -73,7 +73,7 @@ function rangeOfNumbers(startNum, endNum) { if (endNum - startNum === 0) { return [startNum]; } else { - var numbers = rangeOfNumbers(startNum, endNum - 1); + const numbers = rangeOfNumbers(startNum, endNum - 1); numbers.push(endNum); return numbers; } diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function-with-a-radix.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function-with-a-radix.md index 81bd81106a..0ff735c10d 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function-with-a-radix.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function-with-a-radix.md @@ -20,7 +20,7 @@ parseInt(string, radix); Exemplo: ```js -var a = parseInt("11", 2); +const a = parseInt("11", 2); ``` A variável radix diz que `11` está no sistema binário, ou base 2. Esse exemplo converte a string `11` para um inteiro `3`. diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function.md index a48ab98937..6cad3010f5 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function.md @@ -12,7 +12,7 @@ dashedName: use-the-parseint-function A função `parseInt()` analisa uma string e retorna um inteiro. Exemplo: ```js -var a = parseInt("007"); +const a = parseInt("007"); ``` A função acima converte a string `007` para o inteiro `7`. Se o primeiro caractere na string não pode ser convertido em um número, então ele retorna `NaN`. diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/using-objects-for-lookups.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/using-objects-for-lookups.md index 6137d6f528..973e9af6f3 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/using-objects-for-lookups.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/using-objects-for-lookups.md @@ -14,7 +14,7 @@ Objetos podem ser pensados como armazenamento de chave/valor, como um dicionári Aqui está um exemplo de uma simples pesquisa reversa no alfabeto: ```js -var alpha = { +const alpha = { 1:"Z", 2:"Y", 3:"X", @@ -24,10 +24,11 @@ var alpha = { 25:"B", 26:"A" }; + alpha[2]; alpha[24]; -var value = 2; +const value = 2; alpha[value]; ``` @@ -102,7 +103,7 @@ assert( ```js // Setup function phoneticLookup(val) { - var result = ""; + let result = ""; // Only change code below this line switch(val) { @@ -136,9 +137,9 @@ phoneticLookup("charlie"); ```js function phoneticLookup(val) { - var result = ""; + let result = ""; - var lookup = { + const lookup = { alpha: "Adams", bravo: "Boston", charlie: "Chicago", diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/word-blanks.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/word-blanks.md index 19f327e8af..4b28d911f6 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/word-blanks.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/word-blanks.md @@ -16,7 +16,7 @@ Em um jogo de "Mad Libs", você recebe frases com algumas palavras faltando, com Considere a frase - Era realmente **\_\_\_\_** e nós **\_\_\_\_** nós mesmos **\_\_\_\_**. Essa frase possui três pedaços faltando - um adjetivo, um verbo e um advérbio, e nós podemos adicionar palavras de nossa escolha para completar. Em seguida, podemos atribuir a frase completa para uma variável como se segue: ```js -var sentence = "It was really " + "hot" + ", and we " + "laughed" + " ourselves " + "silly" + "."; +const sentence = "It was really " + "hot" + ", and we " + "laughed" + " ourselves " + "silly" + "."; ``` # --instructions-- @@ -84,24 +84,24 @@ const removeAssignments = str => str ## --seed-contents-- ```js -var myNoun = "dog"; -var myAdjective = "big"; -var myVerb = "ran"; -var myAdverb = "quickly"; +const myNoun = "dog"; +const myAdjective = "big"; +const myVerb = "ran"; +const myAdverb = "quickly"; // Only change code below this line -var wordBlanks = ""; // Change this line +const wordBlanks = ""; // Change this line // Only change code above this line ``` # --solutions-- ```js -var myNoun = "dog"; -var myAdjective = "big"; -var myVerb = "ran"; -var myAdverb = "quickly"; +const myNoun = "dog"; +const myAdjective = "big"; +const myVerb = "ran"; +const myAdverb = "quickly"; -var wordBlanks = "Once there was a " + myNoun + " which was very " + myAdjective + ". "; +let wordBlanks = "Once there was a " + myNoun + " which was very " + myAdjective + ". "; wordBlanks += "It " + myVerb + " " + myAdverb + " around the yard."; ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/add-elements-to-the-end-of-an-array-using-concat-instead-of-push.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/add-elements-to-the-end-of-an-array-using-concat-instead-of-push.md index 74ca32bb5a..3cab970012 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/add-elements-to-the-end-of-an-array-using-concat-instead-of-push.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/add-elements-to-the-end-of-an-array-using-concat-instead-of-push.md @@ -13,7 +13,7 @@ Programação funcional é basicamente criar e utilizar funções que não modif O último desafio mostrou como usar o método `concat` para criar um novo array a partir da combinação de outros sem modificar os originais. Compare os métodos `concat` e `push`. O `push` adiciona um item ao final do array à esquerda do `.`. Ele modifica o array. Exemplo: ```js -var arr = [1, 2, 3]; +const arr = [1, 2, 3]; arr.push([4, 5, 6]); ``` @@ -71,8 +71,9 @@ function nonMutatingPush(original, newItem) { // Only change code above this line } -var first = [1, 2, 3]; -var second = [4, 5]; + +const first = [1, 2, 3]; +const second = [4, 5]; nonMutatingPush(first, second); ``` @@ -82,7 +83,6 @@ nonMutatingPush(first, second); function nonMutatingPush(original, newItem) { return original.concat(newItem); } -var first = [1, 2, 3]; -var second = [4, 5]; -nonMutatingPush(first, second); +const first = [1, 2, 3]; +const second = [4, 5]; ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs.md index 95d7bb6c98..83daf61613 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs.md @@ -77,7 +77,6 @@ function urlSlug(title) { # --solutions-- ```js -// Only change code below this line function urlSlug(title) { return title.trim().split(/\s+/).join("-").toLowerCase(); } diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/avoid-mutations-and-side-effects-using-functional-programming.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/avoid-mutations-and-side-effects-using-functional-programming.md index c7cef37d22..91fa537088 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/avoid-mutations-and-side-effects-using-functional-programming.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/avoid-mutations-and-side-effects-using-functional-programming.md @@ -57,9 +57,9 @@ A função `incrementer` deve retornar um valor baseado no valor da variável gl ```js // The global variable -var fixedValue = 4; +let fixedValue = 4; -function incrementer () { +function incrementer() { // Only change code below this line @@ -70,7 +70,7 @@ function incrementer () { # --solutions-- ```js -var fixedValue = 4 +let fixedValue = 4 function incrementer() { return fixedValue + 1 diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/combine-an-array-into-a-string-using-the-join-method.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/combine-an-array-into-a-string-using-the-join-method.md index a0f7825272..d44460fcff 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/combine-an-array-into-a-string-using-the-join-method.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/combine-an-array-into-a-string-using-the-join-method.md @@ -13,8 +13,8 @@ O método `join` é usado para juntar os elementos de um array, resultando em um Exemplo: ```js -var arr = ["Hello", "World"]; -var str = arr.join(" "); +const arr = ["Hello", "World"]; +const str = arr.join(" "); ``` O valor de `str` é `Hello World`. @@ -76,6 +76,7 @@ function sentensify(str) { // Only change code above this line } + sentensify("May-the-force-be-with-you"); ``` @@ -83,8 +84,6 @@ sentensify("May-the-force-be-with-you"); ```js function sentensify(str) { - // Only change code below this line return str.split(/\W/).join(' '); - // Only change code above this line } ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/combine-two-arrays-using-the-concat-method.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/combine-two-arrays-using-the-concat-method.md index 5f2e3f0ec3..fe25f4f3fd 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/combine-two-arrays-using-the-concat-method.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/combine-two-arrays-using-the-concat-method.md @@ -60,8 +60,9 @@ function nonMutatingConcat(original, attach) { // Only change code above this line } -var first = [1, 2, 3]; -var second = [4, 5]; + +const first = [1, 2, 3]; +const second = [4, 5]; nonMutatingConcat(first, second); ``` @@ -69,11 +70,8 @@ nonMutatingConcat(first, second); ```js function nonMutatingConcat(original, attach) { - // Only change code below this line return original.concat(attach); - // Only change code above this line } -var first = [1, 2, 3]; -var second = [4, 5]; -nonMutatingConcat(first, second); +const first = [1, 2, 3]; +const second = [4, 5]; ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype.md index 9b054777b8..4bfd307fff 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype.md @@ -38,17 +38,17 @@ assert(!code.match(/\.?[\s\S]*?map/g)); ```js // The global variable -var s = [23, 65, 98, 5]; +const s = [23, 65, 98, 5]; Array.prototype.myMap = function(callback) { - var newArray = []; + const newArray = []; // Only change code below this line // Only change code above this line return newArray; }; -var new_s = s.myMap(function(item) { +const new_s = s.myMap(function(item) { return item * 2; }); ``` @@ -56,20 +56,17 @@ var new_s = s.myMap(function(item) { # --solutions-- ```js -// the global Array -var s = [23, 65, 98, 5]; +const s = [23, 65, 98, 5]; Array.prototype.myMap = function(callback) { - var newArray = []; - // Only change code below this line - for (var elem of this) { + const newArray = []; + for (const elem of this) { newArray.push(callback(elem)); } - // Only change code above this line return newArray; }; -var new_s = s.myMap(function(item) { +const new_s = s.myMap(function(item) { return item * 2; }); ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/implement-the-filter-method-on-a-prototype.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/implement-the-filter-method-on-a-prototype.md index 5936d42877..96fa45b4f6 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/implement-the-filter-method-on-a-prototype.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/implement-the-filter-method-on-a-prototype.md @@ -34,16 +34,16 @@ assert(!code.match(/\.?[\s\S]*?filter/g)); ```js // The global variable -var s = [23, 65, 98, 5]; +const s = [23, 65, 98, 5]; Array.prototype.myFilter = function(callback) { // Only change code below this line - var newArray = []; + const newArray = []; // Only change code above this line return newArray; }; -var new_s = s.myFilter(function(item) { +const new_s = s.myFilter(function(item) { return item % 2 === 1; }); ``` @@ -51,20 +51,17 @@ var new_s = s.myFilter(function(item) { # --solutions-- ```js -// the global Array -var s = [23, 65, 98, 5]; +const s = [23, 65, 98, 5]; Array.prototype.myFilter = function(callback) { - var newArray = []; - // Only change code below this line + const newArray = []; for (let i = 0; i < this.length; i++) { if (callback(this[i])) newArray.push(this[i]); } - // Only change code above this line return newArray; }; -var new_s = s.myFilter(function(item) { +const new_s = s.myFilter(function(item) { return item % 2 === 1; }); ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/introduction-to-currying-and-partial-application.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/introduction-to-currying-and-partial-application.md index f395576c8f..26826046c7 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/introduction-to-currying-and-partial-application.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/introduction-to-currying-and-partial-application.md @@ -35,7 +35,7 @@ curried(1)(2) Isso é útil em seu programa quando você não pode fornecer todos os argumentos para uma função de uma só vez. Você pode salvar cada chamada de função em uma variável, que será uma referência à função retornada que recebe o próximo argumento quando ele estiver disponível. Um exemplo usando a função do exemplo acima: ```js -var funcForY = curried(1); +const funcForY = curried(1); console.log(funcForY(2)); // 3 ``` @@ -45,7 +45,8 @@ Da mesma forma, aplicação parcial pode ser descrita como a aplicaç function impartial(x, y, z) { return x + y + z; } -var partialFn = impartial.bind(this, 1, 2); + +const partialFn = impartial.bind(this, 1, 2); partialFn(10); // 13 ``` @@ -90,6 +91,7 @@ function add(x) { // Only change code above this line } + add(10)(20)(30); ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/pass-arguments-to-avoid-external-dependence-in-a-function.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/pass-arguments-to-avoid-external-dependence-in-a-function.md index 8ff1c00492..573bc8acb0 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/pass-arguments-to-avoid-external-dependence-in-a-function.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/pass-arguments-to-avoid-external-dependence-in-a-function.md @@ -53,10 +53,10 @@ assert(__newValue === 5); ```js // The global variable -var fixedValue = 4; +let fixedValue = 4; // Only change code below this line -function incrementer () { +function incrementer() { // Only change code above this line @@ -66,15 +66,9 @@ function incrementer () { # --solutions-- ```js -// The global variable -var fixedValue = 4; +let fixedValue = 4; -// Only change code below this line -function incrementer (fixedValue) { +function incrementer(fixedValue) { return fixedValue + 1; - - // Only change code above this line } - - ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/remove-elements-from-an-array-using-slice-instead-of-splice.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/remove-elements-from-an-array-using-slice-instead-of-splice.md index add3158900..54d0a2f3e4 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/remove-elements-from-an-array-using-slice-instead-of-splice.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/remove-elements-from-an-array-using-slice-instead-of-splice.md @@ -11,7 +11,7 @@ dashedName: remove-elements-from-an-array-using-slice-instead-of-splice É comum precisar remover alguns itens de um array e manter o resto. O JavaScript oferece o método `splice`, que recebe uma posição de onde começar a remover e o número de elementos para remover como argumentos para isso. Se o segundo argumento for omitido, o padrão é remover todos os itens até o final. No entanto, o método `splice` modifica o array original em que é chamado. Exemplo: ```js -var cities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"]; +const cities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"]; cities.splice(3, 1); ``` @@ -69,7 +69,8 @@ function nonMutatingSplice(cities) { // Only change code above this line } -var inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"]; + +const inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"]; nonMutatingSplice(inputCities); ``` @@ -77,10 +78,7 @@ nonMutatingSplice(inputCities); ```js function nonMutatingSplice(cities) { - // Only change code below this line return cities.slice(0,3); - // Only change code above this line } -var inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"]; -nonMutatingSplice(inputCities); +const inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"]; ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/return-a-sorted-array-without-changing-the-original-array.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/return-a-sorted-array-without-changing-the-original-array.md index 54bcac4eb5..6d520e4dc7 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/return-a-sorted-array-without-changing-the-original-array.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/return-a-sorted-array-without-changing-the-original-array.md @@ -68,24 +68,23 @@ assert(JSON.stringify(nonMutatingSort([140000, 104, 99])) === ## --seed-contents-- ```js -var globalArray = [5, 6, 3, 2, 9]; +const globalArray = [5, 6, 3, 2, 9]; + function nonMutatingSort(arr) { // Only change code below this line // Only change code above this line } + nonMutatingSort(globalArray); ``` # --solutions-- ```js -var globalArray = [5, 6, 3, 2, 9]; +const globalArray = [5, 6, 3, 2, 9]; function nonMutatingSort(arr) { - // Only change code below this line return [].concat(arr).sort((a,b) => a-b); - // Only change code above this line } -nonMutatingSort(globalArray); ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/return-part-of-an-array-using-the-slice-method.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/return-part-of-an-array-using-the-slice-method.md index 79e0a6cfe5..884d555ac4 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/return-part-of-an-array-using-the-slice-method.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/return-part-of-an-array-using-the-slice-method.md @@ -13,8 +13,8 @@ O método `slice` retorna uma fatia de elementos de um array. Ele pode receber d Exemplo: ```js -var arr = ["Cat", "Dog", "Tiger", "Zebra"]; -var newArray = arr.slice(1, 3); +const arr = ["Cat", "Dog", "Tiger", "Zebra"]; +const newArray = arr.slice(1, 3); ``` `newArray` terá o valor `["Dog", "Tiger"]`. @@ -78,7 +78,8 @@ function sliceArray(anim, beginSlice, endSlice) { // Only change code above this line } -var inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"]; + +const inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"]; sliceArray(inputAnim, 1, 3); ``` @@ -86,10 +87,7 @@ sliceArray(inputAnim, 1, 3); ```js function sliceArray(anim, beginSlice, endSlice) { - // Only change code below this line - return anim.slice(beginSlice, endSlice) - // Only change code above this line + return anim.slice(beginSlice, endSlice); } -var inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"]; -sliceArray(inputAnim, 1, 3); +const inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"]; ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/sort-an-array-alphabetically-using-the-sort-method.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/sort-an-array-alphabetically-using-the-sort-method.md index 6e733a5bcb..33c39df3bb 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/sort-an-array-alphabetically-using-the-sort-method.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/sort-an-array-alphabetically-using-the-sort-method.md @@ -18,6 +18,7 @@ function ascendingOrder(arr) { return a - b; }); } + ascendingOrder([1, 5, 2, 3, 4]); ``` @@ -29,6 +30,7 @@ function reverseAlpha(arr) { return a === b ? 0 : a < b ? 1 : -1; }); } + reverseAlpha(['l', 'h', 'z', 'b', 's']); ``` @@ -86,6 +88,7 @@ function alphabeticalOrder(arr) { return arr // Only change code above this line } + alphabeticalOrder(["a", "d", "c", "a", "z", "g"]); ``` @@ -93,9 +96,6 @@ alphabeticalOrder(["a", "d", "c", "a", "z", "g"]); ```js function alphabeticalOrder(arr) { - // Only change code below this line return arr.sort(); - // Only change code above this line } -alphabeticalOrder(["a", "d", "c", "a", "z", "g"]); ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/split-a-string-into-an-array-using-the-split-method.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/split-a-string-into-an-array-using-the-split-method.md index 12ff08ab86..b0c70d668d 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/split-a-string-into-an-array-using-the-split-method.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/split-a-string-into-an-array-using-the-split-method.md @@ -13,11 +13,11 @@ O método `split` divide uma string em um array de strings. Ela recebe um delimi Abaixo há dois exemplos de uso de split, um separando uma string por espaços, e outro por dígitos usando uma expressão regular: ```js -var str = "Hello World"; -var bySpace = str.split(" "); +const str = "Hello World"; +const bySpace = str.split(" "); -var otherString = "How9are7you2today"; -var byDigits = otherString.split(/\d/); +const otherString = "How9are7you2today"; +const byDigits = otherString.split(/\d/); ``` `bySpace` terá o valor `["Hello", "World"]` e `byDigits` terá o valor `["How", "are", "you", "today"]`. @@ -74,6 +74,7 @@ function splitify(str) { // Only change code above this line } + splitify("Hello World,I-am code"); ``` @@ -81,8 +82,6 @@ splitify("Hello World,I-am code"); ```js function splitify(str) { - // Only change code below this line return str.split(/\W/); - // Only change code above this line } ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/understand-the-hazards-of-using-imperative-code.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/understand-the-hazards-of-using-imperative-code.md index 6504a860f3..9f5a8d1c36 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/understand-the-hazards-of-using-imperative-code.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/understand-the-hazards-of-using-imperative-code.md @@ -59,29 +59,29 @@ assert.deepEqual(finalTabs.tabs, [ ```js // tabs is an array of titles of each site open within the window -var Window = function(tabs) { +const Window = function(tabs) { this.tabs = tabs; // We keep a record of the array inside the object }; // When you join two windows into one window -Window.prototype.join = function (otherWindow) { +Window.prototype.join = function(otherWindow) { this.tabs = this.tabs.concat(otherWindow.tabs); return this; }; // When you open a new tab at the end -Window.prototype.tabOpen = function (tab) { +Window.prototype.tabOpen = function(tab) { this.tabs.push('new tab'); // Let's open a new tab for now return this; }; // When you close a tab -Window.prototype.tabClose = function (index) { +Window.prototype.tabClose = function(index) { // Only change code below this line - var tabsBeforeIndex = this.tabs.splice(0, index); // Get the tabs before the tab - var tabsAfterIndex = this.tabs.splice(index + 1); // Get the tabs after the tab + const tabsBeforeIndex = this.tabs.splice(0, index); // Get the tabs before the tab + const tabsAfterIndex = this.tabs.splice(index + 1); // Get the tabs after the tab this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // Join them together @@ -91,12 +91,12 @@ Window.prototype.tabClose = function (index) { }; // Let's create three browser windows -var workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); // Your mailbox, drive, and other work sites -var socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); // Social sites -var videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); // Entertainment sites +const workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); // Your mailbox, drive, and other work sites +const socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); // Social sites +const videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); // Entertainment sites // Now perform the tab opening, closing, and other operations -var finalTabs = socialWindow +const finalTabs = socialWindow .tabOpen() // Open a new tab for cat memes .join(videoWindow.tabClose(2)) // Close third tab in video window, and join .join(workWindow.tabClose(1).tabOpen()); @@ -106,40 +106,34 @@ console.log(finalTabs.tabs); # --solutions-- ```js -// tabs is an array of titles of each site open within the window -var Window = function(tabs) { - this.tabs = tabs; // We keep a record of the array inside the object +const Window = function(tabs) { + this.tabs = tabs; }; -// When you join two windows into one window -Window.prototype.join = function (otherWindow) { +Window.prototype.join = function(otherWindow) { this.tabs = this.tabs.concat(otherWindow.tabs); return this; }; -// When you open a new tab at the end -Window.prototype.tabOpen = function (tab) { - this.tabs.push('new tab'); // Let's open a new tab for now +Window.prototype.tabOpen = function(tab) { + this.tabs.push('new tab'); return this; }; -// When you close a tab -Window.prototype.tabClose = function (index) { - var tabsBeforeIndex = this.tabs.slice(0, index); // Get the tabs before the tab - var tabsAfterIndex = this.tabs.slice(index + 1); // Get the tabs after the tab +Window.prototype.tabClose = function(index) { + const tabsBeforeIndex = this.tabs.slice(0, index); + const tabsAfterIndex = this.tabs.slice(index + 1); - this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // Join them together + this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); return this; }; -// Let's create three browser windows -var workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); // Your mailbox, drive, and other work sites -var socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); // Social sites -var videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); // Entertainment sites +const workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); +const socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); +const videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); -// Now perform the tab opening, closing, and other operations -var finalTabs = socialWindow - .tabOpen() // Open a new tab for cat memes - .join(videoWindow.tabClose(2)) // Close third tab in video window, and join +const finalTabs = socialWindow + .tabOpen() + .join(videoWindow.tabClose(2)) .join(workWindow.tabClose(1).tabOpen()); ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria.md index e4582ceaf8..e060ee8e5d 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria.md @@ -13,7 +13,8 @@ O método `every` funciona verificando se *todos* os elementos de um array passa Por exemplo, o código a seguir verifica se todos os elementos no array `numbers` são menores que 10: ```js -var numbers = [1, 5, 8, 0, 10, 11]; +const numbers = [1, 5, 8, 0, 10, 11]; + numbers.every(function(currentValue) { return currentValue < 10; }); @@ -62,6 +63,7 @@ function checkPositive(arr) { // Only change code above this line } + checkPositive([1, 2, 3, -4, 5]); ``` @@ -69,9 +71,6 @@ checkPositive([1, 2, 3, -4, 5]); ```js function checkPositive(arr) { - // Only change code below this line return arr.every(num => num > 0); - // Only change code above this line } -checkPositive([1, 2, 3, -4, 5]); ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/use-the-reduce-method-to-analyze-data.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/use-the-reduce-method-to-analyze-data.md index 4b3fbd73b7..7ad02577d7 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/use-the-reduce-method-to-analyze-data.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/use-the-reduce-method-to-analyze-data.md @@ -93,7 +93,7 @@ assert(getRating(watchList.filter((_, i) => i < 1 || i > 2)) === 8.55); ```js // The global variable -var watchList = [ +const watchList = [ { "Title": "Inception", "Year": "2010", @@ -206,22 +206,22 @@ var watchList = [ } ]; -function getRating(watchList){ +function getRating(watchList) { // Only change code below this line - var averageRating; + let averageRating; // Only change code above this line return averageRating; } + console.log(getRating(watchList)); ``` # --solutions-- ```js -// The global variable -var watchList = [ +const watchList = [ { "Title": "Inception", "Year": "2010", @@ -334,8 +334,8 @@ var watchList = [ } ]; -function getRating(watchList){ - var averageRating; +function getRating(watchList) { + let averageRating; const rating = watchList .filter(obj => obj.Director === "Christopher Nolan") .map(obj => Number(obj.imdbRating)); diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/use-the-some-method-to-check-that-any-elements-in-an-array-meet-a-criteria.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/use-the-some-method-to-check-that-any-elements-in-an-array-meet-a-criteria.md index d0297e13c4..a2d55337a2 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/use-the-some-method-to-check-that-any-elements-in-an-array-meet-a-criteria.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/functional-programming/use-the-some-method-to-check-that-any-elements-in-an-array-meet-a-criteria.md @@ -13,7 +13,8 @@ O método `some` funciona verificando se *pelo menos um* dos elementos de um arr Por exemplo, o código a seguir verifica se qualquer elemento no array `numbers` é menor que 10: ```js -var numbers = [10, 50, 8, 220, 110, 11]; +const numbers = [10, 50, 8, 220, 110, 11]; + numbers.some(function(currentValue) { return currentValue < 10; }); @@ -62,6 +63,7 @@ function checkPositive(arr) { // Only change code above this line } + checkPositive([1, 2, 3, -4, 5]); ``` @@ -69,9 +71,6 @@ checkPositive([1, 2, 3, -4, 5]); ```js function checkPositive(arr) { - // Only change code below this line return arr.some(elem => elem > 0); - // Only change code above this line } -checkPositive([1, 2, 3, -4, 5]); ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays.md index 176f3a943a..87cec648df 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays.md @@ -157,7 +157,7 @@ assert(diffArray([1, 'calf', 3, 'piglet'], [7, 'filly']).length === 6); ```js function diffArray(arr1, arr2) { - var newArr = []; + const newArr = []; return newArr; } @@ -168,13 +168,12 @@ diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]); ```js function diffArray(arr1, arr2) { - var newArr = []; - var h1 = Object.create(null); + const newArr = []; + const h1 = Object.create(null); arr1.forEach(function(e) { h1[e] = e; }); - - var h2 = Object.create(null); + const h2 = Object.create(null); arr2.forEach(function(e) { h2[e] = e; }); diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/make-a-person.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/make-a-person.md index 0440792750..c2b1339d6d 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/make-a-person.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/make-a-person.md @@ -23,10 +23,19 @@ Execute os testes para ver a saída esperada para cada método. Os métodos que # --hints-- -`Object.keys(bob).length` deve retornar 6. +Nenhuma propriedade deve ser adicionada. `Object.keys(bob).length` deve sempre retornar 6. ```js -assert.deepEqual(Object.keys(bob).length, 6); +assert.strictEqual( + Object.keys((function () { + let bob = new Person('Bob Ross'); + bob.setFirstName('Haskell'); + bob.setLastName('Curry'); + bob.setFullName('John Smith'); + return bob; + })()).length, + 6 + ); ``` `bob instanceof Pessoa` deve retornar `true`. @@ -139,7 +148,7 @@ if(bob){ ## --seed-contents-- ```js -var Person = function(firstAndLast) { +const Person = function(firstAndLast) { // Only change code below this line // Complete the method below and implement the others similarly this.getFullName = function() { @@ -148,16 +157,16 @@ var Person = function(firstAndLast) { return firstAndLast; }; -var bob = new Person('Bob Ross'); +const bob = new Person('Bob Ross'); bob.getFullName(); ``` # --solutions-- ```js -var Person = function(firstAndLast) { +const Person = function(firstAndLast) { - var firstName, lastName; + let firstName, lastName; function updateName(str) { firstName = str.split(" ")[0]; @@ -192,6 +201,6 @@ var Person = function(firstAndLast) { }; }; -var bob = new Person('Bob Ross'); +const bob = new Person('Bob Ross'); bob.getFullName(); ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/map-the-debris.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/map-the-debris.md index 5d7e434445..ffbbd4805e 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/map-the-debris.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/map-the-debris.md @@ -51,8 +51,8 @@ assert.deepEqual( ```js function orbitalPeriod(arr) { - var GM = 398600.4418; - var earthRadius = 6367.4447; + const GM = 398600.4418; + const earthRadius = 6367.4447; return arr; } @@ -63,9 +63,9 @@ orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]); ```js function orbitalPeriod(arr) { - var GM = 398600.4418; - var earthRadius = 6367.4447; - var TAU = 2 * Math.PI; + const GM = 398600.4418; + const earthRadius = 6367.4447; + const TAU = 2 * Math.PI; return arr.map(function(obj) { return { name: obj.name, @@ -73,6 +73,4 @@ function orbitalPeriod(arr) { }; }); } - -orbitalPeriod([{name : "sputkin", avgAlt : 35873.5553}]); ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple.md index 4991be8782..46a74b2584 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple.md @@ -61,7 +61,6 @@ function smallestCommons(arr) { return arr; } - smallestCommons([1,5]); ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou.md index afdff0e631..4191a51121 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou.md @@ -103,7 +103,7 @@ assert.deepEqual( ```js function whatIsInAName(collection, source) { - var arr = []; + const arr = []; // Only change code below this line @@ -118,8 +118,8 @@ whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: ```js function whatIsInAName(collection, source) { - var arr = []; - var keys = Object.keys(source); + const arr = []; + const keys = Object.keys(source); collection.forEach(function(e) { if(keys.every(function(key) {return e[key] === source[key];})) { arr.push(e); diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/caesars-cipher.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/caesars-cipher.md index a5aa3e63ce..a5795068b3 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/caesars-cipher.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/caesars-cipher.md @@ -51,7 +51,6 @@ assert( ```js function rot13(str) { - return str; } diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/cash-register.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/cash-register.md index 283ed15f2b..4ddb07a518 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/cash-register.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/cash-register.md @@ -186,7 +186,7 @@ assert.deepEqual( ```js function checkCashRegister(price, cash, cid) { - var change; + let change; return change; } @@ -196,54 +196,57 @@ checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], [ # --solutions-- ```js -var denom = [ - { name: 'ONE HUNDRED', val: 100}, - { name: 'TWENTY', val: 20}, - { name: 'TEN', val: 10}, - { name: 'FIVE', val: 5}, - { name: 'ONE', val: 1}, - { name: 'QUARTER', val: 0.25}, - { name: 'DIME', val: 0.1}, - { name: 'NICKEL', val: 0.05}, - { name: 'PENNY', val: 0.01} +const denom = [ + { name: "ONE HUNDRED", val: 100 }, + { name: "TWENTY", val: 20 }, + { name: "TEN", val: 10 }, + { name: "FIVE", val: 5 }, + { name: "ONE", val: 1 }, + { name: "QUARTER", val: 0.25 }, + { name: "DIME", val: 0.1 }, + { name: "NICKEL", val: 0.05 }, + { name: "PENNY", val: 0.01 }, ]; function checkCashRegister(price, cash, cid) { - var output = {status: null, change: []}; - var change = cash - price; - var register = cid.reduce(function(acc, curr) { - acc.total += curr[1]; - acc[curr[0]] = curr[1]; - return acc; - }, {total: 0}); - if(register.total === change) { - output.status = 'CLOSED'; - output.change = cid; - return output; - } - if(register.total < change) { - output.status = 'INSUFFICIENT_FUNDS'; - return output; - } - var change_arr = denom.reduce(function(acc, curr) { - var value = 0; - while(register[curr.name] > 0 && change >= curr.val) { - change -= curr.val; - register[curr.name] -= curr.val; - value += curr.val; - change = Math.round(change * 100) / 100; - } - if(value > 0) { - acc.push([ curr.name, value ]); - } - return acc; - }, []); - if(change_arr.length < 1 || change > 0) { - output.status = 'INSUFFICIENT_FUNDS'; - return output; - } - output.status = 'OPEN'; - output.change = change_arr; - return output; + const output = { status: null, change: [] }; + let change = cash - price; + const register = cid.reduce( + function (acc, curr) { + acc.total += curr[1]; + acc[curr[0]] = curr[1]; + return acc; + }, + { total: 0 } + ); + if (register.total === change) { + output.status = "CLOSED"; + output.change = cid; + return output; + } + if (register.total < change) { + output.status = "INSUFFICIENT_FUNDS"; + return output; + } + const change_arr = denom.reduce(function (acc, curr) { + let value = 0; + while (register[curr.name] > 0 && change >= curr.val) { + change -= curr.val; + register[curr.name] -= curr.val; + value += curr.val; + change = Math.round(change * 100) / 100; + } + if (value > 0) { + acc.push([curr.name, value]); + } + return acc; + }, []); + if (change_arr.length < 1 || change > 0) { + output.status = "INSUFFICIENT_FUNDS"; + return output; + } + output.status = "OPEN"; + output.change = change_arr; + return output; } ``` diff --git a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/palindrome-checker.md b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/palindrome-checker.md index ed254b9ac9..2582b57d2f 100644 --- a/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/palindrome-checker.md +++ b/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/palindrome-checker.md @@ -107,8 +107,6 @@ function palindrome(str) { return true; } - - palindrome("eye"); ``` diff --git a/curriculum/challenges/portuguese/03-front-end-development-libraries/front-end-development-libraries-projects/build-a-markdown-previewer.md b/curriculum/challenges/portuguese/03-front-end-development-libraries/front-end-development-libraries-projects/build-a-markdown-previewer.md index 11b9de70eb..73c349f709 100644 --- a/curriculum/challenges/portuguese/03-front-end-development-libraries/front-end-development-libraries-projects/build-a-markdown-previewer.md +++ b/curriculum/challenges/portuguese/03-front-end-development-libraries/front-end-development-libraries-projects/build-a-markdown-previewer.md @@ -22,7 +22,7 @@ Você pode usar qualquer mistura de HTML, JavaScript, CSS, Bootstrap, SASS, Reac **Especificação de usuário nº 4:** quando insiro marcação do GitHub no elemento `#editor`, o texto é renderizado como HTML no elemento `#preview` enquanto eu escrevo (DICA: você não precisa analisar a marcação você mesmo - você pode importar a biblioteca Marked para isso: ). -**Especificação de usuário nº 5:** quando meu pré-visualizador de marcação carregar pela primeira vez, o texto padrão no campo `#editor` deve conter uma marcação válida que represente pelo menos um de cada um dos elementos a seguir: um header (tamanho H1), um subheader (tamanho H2), um link, um código em linha, um código de bloco, uma lista de item, um blockquote, uma imagem e um texto em negrito. +**Especificação de usuário nº 5:** quando meu pré-visualizador de marcação carregar pela primeira vez, o texto padrão no campo `#editor` deve conter uma marcação válida que represente pelo menos um de cada um dos elementos a seguir: um elemento (tamanho H1), um subelemento de título (tamanho H2), um link, um código em linha, um código de bloco, uma lista de item, um blockquote, uma imagem e um texto em negrito. **Especificação de usuário nº 6:** quando meu pré-visualizador de marcação carregar pela primeira vez, a marcação padrão no campo `#editor` deve ser renderizada como HTML no elemento `#preview`. diff --git a/curriculum/challenges/portuguese/03-front-end-development-libraries/react/access-props-using-this.props.md b/curriculum/challenges/portuguese/03-front-end-development-libraries/react/access-props-using-this.props.md index 49d8f70179..ab80387e9b 100644 --- a/curriculum/challenges/portuguese/03-front-end-development-libraries/react/access-props-using-this.props.md +++ b/curriculum/challenges/portuguese/03-front-end-development-libraries/react/access-props-using-this.props.md @@ -14,67 +14,54 @@ Sempre que você se refere a um componente de classe dentro dele mesmo, você us # --instructions-- -Renderize uma instância do componente `ReturnTempPassword` no componente parente `ResetPassword`. Aqui, dê a `ReturnTempPassword` à prop `tempPassword` e atribua a ela o valor de uma string que tenha pelo menos 8 caracteres. Dentro do filho, `ReturnTempPassword`, acesse a prop `tempPassword` dentro das tags `strong` para certificar-se que o usuário veja a senha temporária. +Renderize uma instância do componente `Welcome` no componente parente `App`. Aqui, dê a `Welcome` uma "prop" `name` e atribua a ela um valor de uma string. Dentro do elemento filho, `Welcome`, acesse a propriedade `name` dentro das tags `strong`. # --hints-- -O componente `ResetPassword` deve retornar um único elemento `div`. +O componente `App` deve retornar um único elemento `div`. ```js assert( (function () { - const mockedComponent = Enzyme.mount(React.createElement(ResetPassword)); + const mockedComponent = Enzyme.mount(React.createElement(App)); return mockedComponent.children().type() === 'div'; })() ); ``` -O quarto filho de `ResetPassword` deve ser o componente `ReturnTempPassword`. +O elemento filho de `App` deve ser o componente `Welcome`. ```js assert( (function () { - const mockedComponent = Enzyme.mount(React.createElement(ResetPassword)); + const mockedComponent = Enzyme.mount(React.createElement(App)); return ( - mockedComponent.children().childAt(3).name() === 'ReturnTempPassword' + mockedComponent.children().childAt(0).name() === 'Welcome' ); })() ); ``` -O componente `ReturnTempPassword` deve ter uma prop chamada `tempPassword`. +O componente `Welcome` deve ter uma prop chamada `name`. ```js assert( (function () { - const mockedComponent = Enzyme.mount(React.createElement(ResetPassword)); - return mockedComponent.find('ReturnTempPassword').props().tempPassword; + const mockedComponent = Enzyme.mount(React.createElement(App)); + return mockedComponent.find('Welcome').props().name; })() ); ``` -A prop `tempPassword` de `ReturnTempPassword` deve ser igual uma string de pelo menos 8 caracteres. +O componente `Welcome` deve exibir a string que você passou como a prop `name` dentro das tags `strong`. ```js assert( (function () { - const mockedComponent = Enzyme.mount(React.createElement(ResetPassword)); - const temp = mockedComponent.find('ReturnTempPassword').props() - .tempPassword; - return typeof temp === 'string' && temp.length >= 8; - })() -); -``` - -O componente `ReturnTempPassword` deve exibir a senha que você criou como a prop `tempPassword` dentro das tags `strong`. - -```js -assert( - (function () { - const mockedComponent = Enzyme.mount(React.createElement(ResetPassword)); + const mockedComponent = Enzyme.mount(React.createElement(App)); return ( mockedComponent.find('strong').text() === - mockedComponent.find('ReturnTempPassword').props().tempPassword + mockedComponent.find('Welcome').props().name ); })() ); @@ -85,13 +72,13 @@ assert( ## --after-user-code-- ```jsx -ReactDOM.render(, document.getElementById('root')) +ReactDOM.render(, document.getElementById('root')) ``` ## --seed-contents-- ```jsx -class ReturnTempPassword extends React.Component { +class App extends React.Component { constructor(props) { super(props); @@ -100,14 +87,14 @@ class ReturnTempPassword extends React.Component { return (
{ /* Change code below this line */ } -

Your temporary password is:

+ { /* Change code above this line */ }
); } }; -class ResetPassword extends React.Component { +class Welcome extends React.Component { constructor(props) { super(props); @@ -115,11 +102,8 @@ class ResetPassword extends React.Component { render() { return (
-

Reset Password

-

We've generated a new temporary password for you.

-

Please reset this password from your account settings ASAP.

{ /* Change code below this line */ } - +

Hello, !

{ /* Change code above this line */ }
); @@ -130,7 +114,7 @@ class ResetPassword extends React.Component { # --solutions-- ```jsx -class ReturnTempPassword extends React.Component { +class Welcome extends React.Component { constructor(props) { super(props); @@ -138,28 +122,27 @@ class ReturnTempPassword extends React.Component { render() { return (
-

Your temporary password is: {this.props.tempPassword}

-
- ); - } -}; - -class ResetPassword extends React.Component { - constructor(props) { - super(props); - - } - render() { - return ( -
-

Reset Password

-

We've generated a new temporary password for you.

-

Please reset this password from your account settings ASAP.

{ /* Change code below this line */ } - +

Hello, {this.props.name}!

{ /* Change code above this line */ }
); } }; + +class App extends React.Component { + constructor(props) { + super(props); + + } + render() { + return ( +
+ { /* Change code below this line */ } + + { /* Change code above this line */ } +
+ ); + } +}; ``` diff --git a/curriculum/challenges/portuguese/03-front-end-development-libraries/react/compose-react-components.md b/curriculum/challenges/portuguese/03-front-end-development-libraries/react/compose-react-components.md index bd8348bd7e..0ec0809f81 100644 --- a/curriculum/challenges/portuguese/03-front-end-development-libraries/react/compose-react-components.md +++ b/curriculum/challenges/portuguese/03-front-end-development-libraries/react/compose-react-components.md @@ -14,7 +14,7 @@ Enquanto os desafios continuam a usar composições mais complexas com component No editor de código, o componente `TypesOfFood` já está renderizando um componente chamado `Vegetables`. Além disso, há o componente `Fruits` do último desafio. -Aninhe dois componentes dentro de `Fruits` — primeiro `NonCitrus`, e depois `Citrus`. Ambos os componentes são fornecidos nos bastidores. Em seguida, aninhe o componente de classe `Fruits` dentro do componente `TypesOfFood`, abaixo do cabeçalho `h1` e acima de `Vegetables`. O resultado deve ser uma série de componentes aninhados, que usa dois tipos de componentes diferentes. +Aninhe dois componentes dentro de `Fruits` — primeiro `NonCitrus`, e depois `Citrus`. Ambos os componentes são fornecidos nos bastidores. Em seguida, aninhe o componente de classe `Fruits` dentro do componente `TypesOfFood`, abaixo do elemento de título `h1` e acima de `Vegetables`. O resultado deve ser uma série de componentes aninhados, que usa dois tipos de componentes diferentes. # --hints-- diff --git a/curriculum/challenges/portuguese/03-front-end-development-libraries/react/create-a-controlled-form.md b/curriculum/challenges/portuguese/03-front-end-development-libraries/react/create-a-controlled-form.md index 1ee0593fbd..25f93e75cf 100644 --- a/curriculum/challenges/portuguese/03-front-end-development-libraries/react/create-a-controlled-form.md +++ b/curriculum/challenges/portuguese/03-front-end-development-libraries/react/create-a-controlled-form.md @@ -109,7 +109,7 @@ assert( ); ``` -O título `h1` deve renderizar o valor do campo `submit` do estado do componente. +O elemento de título `h1` deve renderizar o valor do campo `submit` do estado do componente. ```js (() => { diff --git a/curriculum/challenges/portuguese/03-front-end-development-libraries/react/create-a-react-component.md b/curriculum/challenges/portuguese/03-front-end-development-libraries/react/create-a-react-component.md index a123ce7cc7..b06f7b3308 100644 --- a/curriculum/challenges/portuguese/03-front-end-development-libraries/react/create-a-react-component.md +++ b/curriculum/challenges/portuguese/03-front-end-development-libraries/react/create-a-react-component.md @@ -38,7 +38,7 @@ O componente React deve retornar um elemento `div`. assert(Enzyme.shallow(React.createElement(MyComponent)).type() === 'div'); ``` -A `div` retornada deve renderizar um título `h1` dentro dele. +A `div` retornada deve renderizar um elemento de título `h1` dentro dele. ```js assert( @@ -48,7 +48,7 @@ assert( ); ``` -O título `h1` deve conter a string `Hello React!`. +O elemento de título `h1` deve conter a string `Hello React!`. ```js assert( diff --git a/curriculum/challenges/portuguese/03-front-end-development-libraries/react/render-state-in-the-user-interface-another-way.md b/curriculum/challenges/portuguese/03-front-end-development-libraries/react/render-state-in-the-user-interface-another-way.md index b711aee1c5..4a96203184 100644 --- a/curriculum/challenges/portuguese/03-front-end-development-libraries/react/render-state-in-the-user-interface-another-way.md +++ b/curriculum/challenges/portuguese/03-front-end-development-libraries/react/render-state-in-the-user-interface-another-way.md @@ -27,7 +27,7 @@ assert( ); ``` -`MyComponent` deve renderizar um título `h1` que está dentro de um único `div`. +`MyComponent` deve renderizar um elemento de título `h1` que está dentro de um único `div`. ```js assert( @@ -44,7 +44,7 @@ A tag `h1` renderizada deve ter uma referência a `{name}`. assert(/

\n*\s*\{\s*name\s*\}\s*\n*<\/h1>/.test(getUserInput('index'))); ``` -O título `h1` renderizado deve conter apenas texto renderizado do estado do componente. +O elemento de título `h1` renderizado deve conter apenas texto renderizado do estado do componente. ```js async () => { diff --git a/curriculum/challenges/portuguese/03-front-end-development-libraries/react/render-state-in-the-user-interface.md b/curriculum/challenges/portuguese/03-front-end-development-libraries/react/render-state-in-the-user-interface.md index 56604246e1..6b8c7aae11 100644 --- a/curriculum/challenges/portuguese/03-front-end-development-libraries/react/render-state-in-the-user-interface.md +++ b/curriculum/challenges/portuguese/03-front-end-development-libraries/react/render-state-in-the-user-interface.md @@ -33,7 +33,7 @@ assert( ); ``` -`MyComponent` deve renderizar um título `h1` que está dentro de um único `div`. +`MyComponent` deve renderizar um elemento de título `h1` que está dentro de um único `div`. ```js assert( @@ -43,7 +43,7 @@ assert( ); ``` -O título `h1` renderizado deve conter apenas texto renderizado do estado do componente. +O elemento de título `h1` renderizado deve conter apenas texto renderizado do estado do componente. ```js async () => { diff --git a/curriculum/challenges/portuguese/03-front-end-development-libraries/react/set-state-with-this.setstate.md b/curriculum/challenges/portuguese/03-front-end-development-libraries/react/set-state-with-this.setstate.md index a3e26d5e0a..95d02d99e7 100644 --- a/curriculum/challenges/portuguese/03-front-end-development-libraries/react/set-state-with-this.setstate.md +++ b/curriculum/challenges/portuguese/03-front-end-development-libraries/react/set-state-with-this.setstate.md @@ -35,13 +35,13 @@ assert( ); ``` -`MyComponent` deve retornar um título `h1`. +`MyComponent` deve retornar um elemento de título `h1`. ```js assert(Enzyme.mount(React.createElement(MyComponent)).find('h1').length === 1); ``` -O título `h1` renderizado deve conter apenas texto renderizado do estado do componente. +O elemento de título `h1` renderizado deve conter apenas texto renderizado do estado do componente. ```js async () => { diff --git a/curriculum/challenges/portuguese/05-back-end-development-and-apis/basic-node-and-express/use-the-.env-file.md b/curriculum/challenges/portuguese/05-back-end-development-and-apis/basic-node-and-express/use-the-.env-file.md index 29531b1d6d..ccb30068d6 100644 --- a/curriculum/challenges/portuguese/05-back-end-development-and-apis/basic-node-and-express/use-the-.env-file.md +++ b/curriculum/challenges/portuguese/05-back-end-development-and-apis/basic-node-and-express/use-the-.env-file.md @@ -22,6 +22,8 @@ Em seguida, no manipulador de rota `/json` do GET que você criou no último des **Observação:** se você estiver usando o Replit, você não poderá criar um arquivo `.env`. Em vez disso, use a aba embutida SECRETS para adicionar a variável. +Se você estiver trabalhando localmente, precisará do pacote `dotenv`. Ele carrega as variáveis de ambiente do seu arquivo `.env` em `process.env`. Instale-o com `npm install dotenv`. Em seguida, na parte superior do seu arquivo `myApp.js`, importe e carregue as variáveis com `require('dotenv').config()`. + # --hints-- A resposta do endpoint `/json` deve ser alterada de acordo com a variável de ambiente `MESSAGE_STYLE` diff --git a/curriculum/challenges/portuguese/10-coding-interview-prep/data-structures/delete-a-leaf-node-in-a-binary-search-tree.md b/curriculum/challenges/portuguese/10-coding-interview-prep/data-structures/delete-a-leaf-node-in-a-binary-search-tree.md index 65a3cb21ff..a6c71d5b4a 100644 --- a/curriculum/challenges/portuguese/10-coding-interview-prep/data-structures/delete-a-leaf-node-in-a-binary-search-tree.md +++ b/curriculum/challenges/portuguese/10-coding-interview-prep/data-structures/delete-a-leaf-node-in-a-binary-search-tree.md @@ -46,6 +46,25 @@ assert( ); ``` +Tentar remover um elemento de uma árvore vazia deve retornar `null`. + +```js +assert( + (function () { + var test = false; + if (typeof BinarySearchTree !== 'undefined') { + test = new BinarySearchTree(); + } else { + return false; + } + if (typeof test.remove !== 'function') { + return false; + } + return test.remove(100) == null; + })() +); +``` + Tentar remover um elemento que não existe deve retornar `null`. ```js @@ -60,6 +79,8 @@ assert( if (typeof test.remove !== 'function') { return false; } + test.add(15); + test.add(30); return test.remove(100) == null; })() ); diff --git a/curriculum/challenges/portuguese/10-coding-interview-prep/project-euler/problem-14-longest-collatz-sequence.md b/curriculum/challenges/portuguese/10-coding-interview-prep/project-euler/problem-14-longest-collatz-sequence.md index 42c0555768..ecc0ec5348 100644 --- a/curriculum/challenges/portuguese/10-coding-interview-prep/project-euler/problem-14-longest-collatz-sequence.md +++ b/curriculum/challenges/portuguese/10-coding-interview-prep/project-euler/problem-14-longest-collatz-sequence.md @@ -22,7 +22,7 @@ Podemos ver que essa sequência (começando em 13 e terminando em 1) contém 10 Qual número inicial, sob o `limit` (limite) definido, produz a sequência mais longa? -**Observação:** uma vez iniciada, os termos na sequência podem passar de um milhão. +**Observação:** uma vez iniciada, os termos na sequência podem passar acima do `limit`. # --hints--