diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/boo-who.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/boo-who.md index 4a3296deb5..23b048b60c 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/boo-who.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/boo-who.md @@ -8,67 +8,67 @@ dashedName: boo-who # --description-- -Check if a value is classified as a boolean primitive. Return true or false. +Check if a value is classified as a boolean primitive. Return `true` or `false`. -Boolean primitives are true and false. +Boolean primitives are `true` and `false`. # --hints-- -`booWho(true)` should return true. +`booWho(true)` should return `true`. ```js assert.strictEqual(booWho(true), true); ``` -`booWho(false)` should return true. +`booWho(false)` should return `true`. ```js assert.strictEqual(booWho(false), true); ``` -`booWho([1, 2, 3])` should return false. +`booWho([1, 2, 3])` should return `false`. ```js assert.strictEqual(booWho([1, 2, 3]), false); ``` -`booWho([].slice)` should return false. +`booWho([].slice)` should return `false`. ```js assert.strictEqual(booWho([].slice), false); ``` -`booWho({ "a": 1 })` should return false. +`booWho({ "a": 1 })` should return `false`. ```js assert.strictEqual(booWho({ a: 1 }), false); ``` -`booWho(1)` should return false. +`booWho(1)` should return `false`. ```js assert.strictEqual(booWho(1), false); ``` -`booWho(NaN)` should return false. +`booWho(NaN)` should return `false`. ```js assert.strictEqual(booWho(NaN), false); ``` -`booWho("a")` should return false. +`booWho("a")` should return `false`. ```js assert.strictEqual(booWho('a'), false); ``` -`booWho("true")` should return false. +`booWho("true")` should return `false`. ```js assert.strictEqual(booWho('true'), false); ``` -`booWho("false")` should return false. +`booWho("false")` should return `false`. ```js assert.strictEqual(booWho('false'), false); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/confirm-the-ending.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/confirm-the-ending.md index 2ee2ca3712..a793811b43 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/confirm-the-ending.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/confirm-the-ending.md @@ -14,25 +14,25 @@ This challenge *can* be solved with the `.endsWith()` method, which was introduc # --hints-- -`confirmEnding("Bastian", "n")` should return true. +`confirmEnding("Bastian", "n")` should return `true`. ```js assert(confirmEnding('Bastian', 'n') === true); ``` -`confirmEnding("Congratulation", "on")` should return true. +`confirmEnding("Congratulation", "on")` should return `true`. ```js assert(confirmEnding('Congratulation', 'on') === true); ``` -`confirmEnding("Connor", "n")` should return false. +`confirmEnding("Connor", "n")` should return `false`. ```js assert(confirmEnding('Connor', 'n') === false); ``` -`confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification")` should return false. +`confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification")` should return `false`. ```js assert( @@ -43,31 +43,31 @@ assert( ); ``` -`confirmEnding("He has to give me a new name", "name")` should return true. +`confirmEnding("He has to give me a new name", "name")` should return `true`. ```js assert(confirmEnding('He has to give me a new name', 'name') === true); ``` -`confirmEnding("Open sesame", "same")` should return true. +`confirmEnding("Open sesame", "same")` should return `true`. ```js assert(confirmEnding('Open sesame', 'same') === true); ``` -`confirmEnding("Open sesame", "sage")` should return false. +`confirmEnding("Open sesame", "sage")` should return `false`. ```js assert(confirmEnding('Open sesame', 'sage') === false); ``` -`confirmEnding("Open sesame", "game")` should return false. +`confirmEnding("Open sesame", "game")` should return `false`. ```js assert(confirmEnding('Open sesame', 'game') === false); ``` -`confirmEnding("If you want to save our world, you must hurry. We dont know how much longer we can withstand the nothing", "mountain")` should return false. +`confirmEnding("If you want to save our world, you must hurry. We dont know how much longer we can withstand the nothing", "mountain")` should return `false`. ```js assert( @@ -78,7 +78,7 @@ assert( ); ``` -`confirmEnding("Abstraction", "action")` should return true. +`confirmEnding("Abstraction", "action")` should return `true`. ```js assert(confirmEnding('Abstraction', 'action') === true); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/factorialize-a-number.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/factorialize-a-number.md index 06d29b3b13..5a884cff9d 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/factorialize-a-number.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/factorialize-a-number.md @@ -10,7 +10,7 @@ dashedName: factorialize-a-number Return the factorial of the provided integer. -If the integer is represented with the letter n, a factorial is the product of all positive integers less than or equal to n. +If the integer is represented with the letter `n`, a factorial is the product of all positive integers less than or equal to `n`. Factorials are often represented with the shorthand notation `n!` @@ -26,25 +26,25 @@ Only integers greater than or equal to zero will be supplied to the function. assert(typeof factorialize(5) === 'number'); ``` -`factorialize(5)` should return 120. +`factorialize(5)` should return `120`. ```js assert(factorialize(5) === 120); ``` -`factorialize(10)` should return 3628800. +`factorialize(10)` should return `3628800`. ```js assert(factorialize(10) === 3628800); ``` -`factorialize(20)` should return 2432902008176640000. +`factorialize(20)` should return `2432902008176640000`. ```js assert(factorialize(20) === 2432902008176640000); ``` -`factorialize(0)` should return 1. +`factorialize(0)` should return `1`. ```js assert(factorialize(0) === 1); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/find-the-longest-word-in-a-string.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/find-the-longest-word-in-a-string.md index 1e587b787c..cc62bb4c9f 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/find-the-longest-word-in-a-string.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/find-the-longest-word-in-a-string.md @@ -24,7 +24,7 @@ assert( ); ``` -`findLongestWordLength("The quick brown fox jumped over the lazy dog")` should return 6. +`findLongestWordLength("The quick brown fox jumped over the lazy dog")` should return `6`. ```js assert( @@ -32,19 +32,19 @@ assert( ); ``` -`findLongestWordLength("May the force be with you")` should return 5. +`findLongestWordLength("May the force be with you")` should return `5`. ```js assert(findLongestWordLength('May the force be with you') === 5); ``` -`findLongestWordLength("Google do a barrel roll")` should return 6. +`findLongestWordLength("Google do a barrel roll")` should return `6`. ```js assert(findLongestWordLength('Google do a barrel roll') === 6); ``` -`findLongestWordLength("What is the average airspeed velocity of an unladen swallow")` should return 8. +`findLongestWordLength("What is the average airspeed velocity of an unladen swallow")` should return `8`. ```js assert( @@ -54,7 +54,7 @@ assert( ); ``` -`findLongestWordLength("What if we try a super-long word such as otorhinolaryngology")` should return 19. +`findLongestWordLength("What if we try a super-long word such as otorhinolaryngology")` should return `19`. ```js assert( diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/finders-keepers.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/finders-keepers.md index 6760acd660..6bfd7139fc 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/finders-keepers.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/finders-keepers.md @@ -12,7 +12,7 @@ Create a function that looks through an array `arr` and returns the first elemen # --hints-- -`findElement([1, 3, 5, 8, 9, 10], function(num) { return num % 2 === 0; })` should return 8. +`findElement([1, 3, 5, 8, 9, 10], function(num) { return num % 2 === 0; })` should return `8`. ```js assert.strictEqual( @@ -23,7 +23,7 @@ assert.strictEqual( ); ``` -`findElement([1, 3, 5, 9], function(num) { return num % 2 === 0; })` should return undefined. +`findElement([1, 3, 5, 9], function(num) { return num % 2 === 0; })` should return `undefined`. ```js assert.strictEqual( diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/mutations.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/mutations.md index a3b6017238..99da5fd90b 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/mutations.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/mutations.md @@ -8,83 +8,83 @@ dashedName: mutations # --description-- -Return true if the string in the first element of the array contains all of the letters of the string in the second element of the array. +Return `true` if the string in the first element of the array contains all of the letters of the string in the second element of the array. -For example, `["hello", "Hello"]`, should return true because all of the letters in the second string are present in the first, ignoring case. +For example, `["hello", "Hello"]`, should return `true` because all of the letters in the second string are present in the first, ignoring case. -The arguments `["hello", "hey"]` should return false because the string "hello" does not contain a "y". +The arguments `["hello", "hey"]` should return `false` because the string `hello` does not contain a `y`. -Lastly, `["Alien", "line"]`, should return true because all of the letters in "line" are present in "Alien". +Lastly, `["Alien", "line"]`, should return `true` because all of the letters in `line` are present in `Alien`. # --hints-- -`mutation(["hello", "hey"])` should return false. +`mutation(["hello", "hey"])` should return `false`. ```js assert(mutation(['hello', 'hey']) === false); ``` -`mutation(["hello", "Hello"])` should return true. +`mutation(["hello", "Hello"])` should return `true`. ```js assert(mutation(['hello', 'Hello']) === true); ``` -`mutation(["zyxwvutsrqponmlkjihgfedcba", "qrstu"])` should return true. +`mutation(["zyxwvutsrqponmlkjihgfedcba", "qrstu"])` should return `true`. ```js assert(mutation(['zyxwvutsrqponmlkjihgfedcba', 'qrstu']) === true); ``` -`mutation(["Mary", "Army"])` should return true. +`mutation(["Mary", "Army"])` should return `true`. ```js assert(mutation(['Mary', 'Army']) === true); ``` -`mutation(["Mary", "Aarmy"])` should return true. +`mutation(["Mary", "Aarmy"])` should return `true`. ```js assert(mutation(['Mary', 'Aarmy']) === true); ``` -`mutation(["Alien", "line"])` should return true. +`mutation(["Alien", "line"])` should return `true`. ```js assert(mutation(['Alien', 'line']) === true); ``` -`mutation(["floor", "for"])` should return true. +`mutation(["floor", "for"])` should return `true`. ```js assert(mutation(['floor', 'for']) === true); ``` -`mutation(["hello", "neo"])` should return false. +`mutation(["hello", "neo"])` should return `false`. ```js assert(mutation(['hello', 'neo']) === false); ``` -`mutation(["voodoo", "no"])` should return false. +`mutation(["voodoo", "no"])` should return `false`. ```js assert(mutation(['voodoo', 'no']) === false); ``` -`mutation(["ate", "date"]` should return false. +`mutation(["ate", "date"])` should return `false`. ```js assert(mutation(['ate', 'date']) === false); ``` -`mutation(["Tiger", "Zebra"])` should return false. +`mutation(["Tiger", "Zebra"])` should return `false`. ```js assert(mutation(['Tiger', 'Zebra']) === false); ``` -`mutation(["Noel", "Ole"])` should return true. +`mutation(["Noel", "Ole"])` should return `true`. ```js assert(mutation(['Noel', 'Ole']) === true); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/repeat-a-string-repeat-a-string.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/repeat-a-string-repeat-a-string.md index f00c1a2536..d7349722c0 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/repeat-a-string-repeat-a-string.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/repeat-a-string-repeat-a-string.md @@ -12,37 +12,37 @@ Repeat a given string `str` (first argument) for `num` times (second argument). # --hints-- -`repeatStringNumTimes("*", 3)` should return `"***"`. +`repeatStringNumTimes("*", 3)` should return the string `***`. ```js assert(repeatStringNumTimes('*', 3) === '***'); ``` -`repeatStringNumTimes("abc", 3)` should return `"abcabcabc"`. +`repeatStringNumTimes("abc", 3)` should return the string `abcabcabc`. ```js assert(repeatStringNumTimes('abc', 3) === 'abcabcabc'); ``` -`repeatStringNumTimes("abc", 4)` should return `"abcabcabcabc"`. +`repeatStringNumTimes("abc", 4)` should return the string `abcabcabcabc`. ```js assert(repeatStringNumTimes('abc', 4) === 'abcabcabcabc'); ``` -`repeatStringNumTimes("abc", 1)` should return `"abc"`. +`repeatStringNumTimes("abc", 1)` should return the string `abc`. ```js assert(repeatStringNumTimes('abc', 1) === 'abc'); ``` -`repeatStringNumTimes("*", 8)` should return `"********"`. +`repeatStringNumTimes("*", 8)` should return the string `********`. ```js assert(repeatStringNumTimes('*', 8) === '********'); ``` -`repeatStringNumTimes("abc", -2)` should return `""`. +`repeatStringNumTimes("abc", -2)` should return an empty string (`""`). ```js assert(repeatStringNumTimes('abc', -2) === ''); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/reverse-a-string.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/reverse-a-string.md index 3e44678ceb..0e948fbe9f 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/reverse-a-string.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/reverse-a-string.md @@ -22,19 +22,19 @@ Your result must be a string. assert(typeof reverseString('hello') === 'string'); ``` -`reverseString("hello")` should become `"olleh"`. +`reverseString("hello")` should return the string `olleh`. ```js assert(reverseString('hello') === 'olleh'); ``` -`reverseString("Howdy")` should become `"ydwoH"`. +`reverseString("Howdy")` should return the string `ydwoH`. ```js assert(reverseString('Howdy') === 'ydwoH'); ``` -`reverseString("Greetings from Earth")` should return `"htraE morf sgniteerG"`. +`reverseString("Greetings from Earth")` should return the string `htraE morf sgniteerG`. ```js assert(reverseString('Greetings from Earth') === 'htraE morf sgniteerG'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/title-case-a-sentence.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/title-case-a-sentence.md index 4d155143d3..0dc778c8a4 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/title-case-a-sentence.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/title-case-a-sentence.md @@ -10,7 +10,7 @@ dashedName: title-case-a-sentence Return the provided string with the first letter of each word capitalized. Make sure the rest of the word is in lower case. -For the purpose of this exercise, you should also capitalize connecting words like "the" and "of". +For the purpose of this exercise, you should also capitalize connecting words like `the` and `of`. # --hints-- @@ -20,19 +20,19 @@ For the purpose of this exercise, you should also capitalize connecting words li assert(typeof titleCase("I'm a little tea pot") === 'string'); ``` -`titleCase("I'm a little tea pot")` should return `I'm A Little Tea Pot`. +`titleCase("I'm a little tea pot")` should return the string `I'm A Little Tea Pot`. ```js assert(titleCase("I'm a little tea pot") === "I'm A Little Tea Pot"); ``` -`titleCase("sHoRt AnD sToUt")` should return `Short And Stout`. +`titleCase("sHoRt AnD sToUt")` should return the string `Short And Stout`. ```js assert(titleCase('sHoRt AnD sToUt') === 'Short And Stout'); ``` -`titleCase("HERE IS MY HANDLE HERE IS MY SPOUT")` should return `Here Is My Handle Here Is My Spout`. +`titleCase("HERE IS MY HANDLE HERE IS MY SPOUT")` should return the string `Here Is My Handle Here Is My Spout`. ```js assert( diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/truncate-a-string.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/truncate-a-string.md index c32c069878..bb6270d4a8 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/truncate-a-string.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/truncate-a-string.md @@ -12,7 +12,7 @@ Truncate a string (first argument) if it is longer than the given maximum string # --hints-- -`truncateString("A-tisket a-tasket A green and yellow basket", 8)` should return "A-tisket...". +`truncateString("A-tisket a-tasket A green and yellow basket", 8)` should return the string `A-tisket...`. ```js assert( @@ -21,7 +21,7 @@ assert( ); ``` -`truncateString("Peter Piper picked a peck of pickled peppers", 11)` should return "Peter Piper...". +`truncateString("Peter Piper picked a peck of pickled peppers", 11)` should return the string `Peter Piper...`. ```js assert( @@ -30,7 +30,7 @@ assert( ); ``` -`truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length)` should return "A-tisket a-tasket A green and yellow basket". +`truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length)` should return the string `A-tisket a-tasket A green and yellow basket`. ```js assert( @@ -41,7 +41,7 @@ assert( ); ``` -`truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length + 2)` should return "A-tisket a-tasket A green and yellow basket". +`truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length + 2)` should return the string `A-tisket a-tasket A green and yellow basket`. ```js assert( @@ -52,13 +52,13 @@ assert( ); ``` -`truncateString("A-", 1)` should return "A...". +`truncateString("A-", 1)` should return the string `A...`. ```js assert(truncateString('A-', 1) === 'A...'); ``` -`truncateString("Absolutely Longer", 2)` should return "Ab...". +`truncateString("Absolutely Longer", 2)` should return the string `Ab...`. ```js assert(truncateString('Absolutely Longer', 2) === 'Ab...'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/access-an-arrays-contents-using-bracket-notation.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/access-an-arrays-contents-using-bracket-notation.md index 482d2c5236..4f03872562 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/access-an-arrays-contents-using-bracket-notation.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/access-an-arrays-contents-using-bracket-notation.md @@ -16,47 +16,47 @@ When we define a simple array as seen below, there are 3 items in it: let ourArray = ["a", "b", "c"]; ``` -In an array, each array item has an index. This index doubles as the position of that item in the array, and how you reference it. However, it is important to note, that JavaScript arrays are zero-indexed, meaning that the first element of an array is actually at the ***zeroth*** position, not the first. In order to retrieve an element from an array we can enclose an index in brackets and append it to the end of an array, or more commonly, to a variable which references an array object. This is known as bracket notation. For example, if we want to retrieve the `"a"` from `ourArray` and assign it to a variable, we can do so with the following code: +In an array, each array item has an index. This index doubles as the position of that item in the array, and how you reference it. However, it is important to note, that JavaScript arrays are zero-indexed, meaning that the first element of an array is actually at the ***zeroth*** position, not the first. In order to retrieve an element from an array we can enclose an index in brackets and append it to the end of an array, or more commonly, to a variable which references an array object. This is known as bracket notation. For example, if we want to retrieve the `a` from `ourArray` and assign it to a variable, we can do so with the following code: ```js let ourVariable = ourArray[0]; -// ourVariable equals "a" ``` +Now `ourVariable` has the value of `a`. + In addition to accessing the value associated with an index, you can also *set* an index to a value using the same notation: ```js ourArray[1] = "not b anymore"; -// ourArray now equals ["a", "not b anymore", "c"]; ``` -Using bracket notation, we have now reset the item at index 1 from `"b"`, to `"not b anymore"`. +Using bracket notation, we have now reset the item at index 1 from the string `b`, to `not b anymore`. Now `ourArray` is `["a", "not b anymore", "c"]`. # --instructions-- -In order to complete this challenge, set the 2nd position (index `1`) of `myArray` to anything you want, besides `"b"`. +In order to complete this challenge, set the 2nd position (index `1`) of `myArray` to anything you want, besides the letter `b`. # --hints-- -`myArray[0]` should be equal to `"a"` +`myArray[0]` should be equal to the letter `a` ```js assert.strictEqual(myArray[0], 'a'); ``` -`myArray[1]` should not be equal to `"b"` +`myArray[1]` should not be equal to the letter `b` ```js assert.notStrictEqual(myArray[1], 'b'); ``` -`myArray[2]` should be equal to `"c"` +`myArray[2]` should be equal to the letter `c` ```js assert.strictEqual(myArray[2], 'c'); ``` -`myArray[3]` should be equal to `"d"` +`myArray[3]` should be equal to the letter `d` ```js assert.strictEqual(myArray[3], 'd'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/add-items-to-an-array-with-push-and-unshift.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/add-items-to-an-array-with-push-and-unshift.md index afd8dff124..81963c6d7e 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/add-items-to-an-array-with-push-and-unshift.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/add-items-to-an-array-with-push-and-unshift.md @@ -17,12 +17,16 @@ let twentyThree = 'XXIII'; let romanNumerals = ['XXI', 'XXII']; romanNumerals.unshift('XIX', 'XX'); -// now equals ['XIX', 'XX', 'XXI', 'XXII'] - -romanNumerals.push(twentyThree); -// now equals ['XIX', 'XX', 'XXI', 'XXII', 'XXIII']Notice that we can also pass variables, which allows us even greater flexibility in dynamically modifying our array's data. ``` +`romanNumerals` would have the value `['XIX', 'XX', 'XXI', 'XXII']`. + +```js +romanNumerals.push(twentyThree); +``` + +`romanNumerals` would have the value `['XIX', 'XX', 'XXI', 'XXII', 'XXIII']`. Notice that we can also pass variables, which allows us even greater flexibility in dynamically modifying our array's data. + # --instructions-- We have defined a function, `mixedNumbers`, which we are passing an array as an argument. Modify the function by using `push()` and `unshift()` to add `'I', 2, 'three'` to the beginning of the array and `7, 'VIII', 9` to the end so that the returned array contains representations of the numbers 1-9 in order. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/add-items-using-splice.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/add-items-using-splice.md index 04a8878555..782fb3d101 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/add-items-using-splice.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/add-items-using-splice.md @@ -16,11 +16,11 @@ const startIndex = 3; const amountToDelete = 1; numbers.splice(startIndex, amountToDelete, 13, 14); -// the second entry of 12 is removed, and we add 13 and 14 at the same index console.log(numbers); -// returns [ 10, 11, 12, 13, 14, 15 ] ``` +The second entry of `12` is removed, and we add `13` and `14` at the same index. The `numbers` array would now be `[ 10, 11, 12, 13, 14, 15 ]`. + Here, we begin with an array of numbers. Then, we pass the following to `splice()`: The index at which to begin deleting elements (3), the number of elements to be deleted (1), and the remaining arguments (13, 14) will be inserted starting at that same index. Note that there can be any number of elements (separated by commas) following `amountToDelete`, each of which gets inserted. # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/add-key-value-pairs-to-javascript-objects.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/add-key-value-pairs-to-javascript-objects.md index f5adc6e51b..5bec1202db 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/add-key-value-pairs-to-javascript-objects.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/add-key-value-pairs-to-javascript-objects.md @@ -63,19 +63,19 @@ A `foods` object has been created with three entries. Using the syntax of your c assert(typeof foods === 'object'); ``` -The `foods` object should have a key `"bananas"` with a value of `13`. +The `foods` object should have a key `bananas` with a value of `13`. ```js assert(foods.bananas === 13); ``` -The `foods` object should have a key `"grapes"` with a value of `35`. +The `foods` object should have a key `grapes` with a value of `35`. ```js assert(foods.grapes === 35); ``` -The `foods` object should have a key `"strawberries"` with a value of `27`. +The `foods` object should have a key `strawberries` with a value of `27`. ```js assert(foods.strawberries === 27); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/check-for-the-presence-of-an-element-with-indexof.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/check-for-the-presence-of-an-element-with-indexof.md index 4bc028927f..e9a2f2dbb1 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/check-for-the-presence-of-an-element-with-indexof.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/check-for-the-presence-of-an-element-with-indexof.md @@ -15,11 +15,13 @@ For example: ```js let fruits = ['apples', 'pears', 'oranges', 'peaches', 'pears']; -fruits.indexOf('dates'); // returns -1 -fruits.indexOf('oranges'); // returns 2 -fruits.indexOf('pears'); // returns 1, the first index at which the element exists +fruits.indexOf('dates'); +fruits.indexOf('oranges'); +fruits.indexOf('pears'); ``` +`indexOf('dates')` returns `-1`, `indexOf('oranges')` returns `2`, and `indexOf('pears')` returns `1` (the first index at which each element exists). + # --instructions-- `indexOf()` can be incredibly useful for quickly checking for the presence of an element on an array. We have defined a function, `quickCheck`, that takes an array and an element as arguments. Modify the function using `indexOf()` so that it returns `true` if the passed element exists on the array, and `false` if it does not. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/check-if-an-object-has-a-property.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/check-if-an-object-has-a-property.md index e2ac0392eb..ff59bec03f 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/check-if-an-object-has-a-property.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/check-if-an-object-has-a-property.md @@ -13,9 +13,10 @@ Now we can add, modify, and remove keys from objects. But what if we just wanted ```js users.hasOwnProperty('Alan'); 'Alan' in users; -// both return true ``` +Both of these would return `true`. + # --instructions-- We've created an object, `users`, with some users in it and a function `isEveryoneHere`, which we pass the `users` object to as an argument. Finish writing this function so that it returns `true` only if the `users` object contains all four names, `Alan`, `Jeff`, `Sarah`, and `Ryan`, as keys, and `false` otherwise. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/combine-arrays-with-the-spread-operator.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/combine-arrays-with-the-spread-operator.md index 0a27f7bb09..6cec90e34d 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/combine-arrays-with-the-spread-operator.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/combine-arrays-with-the-spread-operator.md @@ -8,15 +8,16 @@ dashedName: combine-arrays-with-the-spread-operator # --description-- -Another huge advantage of the spread operator, is the ability to combine arrays, or to insert all the elements of one array into another, at any index. With more traditional syntaxes, we can concatenate arrays, but this only allows us to combine arrays at the end of one, and at the start of another. Spread syntax makes the following operation extremely simple: +Another huge advantage of the spread operator is the ability to combine arrays, or to insert all the elements of one array into another, at any index. With more traditional syntaxes, we can concatenate arrays, but this only allows us to combine arrays at the end of one, and at the start of another. Spread syntax makes the following operation extremely simple: ```js let thisArray = ['sage', 'rosemary', 'parsley', 'thyme']; let thatArray = ['basil', 'cilantro', ...thisArray, 'coriander']; -// thatArray now equals ['basil', 'cilantro', 'sage', 'rosemary', 'parsley', 'thyme', 'coriander'] ``` +`thatArray` would have the value `['basil', 'cilantro', 'sage', 'rosemary', 'parsley', 'thyme', 'coriander']`. + Using spread syntax, we have just achieved an operation that would have been more complex and more verbose had we used traditional methods. # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/copy-an-array-with-the-spread-operator.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/copy-an-array-with-the-spread-operator.md index ca3aa490b5..912149a303 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/copy-an-array-with-the-spread-operator.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/copy-an-array-with-the-spread-operator.md @@ -15,10 +15,10 @@ In practice, we can use the spread operator to copy an array like so: ```js let thisArray = [true, true, undefined, false, null]; let thatArray = [...thisArray]; -// thatArray equals [true, true, undefined, false, null] -// thisArray remains unchanged and thatArray contains the same elements as thisArray ``` +`thatArray` equals `[true, true, undefined, false, null]`. `thisArray` remains unchanged and `thatArray` contains the same elements as `thisArray`. + # --instructions-- We have defined a function, `copyMachine` which takes `arr` (an array) and `num` (a number) as arguments. The function is supposed to return a new array made up of `num` copies of `arr`. We have done most of the work for you, but it doesn't work quite right yet. Modify the function using spread syntax so that it works correctly (hint: another method we have already covered might come in handy here!). diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/copy-array-items-using-slice.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/copy-array-items-using-slice.md index 54ba5bade9..325439ea9a 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/copy-array-items-using-slice.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/copy-array-items-using-slice.md @@ -14,15 +14,15 @@ The next method we will cover is `slice()`. Rather than modifying an array, `sli let weatherConditions = ['rain', 'snow', 'sleet', 'hail', 'clear']; let todaysWeather = weatherConditions.slice(1, 3); -// todaysWeather equals ['snow', 'sleet']; -// weatherConditions still equals ['rain', 'snow', 'sleet', 'hail', 'clear'] ``` +`todaysWeather` would have the value `['snow', 'sleet']`, while `weatherConditions` would still have `['rain', 'snow', 'sleet', 'hail', 'clear']`. + In effect, we have created a new array by extracting elements from an existing array. # --instructions-- -We have defined a function, `forecast`, that takes an array as an argument. Modify the function using `slice()` to extract information from the argument array and return a new array that contains the elements `'warm'` and `'sunny'`. +We have defined a function, `forecast`, that takes an array as an argument. Modify the function using `slice()` to extract information from the argument array and return a new array that contains the string elements `warm` and `sunny`. # --hints-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/create-complex-multi-dimensional-arrays.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/create-complex-multi-dimensional-arrays.md index d15e24bcd4..4f33c93637 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/create-complex-multi-dimensional-arrays.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/create-complex-multi-dimensional-arrays.md @@ -13,43 +13,45 @@ Awesome! You have just learned a ton about arrays! This has been a fairly high l One of the most powerful features when thinking of arrays as data structures, is that arrays can contain, or even be completely made up of other arrays. We have seen arrays that contain arrays in previous challenges, but fairly simple ones. However, arrays can contain an infinite depth of arrays that can contain other arrays, each with their own arbitrary levels of depth, and so on. In this way, an array can very quickly become very complex data structure, known as a multi-dimensional, or nested array. Consider the following example: ```js -let nestedArray = [ // top, or first level - the outer most array - ['deep'], // an array within an array, 2 levels of depth +let nestedArray = [ + ['deep'], [ - ['deeper'], ['deeper'] // 2 arrays nested 3 levels deep + ['deeper'], ['deeper'] ], [ [ - ['deepest'], ['deepest'] // 2 arrays nested 4 levels deep + ['deepest'], ['deepest'] ], [ [ - ['deepest-est?'] // an array nested 5 levels deep + ['deepest-est?'] ] ] ] ]; ``` +The `deep` array is nested 2 levels deep. The `deeper` arrays are 3 levels deep. The `deepest` arrays are 4 levels, and the `deepest-est?` is 5. + While this example may seem convoluted, this level of complexity is not unheard of, or even unusual, when dealing with large amounts of data. However, we can still very easily access the deepest levels of an array this complex with bracket notation: ```js console.log(nestedArray[2][1][0][0][0]); -// logs: deepest-est? ``` -And now that we know where that piece of data is, we can reset it if we need to: +This logs the string `deepest-est?`. And now that we know where that piece of data is, we can reset it if we need to: ```js nestedArray[2][1][0][0][0] = 'deeper still'; console.log(nestedArray[2][1][0][0][0]); -// now logs: deeper still ``` +Now it logs `deeper still`. + # --instructions-- -We have defined a variable, `myNestedArray`, set equal to an array. Modify `myNestedArray`, using any combination of strings, numbers, and booleans for data elements, so that it has exactly five levels of depth (remember, the outer-most array is level 1). Somewhere on the third level, include the string `'deep'`, on the fourth level, include the string `'deeper'`, and on the fifth level, include the string `'deepest'`. +We have defined a variable, `myNestedArray`, set equal to an array. Modify `myNestedArray`, using any combination of strings, numbers, and booleans for data elements, so that it has exactly five levels of depth (remember, the outer-most array is level 1). Somewhere on the third level, include the string `deep`, on the fourth level, include the string `deeper`, and on the fifth level, include the string `deepest`. # --hints-- @@ -100,7 +102,7 @@ assert.strictEqual( ); ``` -`myNestedArray` should contain exactly one occurrence of the string `"deep"` on an array nested 3 levels deep +`myNestedArray` should contain exactly one occurrence of the string `deep` on an array nested 3 levels deep ```js assert( @@ -129,7 +131,7 @@ assert( ); ``` -`myNestedArray` should contain exactly one occurrence of the string `"deeper"` on an array nested 4 levels deep +`myNestedArray` should contain exactly one occurrence of the string `deeper` on an array nested 4 levels deep ```js assert( @@ -158,7 +160,7 @@ assert( ); ``` -`myNestedArray` should contain exactly one occurrence of the string `"deepest"` on an array nested 5 levels deep +`myNestedArray` should contain exactly one occurrence of the string `deepest` on an array nested 5 levels deep ```js assert( diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/iterate-through-all-an-arrays-items-using-for-loops.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/iterate-through-all-an-arrays-items-using-for-loops.md index 6674711f21..25a7f5363c 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/iterate-through-all-an-arrays-items-using-for-loops.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/iterate-through-all-an-arrays-items-using-for-loops.md @@ -24,10 +24,9 @@ function greaterThanTen(arr) { } greaterThanTen([2, 12, 8, 14, 80, 0, 1]); -// returns [12, 14, 80] ``` -Using a `for` loop, this function iterates through and accesses each element of the array, and subjects it to a simple test that we have created. In this way, we have easily and programmatically determined which data items are greater than `10`, and returned a new array containing those items. +Using a `for` loop, this function iterates through and accesses each element of the array, and subjects it to a simple test that we have created. In this way, we have easily and programmatically determined which data items are greater than `10`, and returned a new array, `[12, 14, 80]`, containing those items. # --instructions-- @@ -35,7 +34,7 @@ We have defined a function, `filteredArray`, which takes `arr`, a nested array, # --hints-- -`filteredArray([[10, 8, 3], [14, 6, 23], [3, 18, 6]], 18)` should return `[ [10, 8, 3], [14, 6, 23] ]` +`filteredArray([[10, 8, 3], [14, 6, 23], [3, 18, 6]], 18)` should return `[[10, 8, 3], [14, 6, 23]]` ```js assert.deepEqual( @@ -54,7 +53,7 @@ assert.deepEqual( ); ``` -`filteredArray([ ["trumpets", 2], ["flutes", 4], ["saxophones", 2] ], 2)` should return `[ ["flutes", 4] ]` +`filteredArray([["trumpets", 2], ["flutes", 4], ["saxophones", 2]], 2)` should return `[["flutes", 4]]` ```js assert.deepEqual( @@ -70,7 +69,7 @@ assert.deepEqual( ); ``` -`filteredArray([ ["amy", "beth", "sam"], ["dave", "sean", "peter"] ], "peter")` should return `[ ["amy", "beth", "sam"] ]` +`filteredArray([["amy", "beth", "sam"], ["dave", "sean", "peter"]], "peter")` should return `[["amy", "beth", "sam"]]` ```js assert.deepEqual( @@ -85,7 +84,7 @@ assert.deepEqual( ); ``` -`filteredArray([[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 3, 9]], 3)` should return `[ ]` +`filteredArray([[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 3, 9]], 3)` should return `[]` ```js assert.deepEqual( diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/iterate-through-the-keys-of-an-object-with-a-for...in-statement.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/iterate-through-the-keys-of-an-object-with-a-for...in-statement.md index 390132b504..5f2b085b6b 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/iterate-through-the-keys-of-an-object-with-a-for...in-statement.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/iterate-through-the-keys-of-an-object-with-a-for...in-statement.md @@ -14,15 +14,13 @@ Sometimes you may need to iterate through all the keys within an object. This re for (let user in users) { console.log(user); } - -// logs: -Alan -Jeff -Sarah -Ryan ``` -In this statement, we defined a variable `user`, and as you can see, this variable was reset during each iteration to each of the object's keys as the statement looped through the object, resulting in each user's name being printed to the console. **NOTE:** Objects do not maintain an ordering to stored keys like arrays do; thus a key's position on an object, or the relative order in which it appears, is irrelevant when referencing or accessing that key. +This would log `Alan`, `Jeff`, `Sarah`, and `Ryan` - each value on its own line. + +In this statement, we defined a variable `user`, and as you can see, this variable was reset during each iteration to each of the object's keys as the statement looped through the object, resulting in each user's name being printed to the console. + +**NOTE:** Objects do not maintain an ordering to stored keys like arrays do; thus a key's position on an object, or the relative order in which it appears, is irrelevant when referencing or accessing that key. # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/remove-items-from-an-array-with-pop-and-shift.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/remove-items-from-an-array-with-pop-and-shift.md index 9cb6b79038..4c19f1418d 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/remove-items-from-an-array-with-pop-and-shift.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/remove-items-from-an-array-with-pop-and-shift.md @@ -16,20 +16,24 @@ Let's take a look: let greetings = ['whats up?', 'hello', 'see ya!']; greetings.pop(); -// now equals ['whats up?', 'hello'] - -greetings.shift(); -// now equals ['hello'] ``` +`greetings` would have the value `['whats up?', 'hello']`. + +```js +greetings.shift(); +``` + +`greetings` would have the value `['hello']`. + We can also return the value of the removed element with either method like this: ```js let popped = greetings.pop(); -// returns 'hello' -// greetings now equals [] ``` +`greetings` would have the value `[]`, and `popped` would have the value `hello`. + # --instructions-- We have defined a function, `popShift`, which takes an array as an argument and returns a new array. Modify the function, using `pop()` and `shift()`, to remove the first and last elements of the argument array, and assign the removed elements to their corresponding variables, so that the returned array contains their values. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/remove-items-using-splice.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/remove-items-using-splice.md index ce579da8e7..d1a989882d 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/remove-items-using-splice.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/remove-items-using-splice.md @@ -16,19 +16,20 @@ Ok, so we've learned how to remove elements from the beginning and end of arrays let array = ['today', 'was', 'not', 'so', 'great']; array.splice(2, 2); -// remove 2 elements beginning with the 3rd element -// array now equals ['today', 'was', 'great'] ``` +Here we remove 2 elements, beginning with the third element (at index 2). `array` would have the value `['today', 'was', 'great']`. + `splice()` not only modifies the array it's being called on, but it also returns a new array containing the value of the removed elements: ```js let array = ['I', 'am', 'feeling', 'really', 'happy']; let newArray = array.splice(3, 2); -// newArray equals ['really', 'happy'] ``` +`newArray` has the value `['really', 'happy']`. + # --instructions-- We've initialized an array `arr`. Use `splice()` to remove elements from `arr`, so that it only contains elements that sum to the value of `10`. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/use-an-array-to-store-a-collection-of-data.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/use-an-array-to-store-a-collection-of-data.md index 61f8b4f1c3..4fdbdbdb29 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/use-an-array-to-store-a-collection-of-data.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/use-an-array-to-store-a-collection-of-data.md @@ -13,9 +13,10 @@ The below is an example of the simplest implementation of an array data structur ```js let simpleArray = ['one', 2, 'three', true, false, undefined, null]; console.log(simpleArray.length); -// logs 7 ``` +The `console.log` call displays `7`. + All arrays have a length property, which as shown above, can be very easily accessed with the syntax `Array.length`. A more complex implementation of an array can be seen below. This is known as a multi-dimensional array, or an array that contains other arrays. Notice that this array also contains JavaScript objects, which we will examine very closely in our next section, but for now, all you need to know is that arrays are also capable of storing complex objects. ```js diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/access-array-data-with-indexes.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/access-array-data-with-indexes.md index 0a1b708108..68ca2cda1b 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/access-array-data-with-indexes.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/access-array-data-with-indexes.md @@ -19,12 +19,13 @@ Array indexes are written in the same bracket notation that strings use, except ```js var array = [50,60,70]; -array[0]; // equals 50 -var data = array[1]; // equals 60 +array[0]; +var data = array[1]; ``` -**Note** -There shouldn't be any spaces between the array name and the square brackets, like `array [0]`. Although JavaScript is able to process this correctly, this may confuse other programmers reading your code. +`array[0]` is now `50`, and `data` has the value `60`. + +**Note:** There shouldn't be any spaces between the array name and the square brackets, like `array [0]`. Although JavaScript is able to process this correctly, this may confuse other programmers reading your code. # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/access-multi-dimensional-arrays-with-indexes.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/access-multi-dimensional-arrays-with-indexes.md index d7ca5ed641..a5ba1310c9 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/access-multi-dimensional-arrays-with-indexes.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/access-multi-dimensional-arrays-with-indexes.md @@ -20,13 +20,14 @@ var arr = [ [7,8,9], [[10,11,12], 13, 14] ]; -arr[3]; // equals [[10,11,12], 13, 14] -arr[3][0]; // equals [10,11,12] -arr[3][0][1]; // equals 11 +arr[3]; +arr[3][0]; +arr[3][0][1]; ``` -**Note** -There shouldn't be any spaces between the array name and the square brackets, like `array [0][0]` and even this `array [0] [0]` is not allowed. Although JavaScript is able to process this correctly, this may confuse other programmers reading your code. +`arr[3]` is `[[10, 11, 12], 13, 14]`, `arr[3][0]` is `[10, 11, 12]`, and `arr[3][0][1]` is `11`. + +**Note:** There shouldn't be any spaces between the array name and the square brackets, like `array [0][0]` and even this `array [0] [0]` is not allowed. Although JavaScript is able to process this correctly, this may confuse other programmers reading your code. # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-arrays.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-arrays.md index 59d912c1cf..247c0f2eab 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-arrays.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-arrays.md @@ -9,7 +9,7 @@ dashedName: accessing-nested-arrays # --description-- -As we have seen in earlier examples, objects can contain both nested objects and nested arrays. Similar to accessing nested objects, Array bracket notation can be chained to access nested arrays. +As we have seen in earlier examples, objects can contain both nested objects and nested arrays. Similar to accessing nested objects, array bracket notation can be chained to access nested arrays. Here is an example of how to access a nested array: @@ -32,17 +32,19 @@ var ourPets = [ ] } ]; -ourPets[0].names[1]; // "Fluffy" -ourPets[1].names[0]; // "Spot" +ourPets[0].names[1]; +ourPets[1].names[0]; ``` +`ourPets[0].names[1]` would be the string `Fluffy`, and `ourPets[1].names[0]` would be the string `Spot`. + # --instructions-- Retrieve the second tree from the variable `myPlants` using object dot and array bracket notation. # --hints-- -`secondTree` should equal "pine". +`secondTree` should equal the string `pine`. ```js assert(secondTree === 'pine'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-objects.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-objects.md index d8a7470d1f..ec531594bc 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-objects.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-nested-objects.md @@ -26,17 +26,19 @@ var ourStorage = { "bottom drawer": "soda" } }; -ourStorage.cabinet["top drawer"].folder2; // "secrets" -ourStorage.desk.drawer; // "stapler" +ourStorage.cabinet["top drawer"].folder2; +ourStorage.desk.drawer; ``` +`ourStorage.cabinet["top drawer"].folder2` would be the string `secrets`, and `ourStorage.desk.drawer` would be the string `stapler`. + # --instructions-- Access the `myStorage` object and assign the contents of the `glove box` property to the `gloveBoxContents` variable. Use dot notation for all properties where possible, otherwise use bracket notation. # --hints-- -`gloveBoxContents` should equal "maps". +`gloveBoxContents` should equal the string `maps`. ```js assert(gloveBoxContents === 'maps'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-bracket-notation.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-bracket-notation.md index a92f2eddcd..5716362cf9 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-bracket-notation.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-bracket-notation.md @@ -21,16 +21,18 @@ var myObj = { "More Space": "Spock", "NoSpace": "USS Enterprise" }; -myObj["Space Name"]; // Kirk -myObj['More Space']; // Spock -myObj["NoSpace"]; // USS Enterprise +myObj["Space Name"]; +myObj['More Space']; +myObj["NoSpace"]; ``` +`myObj["Space Name"]` would be the string `Kirk`, `myObj['More Space']` would be the string `Spock`, and `myObj["NoSpace"]` would be the string `USS Enterprise`. + Note that property names with spaces in them must be in quotes (single or double). # --instructions-- -Read the values of the properties `"an entree"` and `"the drink"` of `testObj` using bracket notation and assign them to `entreeValue` and `drinkValue` respectively. +Read the values of the properties `an entree` and `the drink` of `testObj` using bracket notation and assign them to `entreeValue` and `drinkValue` respectively. # --hints-- @@ -40,7 +42,7 @@ Read the values of the properties `"an entree"` and `"the drink"` of `testObj` u assert(typeof entreeValue === 'string'); ``` -The value of `entreeValue` should be `"hamburger"` +The value of `entreeValue` should be the string `hamburger` ```js assert(entreeValue === 'hamburger'); @@ -52,7 +54,7 @@ assert(entreeValue === 'hamburger'); assert(typeof drinkValue === 'string'); ``` -The value of `drinkValue` should be `"water"` +The value of `drinkValue` should be the string `water` ```js assert(drinkValue === 'water'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-dot-notation.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-dot-notation.md index af90aafcbc..d420ede372 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-dot-notation.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-dot-notation.md @@ -20,10 +20,11 @@ var myObj = { prop1: "val1", prop2: "val2" }; -var prop1val = myObj.prop1; // val1 -var prop2val = myObj.prop2; // val2 +var prop1val = myObj.prop1; +var prop2val = myObj.prop2; ``` +`prop1val` would have a value of the string `val1`, and `prop2val` would have a value of the string `val2`. # --instructions-- Read in the property values of `testObj` using dot notation. Set the variable `hatValue` equal to the object's property `hat` and set the variable `shirtValue` equal to the object's property `shirt`. @@ -36,7 +37,7 @@ Read in the property values of `testObj` using dot notation. Set the variable `h assert(typeof hatValue === 'string'); ``` -The value of `hatValue` should be `"ballcap"` +The value of `hatValue` should be the string `ballcap` ```js assert(hatValue === 'ballcap'); @@ -48,7 +49,7 @@ assert(hatValue === 'ballcap'); assert(typeof shirtValue === 'string'); ``` -The value of `shirtValue` should be `"jersey"` +The value of `shirtValue` should be the string `jersey` ```js assert(shirtValue === 'jersey'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-variables.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-variables.md index 05713220d6..2ec802ab59 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-variables.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/accessing-object-properties-with-variables.md @@ -19,9 +19,11 @@ var dogs = { }; var myDog = "Hunter"; var myBreed = dogs[myDog]; -console.log(myBreed); // "Doberman" +console.log(myBreed); ``` +The string `Doberman` would be displayed in the console. + Another way you can use this concept is when the property's name is collected dynamically during the program execution, as follows: ```js @@ -32,10 +34,12 @@ function propPrefix(str) { var s = "prop"; return s + str; } -var someProp = propPrefix("Name"); // someProp now holds the value 'propName' -console.log(someObj[someProp]); // "John" +var someProp = propPrefix("Name"); +console.log(someObj[someProp]); ``` +`someProp` would have a value of the string `propName`, and the string `John` would be displayed in the console. + Note that we do *not* use quotes around the variable name when using it to access the property because we are using the *value* of the variable, not the *name*. # --instructions-- @@ -56,7 +60,7 @@ The variable `player` should be a string assert(typeof player === 'string'); ``` -The value of `player` should be "Montana" +The value of `player` should be the string `Montana` ```js assert(player === 'Montana'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/add-new-properties-to-a-javascript-object.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/add-new-properties-to-a-javascript-object.md index 975b0206be..ffc41589ea 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/add-new-properties-to-a-javascript-object.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/add-new-properties-to-a-javascript-object.md @@ -11,7 +11,7 @@ dashedName: add-new-properties-to-a-javascript-object You can add new properties to existing JavaScript objects the same way you would modify them. -Here's how we would add a `"bark"` property to `ourDog`: +Here's how we would add a `bark` property to `ourDog`: `ourDog.bark = "bow-wow";` @@ -19,7 +19,7 @@ or `ourDog["bark"] = "bow-wow";` -Now when we evaluate `ourDog.bark`, we'll get his bark, "bow-wow". +Now when we evaluate `ourDog.bark`, we'll get his bark, `bow-wow`. Example: @@ -36,17 +36,17 @@ ourDog.bark = "bow-wow"; # --instructions-- -Add a `"bark"` property to `myDog` and set it to a dog sound, such as "woof". You may use either dot or bracket notation. +Add a `bark` property to `myDog` and set it to a dog sound, such as "woof". You may use either dot or bracket notation. # --hints-- -You should add the property `"bark"` to `myDog`. +You should add the property `bark` to `myDog`. ```js assert(myDog.bark !== undefined); ``` -You should not add `"bark"` to the setup section. +You should not add `bark` to the setup section. ```js assert(!/bark[^\n]:/.test(code)); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/add-two-numbers-with-javascript.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/add-two-numbers-with-javascript.md index 255cd3a3ed..3703a18fb2 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/add-two-numbers-with-javascript.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/add-two-numbers-with-javascript.md @@ -18,9 +18,11 @@ JavaScript uses the `+` symbol as an addition operator when placed between two n **Example:** ```js -myVar = 5 + 10; // assigned 15 +myVar = 5 + 10; ``` +`myVar` now has the value `15`. + # --instructions-- Change the `0` so that sum will equal `20`. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/adding-a-default-option-in-switch-statements.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/adding-a-default-option-in-switch-statements.md index 51b62017b0..dc1c62c6d4 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/adding-a-default-option-in-switch-statements.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/adding-a-default-option-in-switch-statements.md @@ -31,38 +31,38 @@ switch (num) { # --instructions-- Write a switch statement to set `answer` for the following conditions: -`"a"` - "apple" -`"b"` - "bird" -`"c"` - "cat" -`default` - "stuff" +`a` - `apple` +`b` - `bird` +`c` - `cat` +`default` - `stuff` # --hints-- -`switchOfStuff("a")` should have a value of "apple" +`switchOfStuff("a")` should return the string `apple` ```js assert(switchOfStuff('a') === 'apple'); ``` -`switchOfStuff("b")` should have a value of "bird" +`switchOfStuff("b")` should return the string `bird` ```js assert(switchOfStuff('b') === 'bird'); ``` -`switchOfStuff("c")` should have a value of "cat" +`switchOfStuff("c")` should return the string `cat` ```js assert(switchOfStuff('c') === 'cat'); ``` -`switchOfStuff("d")` should have a value of "stuff" +`switchOfStuff("d")` should return the string `stuff` ```js assert(switchOfStuff('d') === 'stuff'); ``` -`switchOfStuff(4)` should have a value of "stuff" +`switchOfStuff(4)` should return the string `stuff` ```js assert(switchOfStuff(4) === 'stuff'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/appending-variables-to-strings.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/appending-variables-to-strings.md index be826ab034..3ca8297b81 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/appending-variables-to-strings.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/appending-variables-to-strings.md @@ -17,9 +17,10 @@ Example: var anAdjective = "awesome!"; var ourStr = "freeCodeCamp is "; ourStr += anAdjective; -// ourStr is now "freeCodeCamp is awesome!" ``` +`ourStr` would have the value `freeCodeCamp is awesome!`. + # --instructions-- Set `someAdjective` to a string of at least 3 characters and append it to `myStr` using the `+=` operator. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/assigning-the-value-of-one-variable-to-another.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/assigning-the-value-of-one-variable-to-another.md index 2938f087ee..ad5a0371ab 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/assigning-the-value-of-one-variable-to-another.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/assigning-the-value-of-one-variable-to-another.md @@ -32,7 +32,7 @@ You should not change code above the specified comment. assert(/var a;/.test(code) && /a = 7;/.test(code) && /var b;/.test(code)); ``` -`b` should have a value of 7. +`b` should have a value of `7`. ```js assert(typeof b === 'number' && b === 7); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/build-javascript-objects.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/build-javascript-objects.md index 9289d9ff58..b67d8c4d52 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/build-javascript-objects.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/build-javascript-objects.md @@ -26,7 +26,7 @@ var cat = { }; ``` -In this example, all the properties are stored as strings, such as - `"name"`, `"legs"`, and `"tails"`. However, you can also use numbers as properties. You can even omit the quotes for single-word string properties, as follows: +In this example, all the properties are stored as strings, such as - `name`, `legs`, and `tails`. However, you can also use numbers as properties. You can even omit the quotes for single-word string properties, as follows: ```js var anotherObject = { @@ -40,9 +40,9 @@ However, if your object has any non-string properties, JavaScript will automatic # --instructions-- -Make an object that represents a dog called `myDog` which contains the properties `"name"` (a string), `"legs"`, `"tails"` and `"friends"`. +Make an object that represents a dog called `myDog` which contains the properties `name` (a string), `legs`, `tails` and `friends`. -You can set these object properties to whatever values you want, as long as `"name"` is a string, `"legs"` and `"tails"` are numbers, and `"friends"` is an array. +You can set these object properties to whatever values you want, as long as `name` is a string, `legs` and `tails` are numbers, and `friends` is an array. # --hints-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/chaining-if-else-statements.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/chaining-if-else-statements.md index f68a2f94db..608723120c 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/chaining-if-else-statements.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/chaining-if-else-statements.md @@ -28,11 +28,11 @@ if (condition1) { Write chained `if`/`else if` statements to fulfill the following conditions: -`num < 5` - return "Tiny" -`num < 10` - return "Small" -`num < 15` - return "Medium" -`num < 20` - return "Large" -`num >= 20` - return "Huge" +`num < 5` - return `Tiny` +`num < 10` - return `Small` +`num < 15` - return `Medium` +`num < 20` - return `Large` +`num >= 20` - return `Huge` # --hints-- @@ -54,61 +54,61 @@ You should have at least one `return` statement assert(code.match(/return/g).length >= 1); ``` -`testSize(0)` should return "Tiny" +`testSize(0)` should return the string `Tiny` ```js assert(testSize(0) === 'Tiny'); ``` -`testSize(4)` should return "Tiny" +`testSize(4)` should return the string `Tiny` ```js assert(testSize(4) === 'Tiny'); ``` -`testSize(5)` should return "Small" +`testSize(5)` should return the string `Small` ```js assert(testSize(5) === 'Small'); ``` -`testSize(8)` should return "Small" +`testSize(8)` should return the string `Small` ```js assert(testSize(8) === 'Small'); ``` -`testSize(10)` should return "Medium" +`testSize(10)` should return the string `Medium` ```js assert(testSize(10) === 'Medium'); ``` -`testSize(14)` should return "Medium" +`testSize(14)` should return the string `Medium` ```js assert(testSize(14) === 'Medium'); ``` -`testSize(15)` should return "Large" +`testSize(15)` should return the string `Large` ```js assert(testSize(15) === 'Large'); ``` -`testSize(17)` should return "Large" +`testSize(17)` should return the string `Large` ```js assert(testSize(17) === 'Large'); ``` -`testSize(20)` should return "Huge" +`testSize(20)` should return the string `Huge` ```js assert(testSize(20) === 'Huge'); ``` -`testSize(25)` should return "Huge" +`testSize(25)` should return the string `Huge` ```js assert(testSize(25) === 'Huge'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comment-your-javascript-code.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comment-your-javascript-code.md index c617da8e8e..7108d22ce3 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comment-your-javascript-code.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comment-your-javascript-code.md @@ -13,21 +13,20 @@ Comments are lines of code that JavaScript will intentionally ignore. Comments a There are two ways to write comments in JavaScript: -Using `//` will tell JavaScript to ignore the remainder of the text on the current line: +Using `//` will tell JavaScript to ignore the remainder of the text on the current line. This is an in-line comment: ```js // This is an in-line comment. ``` -You can make a multi-line comment beginning with `/*` and ending with `*/`: +You can make a multi-line comment beginning with `/*` and ending with `*/`. This is a multi-line comment: ```js /* This is a multi-line comment */ ``` -**Best Practice** -As you write code, you should regularly add comments to clarify the function of parts of your code. Good commenting can help communicate the intent of your code—both for others *and* for your future self. +**NOTE:** As you write code, you should regularly add comments to clarify the function of parts of your code. Good commenting can help communicate the intent of your code—both for others *and* for your future self. # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-equality-operator.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-equality-operator.md index 8fd2086992..7bd40b179f 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-equality-operator.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-equality-operator.md @@ -22,34 +22,36 @@ function equalityTest(myVal) { } ``` -If `myVal` is equal to `10`, the equality operator returns `true`, so the code in the curly braces will execute, and the function will return `"Equal"`. Otherwise, the function will return `"Not Equal"`. In order for JavaScript to compare two different data types (for example, `numbers` and `strings`), it must convert one type to another. This is known as "Type Coercion". Once it does, however, it can compare terms as follows: +If `myVal` is equal to `10`, the equality operator returns `true`, so the code in the curly braces will execute, and the function will return `Equal`. Otherwise, the function will return `Not Equal`. In order for JavaScript to compare two different data types (for example, `numbers` and `strings`), it must convert one type to another. This is known as Type Coercion. Once it does, however, it can compare terms as follows: ```js -1 == 1 // true -1 == 2 // false -1 == '1' // true -"3" == 3 // true +1 == 1 +1 == 2 +1 == '1' +"3" == 3 ``` +In order, these expressions would evaluate to `true`, `false`, `true`, and `true`. + # --instructions-- -Add the equality operator to the indicated line so that the function will return "Equal" when `val` is equivalent to `12`. +Add the equality operator to the indicated line so that the function will return the string `Equal` when `val` is equivalent to `12`. # --hints-- -`testEqual(10)` should return "Not Equal" +`testEqual(10)` should return the string `Not Equal` ```js assert(testEqual(10) === 'Not Equal'); ``` -`testEqual(12)` should return "Equal" +`testEqual(12)` should return the string `Equal` ```js assert(testEqual(12) === 'Equal'); ``` -`testEqual("12")` should return "Equal" +`testEqual("12")` should return the string `Equal` ```js assert(testEqual('12') === 'Equal'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-greater-than-operator.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-greater-than-operator.md index 840dc21d81..028df02eb7 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-greater-than-operator.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-greater-than-operator.md @@ -16,55 +16,57 @@ Like the equality operator, greater than operator will convert data types of val **Examples** ```js -5 > 3 // true -7 > '3' // true -2 > 3 // false -'1' > 9 // false +5 > 3 +7 > '3' +2 > 3 +'1' > 9 ``` +In order, these expressions would evaluate to `true`, `true`, `false`, and `false`. + # --instructions-- Add the greater than operator to the indicated lines so that the return statements make sense. # --hints-- -`testGreaterThan(0)` should return "10 or Under" +`testGreaterThan(0)` should return the string `10 or Under` ```js assert(testGreaterThan(0) === '10 or Under'); ``` -`testGreaterThan(10)` should return "10 or Under" +`testGreaterThan(10)` should return the string `10 or Under` ```js assert(testGreaterThan(10) === '10 or Under'); ``` -`testGreaterThan(11)` should return "Over 10" +`testGreaterThan(11)` should return the string `Over 10` ```js assert(testGreaterThan(11) === 'Over 10'); ``` -`testGreaterThan(99)` should return "Over 10" +`testGreaterThan(99)` should return the string `Over 10` ```js assert(testGreaterThan(99) === 'Over 10'); ``` -`testGreaterThan(100)` should return "Over 10" +`testGreaterThan(100)` should return the string `Over 10` ```js assert(testGreaterThan(100) === 'Over 10'); ``` -`testGreaterThan(101)` should return "Over 100" +`testGreaterThan(101)` should return the string `Over 100` ```js assert(testGreaterThan(101) === 'Over 100'); ``` -`testGreaterThan(150)` should return "Over 100" +`testGreaterThan(150)` should return the string `Over 100` ```js assert(testGreaterThan(150) === 'Over 100'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-greater-than-or-equal-to-operator.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-greater-than-or-equal-to-operator.md index 482906b191..6119981966 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-greater-than-or-equal-to-operator.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-greater-than-or-equal-to-operator.md @@ -16,55 +16,57 @@ Like the equality operator, the `>=` will convert data types while comparing. **Examples** ```js -6 >= 6 // true -7 >= '3' // true -2 >= 3 // false -'7' >= 9 // false +6 >= 6 +7 >= '3' +2 >= 3 +'7' >= 9 ``` +In order, these expressions would evaluate to `true`, `true`, `false`, and `false`. + # --instructions-- Add the greater than or equal to operator to the indicated lines so that the return statements make sense. # --hints-- -`testGreaterOrEqual(0)` should return "Less than 10" +`testGreaterOrEqual(0)` should return the string `Less than 10` ```js assert(testGreaterOrEqual(0) === 'Less than 10'); ``` -`testGreaterOrEqual(9)` should return "Less than 10" +`testGreaterOrEqual(9)` should return the string `Less than 10` ```js assert(testGreaterOrEqual(9) === 'Less than 10'); ``` -`testGreaterOrEqual(10)` should return "10 or Over" +`testGreaterOrEqual(10)` should return the string `10 or Over` ```js assert(testGreaterOrEqual(10) === '10 or Over'); ``` -`testGreaterOrEqual(11)` should return "10 or Over" +`testGreaterOrEqual(11)` should return the string `10 or Over` ```js assert(testGreaterOrEqual(11) === '10 or Over'); ``` -`testGreaterOrEqual(19)` should return "10 or Over" +`testGreaterOrEqual(19)` should return the string `10 or Over` ```js assert(testGreaterOrEqual(19) === '10 or Over'); ``` -`testGreaterOrEqual(100)` should return "20 or Over" +`testGreaterOrEqual(100)` should return the string `20 or Over` ```js assert(testGreaterOrEqual(100) === '20 or Over'); ``` -`testGreaterOrEqual(21)` should return "20 or Over" +`testGreaterOrEqual(21)` should return the string `20 or Over` ```js assert(testGreaterOrEqual(21) === '20 or Over'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-inequality-operator.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-inequality-operator.md index 24d6c5fbec..6b303c3517 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-inequality-operator.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-inequality-operator.md @@ -9,49 +9,51 @@ dashedName: comparison-with-the-inequality-operator # --description-- -The inequality operator (`!=`) is the opposite of the equality operator. It means "Not Equal" and returns `false` where equality would return `true` and *vice versa*. Like the equality operator, the inequality operator will convert data types of values while comparing. +The inequality operator (`!=`) is the opposite of the equality operator. It means not equal and returns `false` where equality would return `true` and *vice versa*. Like the equality operator, the inequality operator will convert data types of values while comparing. **Examples** ```js -1 != 2 // true -1 != "1" // false -1 != '1' // false -1 != true // false -0 != false // false +1 != 2 +1 != "1" +1 != '1' +1 != true +0 != false ``` +In order, these expressions would evaluate to `true`, `false`, `false`, `false`, and `false`. + # --instructions-- -Add the inequality operator `!=` in the `if` statement so that the function will return "Not Equal" when `val` is not equivalent to `99` +Add the inequality operator `!=` in the `if` statement so that the function will return the string `Not Equal` when `val` is not equivalent to `99` # --hints-- -`testNotEqual(99)` should return "Equal" +`testNotEqual(99)` should return the string `Equal` ```js assert(testNotEqual(99) === 'Equal'); ``` -`testNotEqual("99")` should return "Equal" +`testNotEqual("99")` should return the string `Equal` ```js assert(testNotEqual('99') === 'Equal'); ``` -`testNotEqual(12)` should return "Not Equal" +`testNotEqual(12)` should return the string `Not Equal` ```js assert(testNotEqual(12) === 'Not Equal'); ``` -`testNotEqual("12")` should return "Not Equal" +`testNotEqual("12")` should return the string `Not Equal` ```js assert(testNotEqual('12') === 'Not Equal'); ``` -`testNotEqual("bob")` should return "Not Equal" +`testNotEqual("bob")` should return the string `Not Equal` ```js assert(testNotEqual('bob') === 'Not Equal'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-less-than-operator.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-less-than-operator.md index 5fd6bc8d55..0f42d9b22f 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-less-than-operator.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-less-than-operator.md @@ -14,50 +14,52 @@ The less than operator (`<`) compares the values of two numbers. If t **Examples** ```js -2 < 5 // true -'3' < 7 // true -5 < 5 // false -3 < 2 // false -'8' < 4 // false +2 < 5 +'3' < 7 +5 < 5 +3 < 2 +'8' < 4 ``` +In order, these expressions would evaluate to `true`, `true`, `false`, `false`, and `false`. + # --instructions-- Add the less than operator to the indicated lines so that the return statements make sense. # --hints-- -`testLessThan(0)` should return "Under 25" +`testLessThan(0)` should return the string `Under 25` ```js assert(testLessThan(0) === 'Under 25'); ``` -`testLessThan(24)` should return "Under 25" +`testLessThan(24)` should return the string `Under 25` ```js assert(testLessThan(24) === 'Under 25'); ``` -`testLessThan(25)` should return "Under 55" +`testLessThan(25)` should return the string `Under 55` ```js assert(testLessThan(25) === 'Under 55'); ``` -`testLessThan(54)` should return "Under 55" +`testLessThan(54)` should return the string `Under 55` ```js assert(testLessThan(54) === 'Under 55'); ``` -`testLessThan(55)` should return "55 or Over" +`testLessThan(55)` should return the string `55 or Over` ```js assert(testLessThan(55) === '55 or Over'); ``` -`testLessThan(99)` should return "55 or Over" +`testLessThan(99)` should return the string `55 or Over` ```js assert(testLessThan(99) === '55 or Over'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-less-than-or-equal-to-operator.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-less-than-or-equal-to-operator.md index 5174b635b4..a3e3c2da54 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-less-than-or-equal-to-operator.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-less-than-or-equal-to-operator.md @@ -14,56 +14,58 @@ The less than or equal to operator (`<=`) compares the values of two numbers. If **Examples** ```js -4 <= 5 // true -'7' <= 7 // true -5 <= 5 // true -3 <= 2 // false -'8' <= 4 // false +4 <= 5 +'7' <= 7 +5 <= 5 +3 <= 2 +'8' <= 4 ``` +In order, these expressions would evaluate to `true`, `true`, `true`, `false`, and `false`. + # --instructions-- Add the less than or equal to operator to the indicated lines so that the return statements make sense. # --hints-- -`testLessOrEqual(0)` should return "Smaller Than or Equal to 12" +`testLessOrEqual(0)` should return the string `Smaller Than or Equal to 12` ```js assert(testLessOrEqual(0) === 'Smaller Than or Equal to 12'); ``` -`testLessOrEqual(11)` should return "Smaller Than or Equal to 12" +`testLessOrEqual(11)` should return the string `Smaller Than or Equal to 12` ```js assert(testLessOrEqual(11) === 'Smaller Than or Equal to 12'); ``` -`testLessOrEqual(12)` should return "Smaller Than or Equal to 12" +`testLessOrEqual(12)` should return the string `Smaller Than or Equal to 12` ```js assert(testLessOrEqual(12) === 'Smaller Than or Equal to 12'); ``` -`testLessOrEqual(23)` should return "Smaller Than or Equal to 24" +`testLessOrEqual(23)` should return the string `Smaller Than or Equal to 24` ```js assert(testLessOrEqual(23) === 'Smaller Than or Equal to 24'); ``` -`testLessOrEqual(24)` should return "Smaller Than or Equal to 24" +`testLessOrEqual(24)` should return the string `Smaller Than or Equal to 24` ```js assert(testLessOrEqual(24) === 'Smaller Than or Equal to 24'); ``` -`testLessOrEqual(25)` should return "More Than 24" +`testLessOrEqual(25)` should return the string `More Than 24` ```js assert(testLessOrEqual(25) === 'More Than 24'); ``` -`testLessOrEqual(55)` should return "More Than 24" +`testLessOrEqual(55)` should return the string `More Than 24` ```js assert(testLessOrEqual(55) === 'More Than 24'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-strict-equality-operator.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-strict-equality-operator.md index b8d73b9aa4..6aa9ba3861 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-strict-equality-operator.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-strict-equality-operator.md @@ -16,31 +16,33 @@ If the values being compared have different types, they are considered unequal, **Examples** ```js -3 === 3 // true -3 === '3' // false +3 === 3 +3 === '3' ``` +These conditions would return `true` and `false` respectively. + In the second example, `3` is a `Number` type and `'3'` is a `String` type. # --instructions-- -Use the strict equality operator in the `if` statement so the function will return "Equal" when `val` is strictly equal to `7` +Use the strict equality operator in the `if` statement so the function will return the string `Equal` when `val` is strictly equal to `7` # --hints-- -`testStrict(10)` should return "Not Equal" +`testStrict(10)` should return the string `Not Equal` ```js assert(testStrict(10) === 'Not Equal'); ``` -`testStrict(7)` should return "Equal" +`testStrict(7)` should return the string `Equal` ```js assert(testStrict(7) === 'Equal'); ``` -`testStrict("7")` should return "Not Equal" +`testStrict("7")` should return the string `Not Equal` ```js assert(testStrict('7') === 'Not Equal'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-strict-inequality-operator.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-strict-inequality-operator.md index 9d4b49785c..398846da75 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-strict-inequality-operator.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-strict-inequality-operator.md @@ -14,36 +14,38 @@ The strict inequality operator (`!==`) is the logical opposite of the strict equ **Examples** ```js -3 !== 3 // false -3 !== '3' // true -4 !== 3 // true +3 !== 3 +3 !== '3' +4 !== 3 ``` +In order, these expressions would evaluate to `false`, `true`, and `true`. + # --instructions-- -Add the strict inequality operator to the `if` statement so the function will return "Not Equal" when `val` is not strictly equal to `17` +Add the strict inequality operator to the `if` statement so the function will return the string `Not Equal` when `val` is not strictly equal to `17` # --hints-- -`testStrictNotEqual(17)` should return "Equal" +`testStrictNotEqual(17)` should return the string `Equal` ```js assert(testStrictNotEqual(17) === 'Equal'); ``` -`testStrictNotEqual("17")` should return "Not Equal" +`testStrictNotEqual("17")` should return the string `Not Equal` ```js assert(testStrictNotEqual('17') === 'Not Equal'); ``` -`testStrictNotEqual(12)` should return "Not Equal" +`testStrictNotEqual(12)` should return the string `Not Equal` ```js assert(testStrictNotEqual(12) === 'Not Equal'); ``` -`testStrictNotEqual("bob")` should return "Not Equal" +`testStrictNotEqual("bob")` should return the string `Not Equal` ```js assert(testStrictNotEqual('bob') === 'Not Equal'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparisons-with-the-logical-and-operator.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparisons-with-the-logical-and-operator.md index bf9c2a6c1a..da1175e7c0 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparisons-with-the-logical-and-operator.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparisons-with-the-logical-and-operator.md @@ -22,7 +22,7 @@ if (num > 5) { return "No"; ``` -will only return "Yes" if `num` is greater than `5` and less than `10`. The same logic can be written as: +will only return `Yes` if `num` is greater than `5` and less than `10`. The same logic can be written as: ```js if (num > 5 && num < 10) { @@ -33,7 +33,7 @@ return "No"; # --instructions-- -Replace the two if statements with one statement, using the && operator, which will return `"Yes"` if `val` is less than or equal to `50` and greater than or equal to `25`. Otherwise, will return `"No"`. +Replace the two if statements with one statement, using the `&&` operator, which will return the string `Yes` if `val` is less than or equal to `50` and greater than or equal to `25`. Otherwise, will return the string `No`. # --hints-- @@ -49,49 +49,49 @@ You should only have one `if` statement assert(code.match(/if/g).length === 1); ``` -`testLogicalAnd(0)` should return "No" +`testLogicalAnd(0)` should return the string `No` ```js assert(testLogicalAnd(0) === 'No'); ``` -`testLogicalAnd(24)` should return "No" +`testLogicalAnd(24)` should return the string `No` ```js assert(testLogicalAnd(24) === 'No'); ``` -`testLogicalAnd(25)` should return "Yes" +`testLogicalAnd(25)` should return the string `Yes` ```js assert(testLogicalAnd(25) === 'Yes'); ``` -`testLogicalAnd(30)` should return "Yes" +`testLogicalAnd(30)` should return the string `Yes` ```js assert(testLogicalAnd(30) === 'Yes'); ``` -`testLogicalAnd(50)` should return "Yes" +`testLogicalAnd(50)` should return the string `Yes` ```js assert(testLogicalAnd(50) === 'Yes'); ``` -`testLogicalAnd(51)` should return "No" +`testLogicalAnd(51)` should return the string `No` ```js assert(testLogicalAnd(51) === 'No'); ``` -`testLogicalAnd(75)` should return "No" +`testLogicalAnd(75)` should return the string `No` ```js assert(testLogicalAnd(75) === 'No'); ``` -`testLogicalAnd(80)` should return "No" +`testLogicalAnd(80)` should return the string `No` ```js assert(testLogicalAnd(80) === 'No'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparisons-with-the-logical-or-operator.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparisons-with-the-logical-or-operator.md index cd5d09d36f..3202c07163 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparisons-with-the-logical-or-operator.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparisons-with-the-logical-or-operator.md @@ -25,7 +25,7 @@ if (num < 5) { return "Yes"; ``` -will return "Yes" only if `num` is between `5` and `10` (5 and 10 included). The same logic can be written as: +will return `Yes` only if `num` is between `5` and `10` (5 and 10 included). The same logic can be written as: ```js if (num > 10 || num < 5) { @@ -36,7 +36,7 @@ return "Yes"; # --instructions-- -Combine the two `if` statements into one statement which returns `"Outside"` if `val` is not between `10` and `20`, inclusive. Otherwise, return `"Inside"`. +Combine the two `if` statements into one statement which returns the string `Outside` if `val` is not between `10` and `20`, inclusive. Otherwise, return the string `Inside`. # --hints-- @@ -52,49 +52,49 @@ You should only have one `if` statement assert(code.match(/if/g).length === 1); ``` -`testLogicalOr(0)` should return "Outside" +`testLogicalOr(0)` should return the string `Outside` ```js assert(testLogicalOr(0) === 'Outside'); ``` -`testLogicalOr(9)` should return "Outside" +`testLogicalOr(9)` should return the string `Outside` ```js assert(testLogicalOr(9) === 'Outside'); ``` -`testLogicalOr(10)` should return "Inside" +`testLogicalOr(10)` should return the string `Inside` ```js assert(testLogicalOr(10) === 'Inside'); ``` -`testLogicalOr(15)` should return "Inside" +`testLogicalOr(15)` should return the string `Inside` ```js assert(testLogicalOr(15) === 'Inside'); ``` -`testLogicalOr(19)` should return "Inside" +`testLogicalOr(19)` should return the string `Inside` ```js assert(testLogicalOr(19) === 'Inside'); ``` -`testLogicalOr(20)` should return "Inside" +`testLogicalOr(20)` should return the string `Inside` ```js assert(testLogicalOr(20) === 'Inside'); ``` -`testLogicalOr(21)` should return "Outside" +`testLogicalOr(21)` should return the string `Outside` ```js assert(testLogicalOr(21) === 'Outside'); ``` -`testLogicalOr(25)` should return "Outside" +`testLogicalOr(25)` should return the string `Outside` ```js assert(testLogicalOr(25) === 'Outside'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-addition.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-addition.md index 0a2ab04992..7bc5f65127 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-addition.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-addition.md @@ -20,9 +20,11 @@ One such operator is the `+=` operator. ```js var myVar = 1; myVar += 5; -console.log(myVar); // Returns 6 +console.log(myVar); ``` +`6` would be displayed in the console. + # --instructions-- Convert the assignments for `a`, `b`, and `c` to use the `+=` operator. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-plus-operator.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-plus-operator.md index ec94ec73ed..4b9adc2615 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-plus-operator.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-plus-operator.md @@ -17,23 +17,22 @@ In JavaScript, when the `+` operator is used with a `String` value, it is called 'My name is Alan,' + ' I concatenate.' ``` -**Note** -Watch out for spaces. Concatenation does not add spaces between concatenated strings, so you'll need to add them yourself. +**Note:** Watch out for spaces. Concatenation does not add spaces between concatenated strings, so you'll need to add them yourself. Example: ```js var ourStr = "I come first. " + "I come second."; -// ourStr is "I come first. I come second." ``` +The string `I come first. I come second.` would be displayed in the console. # --instructions-- -Build `myStr` from the strings `"This is the start. "` and `"This is the end."` using the `+` operator. +Build `myStr` from the strings `This is the start. ` and `This is the end.` using the `+` operator. # --hints-- -`myStr` should have a value of `This is the start. This is the end.` +`myStr` should have a value of the string `This is the start. This is the end.` ```js assert(myStr === 'This is the start. This is the end.'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-the-plus-equals-operator.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-the-plus-equals-operator.md index e1bf723545..dda39ce727 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-the-plus-equals-operator.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-the-plus-equals-operator.md @@ -11,24 +11,24 @@ dashedName: concatenating-strings-with-the-plus-equals-operator We can also use the `+=` operator to concatenate a string onto the end of an existing string variable. This can be very helpful to break a long string over several lines. -**Note** -Watch out for spaces. Concatenation does not add spaces between concatenated strings, so you'll need to add them yourself. +**Note:** Watch out for spaces. Concatenation does not add spaces between concatenated strings, so you'll need to add them yourself. Example: ```js var ourStr = "I come first. "; ourStr += "I come second."; -// ourStr is now "I come first. I come second." ``` +`ourStr` now has a value of the string `I come first. I come second.`. + # --instructions-- -Build `myStr` over several lines by concatenating these two strings: `"This is the first sentence. "` and `"This is the second sentence."` using the `+=` operator. Use the `+=` operator similar to how it is shown in the editor. Start by assigning the first string to `myStr`, then add on the second string. +Build `myStr` over several lines by concatenating these two strings: `This is the first sentence. ` and `This is the second sentence.` using the `+=` operator. Use the `+=` operator similar to how it is shown in the editor. Start by assigning the first string to `myStr`, then add on the second string. # --hints-- -`myStr` should have a value of `This is the first sentence. This is the second sentence.` +`myStr` should have a value of the string `This is the first sentence. This is the second sentence.` ```js assert(myStr === 'This is the first sentence. This is the second sentence.'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/constructing-strings-with-variables.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/constructing-strings-with-variables.md index 183aa48865..a21e9753ea 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/constructing-strings-with-variables.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/constructing-strings-with-variables.md @@ -16,12 +16,13 @@ Example: ```js var ourName = "freeCodeCamp"; var ourStr = "Hello, our name is " + ourName + ", how are you?"; -// ourStr is now "Hello, our name is freeCodeCamp, how are you?" ``` +`ourStr` would have a value of the string `Hello, our name is freeCodeCamp, how are you?`. + # --instructions-- -Set `myName` to a string equal to your name and build `myStr` with `myName` between the strings `"My name is "` and `" and I am well!"` +Set `myName` to a string equal to your name and build `myStr` with `myName` between the strings `My name is ` and ` and I am well!` # --hints-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/count-backwards-with-a-for-loop.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/count-backwards-with-a-for-loop.md index 9edc5f1cb9..0d30063502 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/count-backwards-with-a-for-loop.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/count-backwards-with-a-for-loop.md @@ -11,7 +11,7 @@ dashedName: count-backwards-with-a-for-loop A for loop can also count backwards, so long as we can define the right conditions. -In order to decrement by two each iteration, we'll need to change our `initialization`, `condition`, and `final-expression`. +In order to decrement by two each iteration, we'll need to change our initialization, condition, and final expression. We'll start at `i = 10` and loop while `i > 0`. We'll decrement `i` by 2 each loop with `i -= 2`. @@ -22,7 +22,7 @@ for (var i = 10; i > 0; i -= 2) { } ``` -`ourArray` will now contain `[10,8,6,4,2]`. Let's change our `initialization` and `final-expression` so we can count backward by twos by odd numbers. +`ourArray` will now contain `[10,8,6,4,2]`. Let's change our initialization and final expression so we can count backward by twos by odd numbers. # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/counting-cards.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/counting-cards.md index 0c62e94608..39e0530fdc 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/counting-cards.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/counting-cards.md @@ -47,7 +47,7 @@ assert( ); ``` -Cards Sequence 7, 8, 9 should return `0 Hold` +Cards Sequence 7, 8, 9 should return the string `0 Hold` ```js assert( @@ -64,7 +64,7 @@ assert( ); ``` -Cards Sequence 10, J, Q, K, A should return `-5 Hold` +Cards Sequence 10, J, Q, K, A should return the string `-5 Hold` ```js assert( @@ -83,7 +83,7 @@ assert( ); ``` -Cards Sequence 3, 7, Q, 8, A should return `-1 Hold` +Cards Sequence 3, 7, Q, 8, A should return the string `-1 Hold` ```js assert( @@ -102,7 +102,7 @@ assert( ); ``` -Cards Sequence 2, J, 9, 2, 7 should return `1 Bet` +Cards Sequence 2, J, 9, 2, 7 should return the string `1 Bet` ```js assert( @@ -121,7 +121,7 @@ assert( ); ``` -Cards Sequence 2, 2, 10 should return `1 Bet` +Cards Sequence 2, 2, 10 should return the string `1 Bet` ```js assert( @@ -138,7 +138,7 @@ assert( ); ``` -Cards Sequence 3, 2, A, 10, K should return `-1 Hold` +Cards Sequence 3, 2, A, 10, K should return the string `-1 Hold` ```js assert( diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/create-decimal-numbers-with-javascript.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/create-decimal-numbers-with-javascript.md index de35aa22d3..49ca86fc2c 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/create-decimal-numbers-with-javascript.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/create-decimal-numbers-with-javascript.md @@ -11,8 +11,7 @@ dashedName: create-decimal-numbers-with-javascript We can store decimal numbers in variables too. Decimal numbers are sometimes referred to as floating point numbers or floats. -**Note** -Not all real numbers can accurately be represented in floating point. This can lead to rounding errors. [Details Here](https://en.wikipedia.org/wiki/Floating_point#Accuracy_problems). +**Note:** Not all real numbers can accurately be represented in floating point. This can lead to rounding errors. [Details Here](https://en.wikipedia.org/wiki/Floating_point#Accuracy_problems). # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/declare-string-variables.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/declare-string-variables.md index 92856c5e26..c8452cb7d9 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/declare-string-variables.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/declare-string-variables.md @@ -17,7 +17,7 @@ Previously we have used the code # --instructions-- -Create two new `string` variables: `myFirstName` and `myLastName` and assign them the values of your first and last name, respectively. +Create two new string variables: `myFirstName` and `myLastName` and assign them the values of your first and last name, respectively. # --hints-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/decrement-a-number-with-javascript.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/decrement-a-number-with-javascript.md index 2f71a24523..9a2f557a57 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/decrement-a-number-with-javascript.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/decrement-a-number-with-javascript.md @@ -17,8 +17,7 @@ is the equivalent of `i = i - 1;` -**Note** -The entire line becomes `i--;`, eliminating the need for the equal sign. +**Note:** The entire line becomes `i--;`, eliminating the need for the equal sign. # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/delete-properties-from-a-javascript-object.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/delete-properties-from-a-javascript-object.md index 21c8366962..d77477d3f0 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/delete-properties-from-a-javascript-object.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/delete-properties-from-a-javascript-object.md @@ -40,11 +40,11 @@ After the last line shown above, `ourDog` looks like: # --instructions-- -Delete the `"tails"` property from `myDog`. You may use either dot or bracket notation. +Delete the `tails` property from `myDog`. You may use either dot or bracket notation. # --hints-- -You should delete the property `"tails"` from `myDog`. +You should delete the property `tails` from `myDog`. ```js assert(typeof myDog === 'object' && myDog.tails === undefined); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-number-by-another-with-javascript.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-number-by-another-with-javascript.md index 7cd4e25b80..e0a3339e4e 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-number-by-another-with-javascript.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/divide-one-number-by-another-with-javascript.md @@ -16,9 +16,10 @@ JavaScript uses the `/` symbol for division. **Example** ```js -myVar = 16 / 2; // assigned 8 +myVar = 16 / 2; ``` +`myVar` now has the value `8`. # --instructions-- Change the `0` so that the `quotient` is equal to `2`. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/find-the-length-of-a-string.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/find-the-length-of-a-string.md index 03bc3f0071..3270c6dbc9 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/find-the-length-of-a-string.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/find-the-length-of-a-string.md @@ -11,9 +11,13 @@ dashedName: find-the-length-of-a-string You can find the length of a `String` value by writing `.length` after the string variable or string literal. -`"Alan Peter".length; // 10` +```js +console.log("Alan Peter".length); +``` -For example, if we created a variable `var firstName = "Charles"`, we could find out how long the string `"Charles"` is by using the `firstName.length` property. +The value `10` would be displayed in the console. + +For example, if we created a variable `var firstName = "Charles"`, we could find out how long the string `Charles` is by using the `firstName.length` property. # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/finding-a-remainder-in-javascript.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/finding-a-remainder-in-javascript.md index c811162a83..c035c81b1d 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/finding-a-remainder-in-javascript.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/finding-a-remainder-in-javascript.md @@ -20,8 +20,7 @@ In mathematics, a number can be checked to be even or odd by checking the remain
17 % 2 = 1 (17 is Odd)
48 % 2 = 0 (48 is Even)
-**Note** -The remainder operator is sometimes incorrectly referred to as the "modulus" operator. It is very similar to modulus, but does not work properly with negative numbers. +**Note:** The remainder operator is sometimes incorrectly referred to as the modulus operator. It is very similar to modulus, but does not work properly with negative numbers. # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/generate-random-fractions-with-javascript.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/generate-random-fractions-with-javascript.md index 7565d935ad..66a7d7db80 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/generate-random-fractions-with-javascript.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/generate-random-fractions-with-javascript.md @@ -13,8 +13,7 @@ Random numbers are useful for creating random behavior. JavaScript has a `Math.random()` function that generates a random decimal number between `0` (inclusive) and not quite up to `1` (exclusive). Thus `Math.random()` can return a `0` but never quite return a `1` -**Note** -Like [Storing Values with the Equal Operator](/learn/javascript-algorithms-and-data-structures/basic-javascript/storing-values-with-the-assignment-operator), all function calls will be resolved before the `return` executes, so we can `return` the value of the `Math.random()` function. +**Note:** Like [Storing Values with the Equal Operator](/learn/javascript-algorithms-and-data-structures/basic-javascript/storing-values-with-the-assignment-operator), all function calls will be resolved before the `return` executes, so we can `return` the value of the `Math.random()` function. # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/global-vs.-local-scope-in-functions.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/global-vs.-local-scope-in-functions.md index 4aa4e70ab0..e1743e39af 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/global-vs.-local-scope-in-functions.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/global-vs.-local-scope-in-functions.md @@ -21,11 +21,11 @@ function myFun() { } ``` -The function `myFun` will return `"Head"` because the `local` version of the variable is present. +The function `myFun` will return the string `Head` because the `local` version of the variable is present. # --instructions-- -Add a local variable to `myOutfit` function to override the value of `outerWear` with `"sweater"`. +Add a local variable to `myOutfit` function to override the value of `outerWear` with the string `sweater`. # --hints-- @@ -35,7 +35,7 @@ You should not change the value of the global `outerWear`. assert(outerWear === 'T-Shirt'); ``` -`myOutfit` should return `"sweater"`. +`myOutfit` should return the string `sweater`. ```js assert(myOutfit() === 'sweater'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/golf-code.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/golf-code.md index c53081daa9..1fe895c71b 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/golf-code.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/golf-code.md @@ -19,67 +19,67 @@ Your function will be passed `par` and `strokes` arguments. Return the correct s # --hints-- -`golfScore(4, 1)` should return "Hole-in-one!" +`golfScore(4, 1)` should return the string `Hole-in-one!` ```js assert(golfScore(4, 1) === 'Hole-in-one!'); ``` -`golfScore(4, 2)` should return "Eagle" +`golfScore(4, 2)` should return the string `Eagle` ```js assert(golfScore(4, 2) === 'Eagle'); ``` -`golfScore(5, 2)` should return "Eagle" +`golfScore(5, 2)` should return the string `Eagle` ```js assert(golfScore(5, 2) === 'Eagle'); ``` -`golfScore(4, 3)` should return "Birdie" +`golfScore(4, 3)` should return the string `Birdie` ```js assert(golfScore(4, 3) === 'Birdie'); ``` -`golfScore(4, 4)` should return "Par" +`golfScore(4, 4)` should return the string `Par` ```js assert(golfScore(4, 4) === 'Par'); ``` -`golfScore(1, 1)` should return "Hole-in-one!" +`golfScore(1, 1)` should return the string `Hole-in-one!` ```js assert(golfScore(1, 1) === 'Hole-in-one!'); ``` -`golfScore(5, 5)` should return "Par" +`golfScore(5, 5)` should return the string `Par` ```js assert(golfScore(5, 5) === 'Par'); ``` -`golfScore(4, 5)` should return "Bogey" +`golfScore(4, 5)` should return the string `Bogey` ```js assert(golfScore(4, 5) === 'Bogey'); ``` -`golfScore(4, 6)` should return "Double Bogey" +`golfScore(4, 6)` should return the string `Double Bogey` ```js assert(golfScore(4, 6) === 'Double Bogey'); ``` -`golfScore(4, 7)` should return "Go Home!" +`golfScore(4, 7)` should return the string `Go Home!` ```js assert(golfScore(4, 7) === 'Go Home!'); ``` -`golfScore(5, 9)` should return "Go Home!" +`golfScore(5, 9)` should return the string `Go Home!` ```js assert(golfScore(5, 9) === 'Go Home!'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/increment-a-number-with-javascript.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/increment-a-number-with-javascript.md index f2d9b91295..704e46fbbd 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/increment-a-number-with-javascript.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/increment-a-number-with-javascript.md @@ -17,8 +17,7 @@ is the equivalent of `i = i + 1;` -**Note** -The entire line becomes `i++;`, eliminating the need for the equal sign. +**Note:** The entire line becomes `i++;`, eliminating the need for the equal sign. # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/introducing-else-if-statements.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/introducing-else-if-statements.md index 9ce7a4d8c6..803a30f9c8 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/introducing-else-if-statements.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/introducing-else-if-statements.md @@ -49,31 +49,31 @@ assert( ); ``` -`testElseIf(0)` should return "Smaller than 5" +`testElseIf(0)` should return the string `Smaller than 5` ```js assert(testElseIf(0) === 'Smaller than 5'); ``` -`testElseIf(5)` should return "Between 5 and 10" +`testElseIf(5)` should return the string `Between 5 and 10` ```js assert(testElseIf(5) === 'Between 5 and 10'); ``` -`testElseIf(7)` should return "Between 5 and 10" +`testElseIf(7)` should return the string `Between 5 and 10` ```js assert(testElseIf(7) === 'Between 5 and 10'); ``` -`testElseIf(10)` should return "Between 5 and 10" +`testElseIf(10)` should return the string `Between 5 and 10` ```js assert(testElseIf(10) === 'Between 5 and 10'); ``` -`testElseIf(12)` should return "Greater than 10" +`testElseIf(12)` should return the string `Greater than 10` ```js assert(testElseIf(12) === 'Greater than 10'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/introducing-else-statements.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/introducing-else-statements.md index 24e5b17225..d9dfef41b7 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/introducing-else-statements.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/introducing-else-statements.md @@ -37,25 +37,25 @@ You should use an `else` statement assert(/else/g.test(code)); ``` -`testElse(4)` should return "5 or Smaller" +`testElse(4)` should return the string `5 or Smaller` ```js assert(testElse(4) === '5 or Smaller'); ``` -`testElse(5)` should return "5 or Smaller" +`testElse(5)` should return the string `5 or Smaller` ```js assert(testElse(5) === '5 or Smaller'); ``` -`testElse(6)` should return "Bigger than 5" +`testElse(6)` should return the string `Bigger than 5` ```js assert(testElse(6) === 'Bigger than 5'); ``` -`testElse(10)` should return "Bigger than 5". +`testElse(10)` should return the string `Bigger than 5` ```js assert(testElse(10) === 'Bigger than 5'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-for-loops.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-for-loops.md index fdd4e3ee80..a5a0a63719 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-for-loops.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-for-loops.md @@ -11,19 +11,19 @@ dashedName: iterate-with-javascript-for-loops You can run the same code multiple times by using a loop. -The most common type of JavaScript loop is called a `for` loop because it runs "for" a specific number of times. +The most common type of JavaScript loop is called a `for` loop because it runs for a specific number of times. For loops are declared with three optional expressions separated by semicolons: -`for ([initialization]; [condition]; [final-expression])` +`for (a; b; c)`, where `a` is the intialization statement, `b` is the condition statement, and `c` is the final expression. -The `initialization` statement is executed one time only before the loop starts. It is typically used to define and setup your loop variable. +The initialization statement is executed one time only before the loop starts. It is typically used to define and setup your loop variable. -The `condition` statement is evaluated at the beginning of every loop iteration and will continue as long as it evaluates to `true`. When `condition` is `false` at the start of the iteration, the loop will stop executing. This means if `condition` starts as `false`, your loop will never execute. +The condition statement is evaluated at the beginning of every loop iteration and will continue as long as it evaluates to `true`. When the condition is `false` at the start of the iteration, the loop will stop executing. This means if the condition starts as false, your loop will never execute. -The `final-expression` is executed at the end of each loop iteration, prior to the next `condition` check and is usually used to increment or decrement your loop counter. +The final expression is executed at the end of each loop iteration, prior to the next condition check and is usually used to increment or decrement your loop counter. -In the following example we initialize with `i = 0` and iterate while our condition `i < 5` is true. We'll increment `i` by `1` in each loop iteration with `i++` as our `final-expression`. +In the following example we initialize with `i = 0` and iterate while our condition `i < 5` is true. We'll increment `i` by `1` in each loop iteration with `i++` as our final expression. ```js var ourArray = []; @@ -32,11 +32,11 @@ for (var i = 0; i < 5; i++) { } ``` -`ourArray` will now contain `[0,1,2,3,4]`. +`ourArray` will now have the value `[0,1,2,3,4]`. # --instructions-- -Use a `for` loop to work to push the values 1 through 5 onto `myArray`. +Use a `for` loop to push the values 1 through 5 onto `myArray`. # --hints-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-while-loops.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-while-loops.md index 3b9dfd4048..1352d3e88d 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-while-loops.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-while-loops.md @@ -11,7 +11,7 @@ dashedName: iterate-with-javascript-while-loops You can run the same code multiple times by using a loop. -The first type of loop we will learn is called a `while` loop because it runs "while" a specified condition is true and stops once that condition is no longer true. +The first type of loop we will learn is called a `while` loop because it runs while a specified condition is true and stops once that condition is no longer true. ```js var ourArray = []; diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/local-scope-and-functions.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/local-scope-and-functions.md index 14d1ca237c..ac3ac95d15 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/local-scope-and-functions.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/local-scope-and-functions.md @@ -9,7 +9,7 @@ dashedName: local-scope-and-functions # --description-- -Variables which are declared within a function, as well as the function parameters have local scope. That means, they are only visible within that function. +Variables which are declared within a function, as well as the function parameters, have local scope. That means they are only visible within that function. Here is a function `myTest` with a local variable called `loc`. @@ -18,17 +18,17 @@ function myTest() { var loc = "foo"; console.log(loc); } -myTest(); // logs "foo" -console.log(loc); // loc is not defined +myTest(); +console.log(loc); ``` -`loc` is not defined outside of the function. +The `myTest()` function call will display the string `foo` in the console. The `console.log(loc)` line will throw an error, as `loc` is not defined outside of the function. # --instructions-- The editor has two `console.log`s to help you see what is happening. Check the console as you code to see how it changes. Declare a local variable `myVar` inside `myLocalScope` and run the tests. -**Note:** The console will still have 'ReferenceError: myVar is not defined', but this will not cause the tests to fail. +**Note:** The console will still display `ReferenceError: myVar is not defined`, but this will not cause the tests to fail. # --hints-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/logical-order-in-if-else-statements.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/logical-order-in-if-else-statements.md index 55c074ae99..c86a9a9a7c 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/logical-order-in-if-else-statements.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/logical-order-in-if-else-statements.md @@ -46,29 +46,31 @@ function bar(x) { While these two functions look nearly identical if we pass a number to both we get different outputs. ```js -foo(0) // "Less than one" -bar(0) // "Less than two" +foo(0) +bar(0) ``` +`foo(0)` will return the string `Less than one`, and `bar(0)` will return the string `Less than two`. + # --instructions-- Change the order of logic in the function so that it will return the correct statements in all cases. # --hints-- -`orderMyLogic(4)` should return "Less than 5" +`orderMyLogic(4)` should return the string `Less than 5` ```js assert(orderMyLogic(4) === 'Less than 5'); ``` -`orderMyLogic(6)` should return "Less than 10" +`orderMyLogic(6)` should return the string `Less than 10` ```js assert(orderMyLogic(6) === 'Less than 10'); ``` -`orderMyLogic(11)` should return "Greater than or equal to 10" +`orderMyLogic(11)` should return the string `Greater than or equal to 10` ```js assert(orderMyLogic(11) === 'Greater than or equal to 10'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-pop.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-pop.md index ae2cc7fab3..0a0cfbe9d7 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-pop.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-pop.md @@ -11,20 +11,22 @@ dashedName: manipulate-arrays-with-pop Another way to change the data in an array is with the `.pop()` function. -`.pop()` is used to "pop" a value off of the end of an array. We can store this "popped off" value by assigning it to a variable. In other words, `.pop()` removes the last element from an array and returns that element. +`.pop()` is used to pop a value off of the end of an array. We can store this popped off value by assigning it to a variable. In other words, `.pop()` removes the last element from an array and returns that element. -Any type of entry can be "popped" off of an array - numbers, strings, even nested arrays. +Any type of entry can be popped off of an array - numbers, strings, even nested arrays. ```js var threeArr = [1, 4, 6]; var oneDown = threeArr.pop(); -console.log(oneDown); // Returns 6 -console.log(threeArr); // Returns [1, 4] +console.log(oneDown); +console.log(threeArr); ``` +The first `console.log` will display the value `6`, and the second will display the value `[1, 4]`. + # --instructions-- -Use the `.pop()` function to remove the last item from `myArray`, assigning the "popped off" value to `removedFromMyArray`. +Use the `.pop()` function to remove the last item from `myArray`, assigning the popped off value to `removedFromMyArray`. # --hints-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-push.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-push.md index b6fcea0681..5770ab00a5 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-push.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-push.md @@ -18,13 +18,13 @@ Examples: ```js var arr1 = [1,2,3]; arr1.push(4); -// arr1 is now [1,2,3,4] var arr2 = ["Stimpson", "J", "cat"]; arr2.push(["happy", "joy"]); -// arr2 now equals ["Stimpson", "J", "cat", ["happy", "joy"]] ``` +`arr1` now has the value `[1, 2, 3, 4]` and `arr2` has the value `["Stimpson", "J", "cat", ["happy", "joy"]]`. + # --instructions-- Push `["dog", 3]` onto the end of the `myArray` variable. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-shift.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-shift.md index 4a68ea9135..b2cfc4b051 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-shift.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-shift.md @@ -18,9 +18,10 @@ Example: ```js var ourArray = ["Stimpson", "J", ["cat"]]; var removedFromOurArray = ourArray.shift(); -// removedFromOurArray now equals "Stimpson" and ourArray now equals ["J", ["cat"]]. ``` +`removedFromOurArray` would have a value of the string `Stimpson`, and `ourArray` would have `["J", ["cat"]]`. + # --instructions-- Use the `.shift()` function to remove the first item from `myArray`, assigning the "shifted off" value to `removedFromMyArray`. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-unshift.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-unshift.md index d6be54037c..cf5fd257b8 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-unshift.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-unshift.md @@ -17,11 +17,12 @@ Example: ```js var ourArray = ["Stimpson", "J", "cat"]; -ourArray.shift(); // ourArray now equals ["J", "cat"] +ourArray.shift(); ourArray.unshift("Happy"); -// ourArray now equals ["Happy", "J", "cat"] ``` +After the `shift`, `ourArray` would have the value `["J", "cat"]`. After the `unshift`, `ourArray` would have the value `["Happy", "J", "cat"]`. + # --instructions-- Add `["Paul",35]` to the beginning of the `myArray` variable using `unshift()`. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/manipulating-complex-objects.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/manipulating-complex-objects.md index 61d0af1cda..09fdda0d1a 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/manipulating-complex-objects.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/manipulating-complex-objects.md @@ -29,7 +29,7 @@ var ourMusic = [ ]; ``` -This is an array which contains one object inside. The object has various pieces of metadata about an album. It also has a nested `"formats"` array. If you want to add more album records, you can do this by adding records to the top level array. Objects hold data in a property, which has a key-value format. In the example above, `"artist": "Daft Punk"` is a property that has a key of `"artist"` and a value of `"Daft Punk"`. [JavaScript Object Notation](http://www.json.org/) or `JSON` is a related data interchange format used to store data. +This is an array which contains one object inside. The object has various pieces of metadata about an album. It also has a nested `formats` array. If you want to add more album records, you can do this by adding records to the top level array. Objects hold data in a property, which has a key-value format. In the example above, `"artist": "Daft Punk"` is a property that has a key of `artist` and a value of `Daft Punk`. [JavaScript Object Notation](http://www.json.org/) or `JSON` is a related data interchange format used to store data. ```json { @@ -45,8 +45,7 @@ This is an array which contains one object inside. The object has various pieces } ``` -**Note** -You will need to place a comma after every object in the array, unless it is the last object in the array. +**Note:** You will need to place a comma after every object in the array, unless it is the last object in the array. # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/modify-array-data-with-indexes.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/modify-array-data-with-indexes.md index 86fa3ee5ba..3c32397583 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/modify-array-data-with-indexes.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/modify-array-data-with-indexes.md @@ -15,11 +15,12 @@ Unlike strings, the entries of arrays are mutable and can be changed ```js var ourArray = [50,40,30]; -ourArray[0] = 15; // equals [15,40,30] +ourArray[0] = 15; ``` -**Note** -There shouldn't be any spaces between the array name and the square brackets, like `array [0]`. Although JavaScript is able to process this correctly, this may confuse other programmers reading your code. +`ourArray` now has the value `[15, 40, 30]`. + +**Note:** There shouldn't be any spaces between the array name and the square brackets, like `array [0]`. Although JavaScript is able to process this correctly, this may confuse other programmers reading your code. # --instructions-- @@ -27,7 +28,7 @@ Modify the data stored at index `0` of `myArray` to a value of `45`. # --hints-- -`myArray` should now be [45,64,99]. +`myArray` should now be `[45,64,99]`. ```js assert( diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/multiple-identical-options-in-switch-statements.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/multiple-identical-options-in-switch-statements.md index 72b18e4928..ad2c7e1643 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/multiple-identical-options-in-switch-statements.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/multiple-identical-options-in-switch-statements.md @@ -29,64 +29,63 @@ Cases for 1, 2, and 3 will all produce the same result. # --instructions-- Write a switch statement to set `answer` for the following ranges: -`1-3` - "Low" -`4-6` - "Mid" -`7-9` - "High" +`1-3` - `Low` +`4-6` - `Mid` +`7-9` - `High` -**Note** -You will need to have a `case` statement for each number in the range. +**Note:** You will need to have a `case` statement for each number in the range. # --hints-- -`sequentialSizes(1)` should return "Low" +`sequentialSizes(1)` should return the string `Low` ```js assert(sequentialSizes(1) === 'Low'); ``` -`sequentialSizes(2)` should return "Low" +`sequentialSizes(2)` should return the string `Low` ```js assert(sequentialSizes(2) === 'Low'); ``` -`sequentialSizes(3)` should return "Low" +`sequentialSizes(3)` should return the string `Low` ```js assert(sequentialSizes(3) === 'Low'); ``` -`sequentialSizes(4)` should return "Mid" +`sequentialSizes(4)` should return the string `Mid` ```js assert(sequentialSizes(4) === 'Mid'); ``` -`sequentialSizes(5)` should return "Mid" +`sequentialSizes(5)` should return the string `Mid` ```js assert(sequentialSizes(5) === 'Mid'); ``` -`sequentialSizes(6)` should return "Mid" +`sequentialSizes(6)` should return the string `Mid` ```js assert(sequentialSizes(6) === 'Mid'); ``` -`sequentialSizes(7)` should return "High" +`sequentialSizes(7)` should return the string `High` ```js assert(sequentialSizes(7) === 'High'); ``` -`sequentialSizes(8)` should return "High" +`sequentialSizes(8)` should return the string `High` ```js assert(sequentialSizes(8) === 'High'); ``` -`sequentialSizes(9)` should return "High" +`sequentialSizes(9)` should return the string `High` ```js assert(sequentialSizes(9) === 'High'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-numbers-with-javascript.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-numbers-with-javascript.md index 5be738a56f..a67c6a1d38 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-numbers-with-javascript.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/multiply-two-numbers-with-javascript.md @@ -16,9 +16,11 @@ JavaScript uses the `*` symbol for multiplication of two numbers. **Example** ```js -myVar = 13 * 13; // assigned 169 +myVar = 13 * 13; ``` +`myVar` would have the value `169`. + # --instructions-- Change the `0` so that product will equal `80`. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/practice-comparing-different-values.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/practice-comparing-different-values.md index c97f6c7eb9..020af1ac5f 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/practice-comparing-different-values.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/practice-comparing-different-values.md @@ -15,32 +15,30 @@ If the values being compared are not of the same type, the equality operator wil **Examples** -```js -3 == '3' // returns true because JavaScript performs type conversion from string to number -3 === '3' // returns false because the types are different and type conversion is not performed -``` +`3 == '3'` returns `true` because JavaScript performs type conversion from string to number. `3 === '3'` returns false because the types are different and type conversion is not performed. -**Note** -In JavaScript, you can determine the type of a variable or a value with the `typeof` operator, as follows: +**Note:** In JavaScript, you can determine the type of a variable or a value with the `typeof` operator, as follows: ```js -typeof 3 // returns 'number' -typeof '3' // returns 'string' +typeof 3 +typeof '3' ``` +`typeof 3` returns the string `number`, and `typeof '3'` returns the string `string`. + # --instructions-- -The `compareEquality` function in the editor compares two values using the equality operator. Modify the function so that it returns "Equal" only when the values are strictly equal. +The `compareEquality` function in the editor compares two values using the equality operator. Modify the function so that it returns the string `Equal` only when the values are strictly equal. # --hints-- -`compareEquality(10, "10")` should return "Not Equal" +`compareEquality(10, "10")` should return the string `Not Equal` ```js assert(compareEquality(10, '10') === 'Not Equal'); ``` -`compareEquality("20", 20)` should return "Not Equal" +`compareEquality("20", 20)` should return the string `Not Equal` ```js assert(compareEquality('20', 20) === 'Not Equal'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/profile-lookup.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/profile-lookup.md index 4f2c51e24c..36cbecd62c 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/profile-lookup.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/profile-lookup.md @@ -17,13 +17,13 @@ The function should check if `name` is an actual contact's `firstName` and the g If both are true, then return the "value" of that property. -If `name` does not correspond to any contacts then return `"No such contact"`. +If `name` does not correspond to any contacts then return the string `No such contact`. -If `prop` does not correspond to any valid properties of a contact found to match `name` then return `"No such property"`. +If `prop` does not correspond to any valid properties of a contact found to match `name` then return the string `No such property`. # --hints-- -`lookUpProfile("Kristian", "lastName")` should return `"Vos"` +`lookUpProfile("Kristian", "lastName")` should return the string `Vos` ```js assert(lookUpProfile('Kristian', 'lastName') === 'Vos'); @@ -44,19 +44,19 @@ assert.deepEqual(lookUpProfile('Sherlock', 'likes'), [ assert(typeof lookUpProfile('Harry', 'likes') === 'object'); ``` -`lookUpProfile("Bob", "number")` should return "No such contact" +`lookUpProfile("Bob", "number")` should return the string `No such contact` ```js assert(lookUpProfile('Bob', 'number') === 'No such contact'); ``` -`lookUpProfile("Bob", "potato")` should return "No such contact" +`lookUpProfile("Bob", "potato")` should return the string `No such contact` ```js assert(lookUpProfile('Bob', 'potato') === 'No such contact'); ``` -`lookUpProfile("Akira", "address")` should return "No such property" +`lookUpProfile("Akira", "address")` should return the string `No such property` ```js assert(lookUpProfile('Akira', 'address') === 'No such property'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/quoting-strings-with-single-quotes.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/quoting-strings-with-single-quotes.md index f7a36cb16d..e9b686d18b 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/quoting-strings-with-single-quotes.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/quoting-strings-with-single-quotes.md @@ -26,12 +26,14 @@ However, this becomes a problem if you need to use the outermost quotes within i ```js goodStr = 'Jake asks Finn, "Hey, let\'s go on an adventure?"'; -badStr = 'Finn responds, "Let's go!"'; // Throws an error +badStr = 'Finn responds, "Let's go!"'; ``` -In the goodStr above, you can use both quotes safely by using the backslash \\ as an escape character. +Here `badStr` will throw an error. -**Note:** The backslash \\ should not be confused with the forward slash `/`. They do not do the same thing. +In the goodStr above, you can use both quotes safely by using the backslash `\` as an escape character. + +**Note:** The backslash `\` should not be confused with the forward slash `/`. They do not do the same thing. # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/record-collection.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/record-collection.md index d3335ba646..58647209e7 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/record-collection.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/record-collection.md @@ -22,7 +22,7 @@ You start with an `updateRecords` function that takes an object like `collection # --hints-- -After `updateRecords(collection, 5439, "artist", "ABBA")`, `artist` should be `ABBA` +After `updateRecords(collection, 5439, "artist", "ABBA")`, `artist` should be the string `ABBA` ```js assert( @@ -31,7 +31,7 @@ assert( ); ``` -After `updateRecords(collection, 5439, "tracks", "Take a Chance on Me")`, `tracks` should have `Take a Chance on Me` as the last element. +After `updateRecords(collection, 5439, "tracks", "Take a Chance on Me")`, `tracks` should have the string `Take a Chance on Me` as the last element. ```js assert( @@ -48,7 +48,7 @@ updateRecords(_recordCollection, 2548, 'artist', ''); assert(!_recordCollection[2548].hasOwnProperty('artist')); ``` -After `updateRecords(collection, 1245, "tracks", "Addicted to Love")`, `tracks` should have `Addicted to Love` as the last element. +After `updateRecords(collection, 1245, "tracks", "Addicted to Love")`, `tracks` should have the string `Addicted to Love` as the last element. ```js assert( @@ -58,7 +58,7 @@ assert( ); ``` -After `updateRecords(collection, 2468, "tracks", "Free")`, `tracks` should have `1999` as the first element. +After `updateRecords(collection, 2468, "tracks", "Free")`, `tracks` should have the string `1999` as the first element. ```js assert( @@ -75,7 +75,7 @@ updateRecords(_recordCollection, 2548, 'tracks', ''); assert(!_recordCollection[2548].hasOwnProperty('tracks')); ``` -After `updateRecords(collection, 1245, "albumTitle", "Riptide")`, `albumTitle` should be `Riptide` +After `updateRecords(collection, 1245, "albumTitle", "Riptide")`, `albumTitle` should be the string `Riptide` ```js assert( diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/replacing-if-else-chains-with-switch.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/replacing-if-else-chains-with-switch.md index e724c8821c..02dc869675 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/replacing-if-else-chains-with-switch.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/replacing-if-else-chains-with-switch.md @@ -60,43 +60,43 @@ You should have at least four `break` statements assert(code.match(/break/g).length >= 4); ``` -`chainToSwitch("bob")` should be "Marley" +`chainToSwitch("bob")` should be the string `Marley` ```js assert(chainToSwitch('bob') === 'Marley'); ``` -`chainToSwitch(42)` should be "The Answer" +`chainToSwitch(42)` should be the string `The Answer` ```js assert(chainToSwitch(42) === 'The Answer'); ``` -`chainToSwitch(1)` should be "There is no #1" +`chainToSwitch(1)` should be the string `There is no #1` ```js assert(chainToSwitch(1) === 'There is no #1'); ``` -`chainToSwitch(99)` should be "Missed me by this much!" +`chainToSwitch(99)` should be the string `Missed me by this much!` ```js assert(chainToSwitch(99) === 'Missed me by this much!'); ``` -`chainToSwitch(7)` should be "Ate Nine" +`chainToSwitch(7)` should be the string `Ate Nine` ```js assert(chainToSwitch(7) === 'Ate Nine'); ``` -`chainToSwitch("John")` should be "" (empty string) +`chainToSwitch("John")` should be `""` (empty string) ```js assert(chainToSwitch('John') === ''); ``` -`chainToSwitch(156)` should be "" (empty string) +`chainToSwitch(156)` should be `""` (empty string) ```js assert(chainToSwitch(156) === ''); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/return-a-value-from-a-function-with-return.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/return-a-value-from-a-function-with-return.md index 1ba77e0bff..f566ef2634 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/return-a-value-from-a-function-with-return.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/return-a-value-from-a-function-with-return.md @@ -17,9 +17,11 @@ We can pass values into a function with arguments. You can use a `ret function plusThree(num) { return num + 3; } -var answer = plusThree(5); // 8 +var answer = plusThree(5); ``` +`answer` has the value `8`. + `plusThree` takes an argument for `num` and returns a value equal to `num + 3`. # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/return-early-pattern-for-functions.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/return-early-pattern-for-functions.md index b51c7ebdb8..6cec2141cf 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/return-early-pattern-for-functions.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/return-early-pattern-for-functions.md @@ -22,7 +22,7 @@ function myFun() { myFun(); ``` -The above outputs "Hello" to the console, returns "World", but `"byebye"` is never output, because the function exits at the `return` statement. +The above will display the string `Hello` in the console, and return the string `World`. The string `byebye` will never display in the console, because the function exits at the `return` statement. # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/returning-boolean-values-from-functions.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/returning-boolean-values-from-functions.md index 1aabc48cbe..93e720df7c 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/returning-boolean-values-from-functions.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/returning-boolean-values-from-functions.md @@ -11,7 +11,7 @@ dashedName: returning-boolean-values-from-functions You may recall from [Comparison with the Equality Operator](/learn/javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-equality-operator) that all comparison operators return a boolean `true` or `false` value. -Sometimes people use an if/else statement to do a comparison, like this: +Sometimes people use an `if/else` statement to do a comparison, like this: ```js function isEqual(a,b) { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/selecting-from-many-options-with-switch-statements.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/selecting-from-many-options-with-switch-statements.md index 3e6c185dd0..81ea5ba048 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/selecting-from-many-options-with-switch-statements.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/selecting-from-many-options-with-switch-statements.md @@ -29,32 +29,32 @@ switch(lowercaseLetter) { # --instructions-- Write a switch statement which tests `val` and sets `answer` for the following conditions: -`1` - "alpha" -`2` - "beta" -`3` - "gamma" -`4` - "delta" +`1` - `alpha` +`2` - `beta` +`3` - `gamma` +`4` - `delta` # --hints-- -`caseInSwitch(1)` should have a value of "alpha" +`caseInSwitch(1)` should have a value of the string `alpha` ```js assert(caseInSwitch(1) === 'alpha'); ``` -`caseInSwitch(2)` should have a value of "beta" +`caseInSwitch(2)` should have a value of the string `beta` ```js assert(caseInSwitch(2) === 'beta'); ``` -`caseInSwitch(3)` should have a value of "gamma" +`caseInSwitch(3)` should have a value of the string `gamma` ```js assert(caseInSwitch(3) === 'gamma'); ``` -`caseInSwitch(4)` should have a value of "delta" +`caseInSwitch(4)` should have a value of the string `delta` ```js assert(caseInSwitch(4) === 'delta'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/subtract-one-number-from-another-with-javascript.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/subtract-one-number-from-another-with-javascript.md index e4b1e9c346..295cab9988 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/subtract-one-number-from-another-with-javascript.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/subtract-one-number-from-another-with-javascript.md @@ -16,9 +16,10 @@ JavaScript uses the `-` symbol for subtraction. **Example** ```js -myVar = 12 - 6; // assigned 6 +myVar = 12 - 6; ``` +`myVar` would have the value `6`. # --instructions-- Change the `0` so the difference is `12`. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties.md index d6c053d601..8266e86836 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties.md @@ -18,17 +18,19 @@ var myObj = { top: "hat", bottom: "pants" }; -myObj.hasOwnProperty("top"); // true -myObj.hasOwnProperty("middle"); // false +myObj.hasOwnProperty("top"); +myObj.hasOwnProperty("middle"); ``` +The first `hasOwnProperty` returns `true`, while the second returns `false`. + # --instructions-- Modify the function `checkObj` to test if an object passed to the function (`obj`) contains a specific property (`checkProp`). If the property is found, return that property's value. If not, return `"Not Found"`. # --hints-- -`checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift")` should return `"pony"`. +`checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift")` should return the string `pony`. ```js assert( @@ -36,7 +38,7 @@ assert( ); ``` -`checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "pet")` should return `"kitten"`. +`checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "pet")` should return the string `kitten`. ```js assert( @@ -44,7 +46,7 @@ assert( ); ``` -`checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "house")` should return `"Not Found"`. +`checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "house")` should return the string `Not Found`. ```js assert( @@ -53,19 +55,19 @@ assert( ); ``` -`checkObj({city: "Seattle"}, "city")` should return `"Seattle"`. +`checkObj({city: "Seattle"}, "city")` should return the string `Seattle`. ```js assert(checkObj({ city: 'Seattle' }, 'city') === 'Seattle'); ``` -`checkObj({city: "Seattle"}, "district")` should return `"Not Found"`. +`checkObj({city: "Seattle"}, "district")` should return the string `Not Found`. ```js assert(checkObj({ city: 'Seattle' }, 'district') === 'Not Found'); ``` -`checkObj({pet: "kitten", bed: "sleigh"}, "gift")` should return `"Not Found"`. +`checkObj({pet: "kitten", bed: "sleigh"}, "gift")` should return the string `Not Found`. ```js assert(checkObj({ pet: 'kitten', bed: 'sleigh' }, 'gift') === 'Not Found'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/understand-string-immutability.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/understand-string-immutability.md index 8a78800648..89597062f4 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/understand-string-immutability.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/understand-string-immutability.md @@ -18,7 +18,7 @@ var myStr = "Bob"; myStr[0] = "J"; ``` -cannot change the value of `myStr` to "Job", because the contents of `myStr` cannot be altered. Note that this does *not* mean that `myStr` cannot be changed, just that the individual characters of a string literal cannot be changed. The only way to change `myStr` would be to assign it with a new string, like this: +cannot change the value of `myStr` to `Job`, because the contents of `myStr` cannot be altered. Note that this does *not* mean that `myStr` cannot be changed, just that the individual characters of a string literal cannot be changed. The only way to change `myStr` would be to assign it with a new string, like this: ```js var myStr = "Bob"; @@ -31,7 +31,7 @@ Correct the assignment to `myStr` so it contains the string value of `Hello Worl # --hints-- -`myStr` should have a value of `Hello World`. +`myStr` should have a value of the string `Hello World`. ```js assert(myStr === 'Hello World'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-boolean-values.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-boolean-values.md index 2348481a8d..5086886e64 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-boolean-values.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-boolean-values.md @@ -9,10 +9,9 @@ dashedName: understanding-boolean-values # --description-- -Another data type is the Boolean. Booleans may only be one of two values: `true` or `false`. They are basically little on-off switches, where `true` is "on" and `false` is "off". These two states are mutually exclusive. +Another data type is the Boolean. Booleans may only be one of two values: `true` or `false`. They are basically little on-off switches, where `true` is on and `false` is off. These two states are mutually exclusive. -**Note** -Boolean values are never written with quotes. The strings `"true"` and `"false"` are not Boolean and have no special meaning in JavaScript. +**Note:** Boolean values are never written with quotes. The strings `"true"` and `"false"` are not Boolean and have no special meaning in JavaScript. # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-case-sensitivity-in-variables.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-case-sensitivity-in-variables.md index e7fcb1247b..93c8577ac6 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-case-sensitivity-in-variables.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-case-sensitivity-in-variables.md @@ -27,7 +27,8 @@ var thisVariableNameIsSoLong; # --instructions-- -Modify the existing declarations and assignments so their names use camelCase. +Modify the existing declarations and assignments so their names use camelCase. + Do not create any new variables. # --hints-- @@ -38,7 +39,7 @@ Do not create any new variables. assert(typeof studlyCapVar !== 'undefined' && studlyCapVar === 10); ``` -`properCamelCase` should be defined and have a value of `"A String"`. +`properCamelCase` should be defined and have a value of the string `A String`. ```js assert( diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-undefined-value-returned-from-a-function.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-undefined-value-returned-from-a-function.md index 94aa143e1e..bf8bd5a27a 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-undefined-value-returned-from-a-function.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-undefined-value-returned-from-a-function.md @@ -18,7 +18,7 @@ var sum = 0; function addSum(num) { sum = sum + num; } -addSum(3); // sum will be modified but returned value is undefined +addSum(3); ``` `addSum` is a function without a `return` statement. The function will change the global `sum` variable but the returned value of the function is `undefined`. @@ -35,7 +35,7 @@ Create a function `addFive` without any arguments. This function adds 5 to the ` assert(typeof addFive === 'function'); ``` -Once both functions have ran, the `sum` should be equal to 8. +Once both functions have run, the `sum` should be equal to `8`. ```js assert(sum === 8); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-uninitialized-variables.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-uninitialized-variables.md index 3779655066..b51f61753d 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-uninitialized-variables.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-uninitialized-variables.md @@ -9,7 +9,7 @@ dashedName: understanding-uninitialized-variables # --description-- -When JavaScript variables are declared, they have an initial value of `undefined`. If you do a mathematical operation on an `undefined` variable your result will be `NaN` which means "Not a Number". If you concatenate a string with an `undefined` variable, you will get a literal string of `"undefined"`. +When JavaScript variables are declared, they have an initial value of `undefined`. If you do a mathematical operation on an `undefined` variable your result will be `NaN` which means "Not a Number". If you concatenate a string with an `undefined` variable, you will get a literal string of `undefined`. # --instructions-- @@ -29,7 +29,7 @@ assert(typeof a === 'number' && a === 6); assert(typeof b === 'number' && b === 15); ``` -`c` should not contain `undefined` and should have a value of "I am a String!" +`c` should not contain `undefined` and should have a value of the string `I am a String!` ```js assert(!/undefined/.test(c) && c === 'I am a String!'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/updating-object-properties.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/updating-object-properties.md index fade65082c..3ea895350d 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/updating-object-properties.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/updating-object-properties.md @@ -22,15 +22,15 @@ var ourDog = { }; ``` -Since he's a particularly happy dog, let's change his name to "Happy Camper". Here's how we update his object's name property: `ourDog.name = "Happy Camper";` or `ourDog["name"] = "Happy Camper";` Now when we evaluate `ourDog.name`, instead of getting "Camper", we'll get his new name, "Happy Camper". +Since he's a particularly happy dog, let's change his name to the string `Happy Camper`. Here's how we update his object's name property: `ourDog.name = "Happy Camper";` or `ourDog["name"] = "Happy Camper";` Now when we evaluate `ourDog.name`, instead of getting `Camper`, we'll get his new name, `Happy Camper`. # --instructions-- -Update the `myDog` object's name property. Let's change her name from "Coder" to "Happy Coder". You can use either dot or bracket notation. +Update the `myDog` object's name property. Let's change her name from `Coder` to `Happy Coder`. You can use either dot or bracket notation. # --hints-- -You should update `myDog`'s `"name"` property to equal "Happy Coder". +You should update `myDog`'s `name` property to equal the string `Happy Coder`. ```js assert(/happy coder/gi.test(myDog.name)); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-first-character-in-a-string.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-first-character-in-a-string.md index 78c7bc400d..840f6fc61f 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-first-character-in-a-string.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-first-character-in-a-string.md @@ -9,19 +9,21 @@ dashedName: use-bracket-notation-to-find-the-first-character-in-a-string # --description-- -Bracket notation is a way to get a character at a specific `index` within a string. +Bracket notation is a way to get a character at a specific index within a string. Most modern programming languages, like JavaScript, don't start counting at 1 like humans do. They start at 0. This is referred to as Zero-based indexing. -For example, the character at index 0 in the word "Charles" is "C". So if `var firstName = "Charles"`, you can get the value of the first letter of the string by using `firstName[0]`. +For example, the character at index 0 in the word `Charles` is `C`. So if `var firstName = "Charles"`, you can get the value of the first letter of the string by using `firstName[0]`. Example: ```js var firstName = "Charles"; -var firstLetter = firstName[0]; // firstLetter is "C" +var firstLetter = firstName[0]; ``` +`firstLetter` would have a value of the string `C`. + # --instructions-- Use bracket notation to find the first character in the `lastName` variable and assign it to `firstLetterOfLastName`. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-last-character-in-a-string.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-last-character-in-a-string.md index 6643d6d469..a4ccbbc7b5 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-last-character-in-a-string.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-last-character-in-a-string.md @@ -17,9 +17,11 @@ Example: ```js var firstName = "Charles"; -var lastLetter = firstName[firstName.length - 1]; // lastLetter is "s" +var lastLetter = firstName[firstName.length - 1]; ``` +`lastLetter` would have a value of the string `s`. + # --instructions-- Use bracket notation to find the last character in the `lastName` variable. @@ -28,7 +30,7 @@ Use bracket notation to find the last character in the `lastName` var # --hints-- -`lastLetterOfLastName` should be "e". +`lastLetterOfLastName` should be the letter `e`. ```js assert(lastLetterOfLastName === 'e'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-nth-character-in-a-string.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-nth-character-in-a-string.md index b3c183a904..a7823188ae 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-nth-character-in-a-string.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-nth-character-in-a-string.md @@ -17,9 +17,11 @@ Example: ```js var firstName = "Ada"; -var secondLetterOfFirstName = firstName[1]; // secondLetterOfFirstName is "d" +var secondLetterOfFirstName = firstName[1]; ``` +`secondLetterOfFirstName` would have a value of the string `d`. + # --instructions-- Let's try to set `thirdLetterOfLastName` to equal the third letter of the `lastName` variable using bracket notation. diff --git a/curriculum/challenges/english/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/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-nth-to-last-character-in-a-string.md index 0cb27719b0..23bcd6f659 100644 --- a/curriculum/challenges/english/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/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-nth-to-last-character-in-a-string.md @@ -17,9 +17,11 @@ Example: ```js var firstName = "Charles"; -var thirdToLastLetter = firstName[firstName.length - 3]; // thirdToLastLetter is "l" +var thirdToLastLetter = firstName[firstName.length - 3]; ``` +`thirdToLastLetter` would have a value of the string `l`. + # --instructions-- Use bracket notation to find the second-to-last character in the `lastName` string. @@ -28,7 +30,7 @@ Use bracket notation to find the second-to-last character in the `las # --hints-- -`secondToLastLetterOfLastName` should be "c". +`secondToLastLetterOfLastName` should be the letter `c`. ```js assert(secondToLastLetterOfLastName === 'c'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-conditional-logic-with-if-statements.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-conditional-logic-with-if-statements.md index e90542e170..53ecda52a4 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-conditional-logic-with-if-statements.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-conditional-logic-with-if-statements.md @@ -26,15 +26,17 @@ function test (myCondition) { } return "It was false"; } -test(true); // returns "It was true" -test(false); // returns "It was false" +test(true); +test(false); ``` -When `test` is called with a value of `true`, the `if` statement evaluates `myCondition` to see if it is `true` or not. Since it is `true`, the function returns `"It was true"`. When we call `test` with a value of `false`, `myCondition` is *not* `true` and the statement in the curly braces is not executed and the function returns `"It was false"`. +`test(true)` returns the string `It was true`, and `test(false)` returns the string `It was false`. + +When `test` is called with a value of `true`, the `if` statement evaluates `myCondition` to see if it is `true` or not. Since it is `true`, the function returns `It was true`. When we call `test` with a value of `false`, `myCondition` is *not* `true` and the statement in the curly braces is not executed and the function returns `It was false`. # --instructions-- -Create an `if` statement inside the function to return `"Yes, that was true"` if the parameter `wasThatTrue` is `true` and return `"No, that was false"` otherwise. +Create an `if` statement inside the function to return `Yes, that was true` if the parameter `wasThatTrue` is `true` and return `No, that was false` otherwise. # --hints-- @@ -56,13 +58,13 @@ assert(typeof trueOrFalse(true) === 'string'); assert(typeof trueOrFalse(false) === 'string'); ``` -`trueOrFalse(true)` should return "Yes, that was true" +`trueOrFalse(true)` should return the string `Yes, that was true` ```js assert(trueOrFalse(true) === 'Yes, that was true'); ``` -`trueOrFalse(false)` should return "No, that was false" +`trueOrFalse(false)` should return the string `No, that was false` ```js assert(trueOrFalse(false) === 'No, that was false'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-multiple-conditional-ternary-operators.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-multiple-conditional-ternary-operators.md index 73a2120e7f..4852147339 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-multiple-conditional-ternary-operators.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-multiple-conditional-ternary-operators.md @@ -11,7 +11,7 @@ dashedName: use-multiple-conditional-ternary-operators In the previous challenge, you used a single conditional operator. You can also chain them together to check for multiple conditions. -The following function uses if, else if, and else statements to check multiple conditions: +The following function uses `if`, `else if`, and `else` statements to check multiple conditions: ```js function findGreaterOrEqual(a, b) { @@ -47,7 +47,7 @@ function findGreaterOrEqual(a, b) { # --instructions-- -In the `checkSign` function, use multiple conditional operators - following the recommended format used in `findGreaterOrEqual` - to check if a number is positive, negative or zero. The function should return `"positive"`, `"negative"` or `"zero"`. +In the `checkSign` function, use multiple conditional operators - following the recommended format used in `findGreaterOrEqual` - to check if a number is positive, negative or zero. The function should return `positive`, `negative` or `zero`. # --hints-- @@ -57,19 +57,19 @@ In the `checkSign` function, use multiple conditional operators - following the assert(/.+?\s*?\?\s*?.+?\s*?:\s*?.+?\s*?\?\s*?.+?\s*?:\s*?.+?/gi.test(code)); ``` -`checkSign(10)` should return "positive". Note that capitalization matters +`checkSign(10)` should return the string `positive`. Note that capitalization matters ```js assert(checkSign(10) === 'positive'); ``` -`checkSign(-12)` should return "negative". Note that capitalization matters +`checkSign(-12)` should return the string `negative`. Note that capitalization matters ```js assert(checkSign(-12) === 'negative'); ``` -`checkSign(0)` should return "zero". Note that capitalization matters +`checkSign(0)` should return the string `zero`. Note that capitalization matters ```js assert(checkSign(0) === 'zero'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-recursion-to-create-a-countdown.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-recursion-to-create-a-countdown.md index 44eace9821..6ccaa69254 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-recursion-to-create-a-countdown.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-recursion-to-create-a-countdown.md @@ -8,7 +8,7 @@ dashedName: use-recursion-to-create-a-countdown # --description-- -In a [previous challenge](/learn/javascript-algorithms-and-data-structures/basic-javascript/replace-loops-using-recursion), you learned how to use recursion to replace a for loop. Now, let's look at a more complex function that returns an array of consecutive integers starting with `1` through the number passed to the function. +In a [previous challenge](/learn/javascript-algorithms-and-data-structures/basic-javascript/replace-loops-using-recursion), you learned how to use recursion to replace a `for` loop. Now, let's look at a more complex function that returns an array of consecutive integers starting with `1` through the number passed to the function. As mentioned in the previous challenge, there will be a base case. The base case tells the recursive function when it no longer needs to call itself. It is a simple case where the return value is already known. There will also be a recursive call which executes the original function with different arguments. If the function is written correctly, eventually the base case will be reached. @@ -24,9 +24,11 @@ function countup(n) { return countArray; } } -console.log(countup(5)); // [ 1, 2, 3, 4, 5 ] +console.log(countup(5)); ``` +The value `[1, 2, 3, 4, 5]` will be displayed in the console. + At first, this seems counterintuitive since the value of `n` *decreases*, but the values in the final array are *increasing*. This happens because the push happens last, after the recursive call has returned. At the point where `n` is pushed into the array, `countup(n - 1)` has already been evaluated and returned `[1, 2, ..., n - 1]`. # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-conditional-ternary-operator.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-conditional-ternary-operator.md index 0a8808b0a8..a224b63a0a 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-conditional-ternary-operator.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-conditional-ternary-operator.md @@ -10,11 +10,9 @@ dashedName: use-the-conditional-ternary-operator The conditional operator, also called the ternary operator, can be used as a one line if-else expression. -The syntax is: +The syntax is `a ? b : c`, where `a` is the condition, `b` is the code to run when the condition returns `true`, and `c` is the code to run when the condition returns `false`. -`condition ? expression-if-true : expression-if-false;` - -The following function uses an if-else statement to check a condition: +The following function uses an `if/else` statement to check a condition: ```js function findGreater(a, b) { @@ -27,7 +25,7 @@ function findGreater(a, b) { } ``` -This can be re-written using the `conditional operator`: +This can be re-written using the conditional operator: ```js function findGreater(a, b) { @@ -37,7 +35,7 @@ function findGreater(a, b) { # --instructions-- -Use the `conditional operator` in the `checkEqual` function to check if two numbers are equal or not. The function should return either "Equal" or "Not Equal". +Use the conditional operator in the `checkEqual` function to check if two numbers are equal or not. The function should return either the string `Equal` or the string `Not Equal`. # --hints-- @@ -47,19 +45,19 @@ Use the `conditional operator` in the `checkEqual` function to check if two numb assert(/.+?\s*?\?\s*?.+?\s*?:\s*?.+?/.test(code)); ``` -`checkEqual(1, 2)` should return "Not Equal" +`checkEqual(1, 2)` should return the string `Not Equal` ```js assert(checkEqual(1, 2) === 'Not Equal'); ``` -`checkEqual(1, 1)` should return "Equal" +`checkEqual(1, 1)` should return the string `Equal` ```js assert(checkEqual(1, 1) === 'Equal'); ``` -`checkEqual(1, -1)` should return "Not Equal" +`checkEqual(1, -1)` should return the string `Not Equal` ```js assert(checkEqual(1, -1) === 'Not Equal'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function-with-a-radix.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function-with-a-radix.md index 7d83a60eb9..a106c813c3 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function-with-a-radix.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function-with-a-radix.md @@ -19,7 +19,7 @@ And here's an example: `var a = parseInt("11", 2);` -The radix variable says that "11" is in the binary system, or base 2. This example converts the string "11" to an integer 3. +The radix variable says that `11` is in the binary system, or base 2. This example converts the string `11` to an integer `3`. # --instructions-- @@ -51,7 +51,7 @@ assert(convertToInteger('10011') === 19); assert(convertToInteger('111001') === 57); ``` -`convertToInteger("JamesBond")` should return NaN +`convertToInteger("JamesBond")` should return `NaN` ```js assert.isNaN(convertToInteger('JamesBond')); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function.md index 94d85f0bdd..edab86583b 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function.md @@ -13,7 +13,7 @@ The `parseInt()` function parses a string and returns an integer. Here's an exam `var a = parseInt("007");` -The above function converts the string "007" to an integer 7. If the first character in the string can't be converted into a number, then it returns `NaN`. +The above function converts the string `007` to the integer `7`. If the first character in the string can't be converted into a number, then it returns `NaN`. # --instructions-- @@ -45,7 +45,7 @@ assert(convertToInteger('56') === 56); assert(convertToInteger('77') === 77); ``` -`convertToInteger("JamesBond")` should return NaN +`convertToInteger("JamesBond")` should return `NaN` ```js assert.isNaN(convertToInteger('JamesBond')); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/using-objects-for-lookups.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/using-objects-for-lookups.md index 1185e31c24..5d9f1071db 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/using-objects-for-lookups.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/using-objects-for-lookups.md @@ -9,7 +9,7 @@ dashedName: using-objects-for-lookups # --description-- -Objects can be thought of as a key/value storage, like a dictionary. If you have tabular data, you can use an object to "lookup" values rather than a `switch` statement or an `if/else` chain. This is most useful when you know that your input data is limited to a certain range. +Objects can be thought of as a key/value storage, like a dictionary. If you have tabular data, you can use an object to lookup values rather than a `switch` statement or an `if/else` chain. This is most useful when you know that your input data is limited to a certain range. Here is an example of a simple reverse alphabet lookup: @@ -24,50 +24,52 @@ var alpha = { 25:"B", 26:"A" }; -alpha[2]; // "Y" -alpha[24]; // "C" +alpha[2]; +alpha[24]; var value = 2; -alpha[value]; // "Y" +alpha[value]; ``` +`alpha[2]` is the string `Y`, `alpha[24]` is the string `C`, and `alpha[value]` is the string `Y`. + # --instructions-- Convert the switch statement into an object called `lookup`. Use it to look up `val` and assign the associated string to the `result` variable. # --hints-- -`phoneticLookup("alpha")` should equal `"Adams"` +`phoneticLookup("alpha")` should equal the string `Adams` ```js assert(phoneticLookup('alpha') === 'Adams'); ``` -`phoneticLookup("bravo")` should equal `"Boston"` +`phoneticLookup("bravo")` should equal the string `Boston` ```js assert(phoneticLookup('bravo') === 'Boston'); ``` -`phoneticLookup("charlie")` should equal `"Chicago"` +`phoneticLookup("charlie")` should equal the string `Chicago` ```js assert(phoneticLookup('charlie') === 'Chicago'); ``` -`phoneticLookup("delta")` should equal `"Denver"` +`phoneticLookup("delta")` should equal the string `Denver` ```js assert(phoneticLookup('delta') === 'Denver'); ``` -`phoneticLookup("echo")` should equal `"Easy"` +`phoneticLookup("echo")` should equal the string `Easy` ```js assert(phoneticLookup('echo') === 'Easy'); ``` -`phoneticLookup("foxtrot")` should equal `"Frank"` +`phoneticLookup("foxtrot")` should equal the string `Frank` ```js assert(phoneticLookup('foxtrot') === 'Frank'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/word-blanks.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/word-blanks.md index 37ab2df30c..18f4e82445 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/word-blanks.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/word-blanks.md @@ -13,7 +13,7 @@ We will now use our knowledge of strings to build a "[Mad Libs](https://en.wikip In a "Mad Libs" game, you are provided sentences with some missing words, like nouns, verbs, adjectives and adverbs. You then fill in the missing pieces with words of your choice in a way that the completed sentence makes sense. -Consider this sentence - "It was really **\_\_\_\_**, and we **\_\_\_\_** ourselves **\_\_\_\_**". This sentence has three missing pieces- an adjective, a verb and an adverb, and we can add words of our choice to complete it. We can then assign the completed sentence to a variable as follows: +Consider this sentence - It was really **\_\_\_\_**, and we **\_\_\_\_** ourselves **\_\_\_\_**. This sentence has three missing pieces- an adjective, a verb and an adverb, and we can add words of our choice to complete it. We can then assign the completed sentence to a variable as follows: ```js var sentence = "It was really " + "hot" + ", and we " + "laughed" + " ourselves " + "silly" + "."; @@ -46,7 +46,7 @@ assert( ); ``` -You should not directly use the values "dog", "ran", "big", or "quickly" to create `wordBlanks`. +You should not directly use the values `dog`, `ran`, `big`, or `quickly` to create `wordBlanks`. ```js const newCode = removeAssignments(code); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/write-reusable-javascript-with-functions.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/write-reusable-javascript-with-functions.md index 183dba49b1..904cd29231 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/write-reusable-javascript-with-functions.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/write-reusable-javascript-with-functions.md @@ -19,7 +19,7 @@ function functionName() { } ``` -You can call or invoke this function by using its name followed by parentheses, like this: `functionName();` Each time the function is called it will print out the message `"Hello World"` on the dev console. All of the code between the curly braces will be executed every time the function is called. +You can call or invoke this function by using its name followed by parentheses, like this: `functionName();` Each time the function is called it will print out the message `Hello World` on the dev console. All of the code between the curly braces will be executed every time the function is called. # --instructions-- @@ -33,7 +33,7 @@ You can call or invoke this function by using its name followed by pa assert(typeof reusableFunction === 'function'); ``` -`reusableFunction` should output "Hi World" to the dev console. +`reusableFunction` should output the string `Hi World` to the console. ```js assert(hiWorldWasLogged); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/catch-missing-open-and-closing-parenthesis-after-a-function-call.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/catch-missing-open-and-closing-parenthesis-after-a-function-call.md index 5a4e0fc060..83f757ada1 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/catch-missing-open-and-closing-parenthesis-after-a-function-call.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/catch-missing-open-and-closing-parenthesis-after-a-function-call.md @@ -16,10 +16,12 @@ The variables in the following example are different: function myFunction() { return "You rock!"; } -let varOne = myFunction; // set to equal a function -let varTwo = myFunction(); // set to equal the string "You rock!" +let varOne = myFunction; +let varTwo = myFunction(); ``` +Here `varOne` is the function `myFunction`, and `varTwo` is the string `You rock!`. + # --instructions-- Fix the code so the variable `result` is set to the value returned from calling the function `getNine`. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/catch-mixed-usage-of-single-and-double-quotes.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/catch-mixed-usage-of-single-and-double-quotes.md index cde18db798..0d11a95773 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/catch-mixed-usage-of-single-and-double-quotes.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/catch-mixed-usage-of-single-and-double-quotes.md @@ -15,17 +15,16 @@ Having two choices is great when a string has contractions or another piece of t Here are some examples of mixing quotes: ```js -// These are correct: const grouchoContraction = "I've had a perfectly wonderful evening, but this wasn't it."; const quoteInString = "Groucho Marx once said 'Quote me as saying I was mis-quoted.'"; -// This is incorrect: const uhOhGroucho = 'I've had a perfectly wonderful evening, but this wasn't it.'; ``` +The first two are correct, but the third is incorrect. + Of course, it is okay to use only one style of quotes. You can escape the quotes inside the string by using the backslash (\\) escape character: ```js -// Correct use of same quotes: const allSameQuotes = 'I\'ve had a perfectly wonderful evening, but this wasn\'t it.'; ``` @@ -35,7 +34,7 @@ Fix the string so it either uses different quotes for the `href` value, or escap # --hints-- -Your code should fix the quotes around the `href` value "#Home" by either changing or escaping them. +Your code should fix the quotes around the `href` value `#Home` by either changing or escaping them. ```js assert(code.match(//g)); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/catch-off-by-one-errors-when-using-indexing.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/catch-off-by-one-errors-when-using-indexing.md index d86487c484..1b22696596 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/catch-off-by-one-errors-when-using-indexing.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/catch-off-by-one-errors-when-using-indexing.md @@ -16,19 +16,18 @@ When you use string or array methods that take index ranges as arguments, it hel let alphabet = "abcdefghijklmnopqrstuvwxyz"; let len = alphabet.length; for (let i = 0; i <= len; i++) { - // loops one too many times at the end console.log(alphabet[i]); } for (let j = 1; j < len; j++) { - // loops one too few times and misses the first character at index 0 console.log(alphabet[j]); } for (let k = 0; k < len; k++) { - // Goldilocks approves - this is just right console.log(alphabet[k]); } ``` +The first example here loops one too many times, and the second loops one too few times (missing the first index, 0). The third example is correct. + # --instructions-- Fix the two indexing errors in the following function so all the numbers 1 through 5 are printed to the console. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/catch-unclosed-parentheses-brackets-braces-and-quotes.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/catch-unclosed-parentheses-brackets-braces-and-quotes.md index a55d812d8a..42ad053023 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/catch-unclosed-parentheses-brackets-braces-and-quotes.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/catch-unclosed-parentheses-brackets-braces-and-quotes.md @@ -24,7 +24,7 @@ Your code should fix the missing piece of the array. assert(code.match(/myArray\s*?=\s*?\[\s*?1\s*?,\s*?2\s*?,\s*?3\s*?\];/g)); ``` -Your code should fix the missing piece of the `.reduce()` method. The console output should show that "Sum of array values is: 6". +Your code should fix the missing piece of the `.reduce()` method. The console output should show that `Sum of array values is: 6`. ```js assert(arraySum === 6); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/catch-use-of-assignment-operator-instead-of-equality-operator.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/catch-use-of-assignment-operator-instead-of-equality-operator.md index e164f37399..7fea55d185 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/catch-use-of-assignment-operator-instead-of-equality-operator.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/catch-use-of-assignment-operator-instead-of-equality-operator.md @@ -20,12 +20,14 @@ The code below assigns `x` to be 2, which evaluates as `true`. Almost every valu let x = 1; let y = 2; if (x = y) { - // this code block will run for any value of y (unless y were originally set as a falsy) + } else { - // this code block is what should run (but won't) in this example + } ``` +In this example, the code block within the `if` statement will run for any value of `y`, unless `y` is falsy. The `else` block, which we expect to run here, will not actually run. + # --instructions-- Fix the condition so the program runs the right branch, and the appropriate value is assigned to `result`. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/understanding-the-differences-between-the-freecodecamp-and-browser-console.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/understanding-the-differences-between-the-freecodecamp-and-browser-console.md index 10f47a1581..d1ebf6fe82 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/understanding-the-differences-between-the-freecodecamp-and-browser-console.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/understanding-the-differences-between-the-freecodecamp-and-browser-console.md @@ -20,7 +20,7 @@ The freeCodeCamp console is cleared before the tests are run and, to avoid spam, If you would like to see every log for every test, run the tests, and open the browser console. If you prefer to use the browser console, and want it to mimic the freeCodeCamp console, place `console.clear()` before any other `console` calls, to clear the browser console. -**Note:** `console.log`s inside functions are printed to the freeCodeCamp console whenever those functions are called, this can help debugging functions that are called during testing. +**Note:** `console.log`s inside functions are printed to the freeCodeCamp console whenever those functions are called. This can help debugging functions that are called during testing. # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/use-the-javascript-console-to-check-the-value-of-a-variable.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/use-the-javascript-console-to-check-the-value-of-a-variable.md index eba2284614..63d36f81a5 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/use-the-javascript-console-to-check-the-value-of-a-variable.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/use-the-javascript-console-to-check-the-value-of-a-variable.md @@ -14,7 +14,7 @@ You can find Developer tools in your Chrome's menu or Web Console in Firefox's m The `console.log()` method, which "prints" the output of what's within its parentheses to the console, will likely be the most helpful debugging tool. Placing it at strategic points in your code can show you the intermediate values of variables. It's good practice to have an idea of what the output should be before looking at what it is. Having check points to see the status of your calculations throughout your code will help narrow down where the problem is. -Here's an example to print 'Hello world!' to the console: +Here's an example to print the string `Hello world!` to the console: `console.log('Hello world!');` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/use-typeof-to-check-the-type-of-a-variable.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/use-typeof-to-check-the-type-of-a-variable.md index e9d54bfb66..866916b9b8 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/use-typeof-to-check-the-type-of-a-variable.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/debugging/use-typeof-to-check-the-type-of-a-variable.md @@ -13,12 +13,14 @@ You can use `typeof` to check the data structure, or type, of a variable. This i Here are some examples using `typeof`: ```js -console.log(typeof ""); // outputs "string" -console.log(typeof 0); // outputs "number" -console.log(typeof []); // outputs "object" -console.log(typeof {}); // outputs "object" +console.log(typeof ""); +console.log(typeof 0); +console.log(typeof []); +console.log(typeof {}); ``` +In order, the console will display the strings `string`, `number`, `object`, and `object`. + JavaScript recognizes six primitive (immutable) data types: `Boolean`, `Null`, `Undefined`, `Number`, `String`, and `Symbol` (new with ES6) and one type for mutable items: `Object`. Note that in JavaScript, arrays are technically a type of object. # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/compare-scopes-of-the-var-and-let-keywords.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/compare-scopes-of-the-var-and-let-keywords.md index 8de15fb93c..4250078f7e 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/compare-scopes-of-the-var-and-let-keywords.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/compare-scopes-of-the-var-and-let-keywords.md @@ -20,11 +20,11 @@ for (var i = 0; i < 3; i++) { numArray.push(i); } console.log(numArray); -// returns [0, 1, 2] console.log(i); -// returns 3 ``` +Here the console will display the values `[0, 1, 2]` and `3`. + With the `var` keyword, `i` is declared globally. So when `i++` is executed, it updates the global variable. This code is similar to the following: ```js @@ -34,12 +34,12 @@ for (i = 0; i < 3; i++) { numArray.push(i); } console.log(numArray); -// returns [0, 1, 2] console.log(i); -// returns 3 ``` -This behavior will cause problems if you were to create a function and store it for later use inside a for loop that uses the `i` variable. This is because the stored function will always refer to the value of the updated global `i` variable. +Here the console will display the values `[0, 1, 2]` and `3`. + +This behavior will cause problems if you were to create a function and store it for later use inside a `for` loop that uses the `i` variable. This is because the stored function will always refer to the value of the updated global `i` variable. ```js var printNumTwo; @@ -51,9 +51,10 @@ for (var i = 0; i < 3; i++) { } } console.log(printNumTwo()); -// returns 3 ``` +Here the console will display the value `3`. + As you can see, `printNumTwo()` prints 3 and not 2. This is because the value assigned to `i` was updated and the `printNumTwo()` returns the global `i` and not the value `i` had when the function was created in the for loop. The `let` keyword does not follow this behavior: ```js @@ -66,16 +67,16 @@ for (let i = 0; i < 3; i++) { } } console.log(printNumTwo()); -// returns 2 console.log(i); -// returns "i is not defined" ``` -`i` is not defined because it was not declared in the global scope. It is only declared within the for loop statement. `printNumTwo()` returned the correct value because three different `i` variables with unique values (0, 1, and 2) were created by the `let` keyword within the loop statement. +Here the console will display the value `2`, and an error that `i is not defined`. + +`i` is not defined because it was not declared in the global scope. It is only declared within the `for` loop statement. `printNumTwo()` returned the correct value because three different `i` variables with unique values (0, 1, and 2) were created by the `let` keyword within the loop statement. # --instructions-- -Fix the code so that `i` declared in the if statement is a separate variable than `i` declared in the first line of the function. Be certain not to use the `var` keyword anywhere in your code. +Fix the code so that `i` declared in the `if` statement is a separate variable than `i` declared in the first line of the function. Be certain not to use the `var` keyword anywhere in your code. This exercise is designed to illustrate the difference between how `var` and `let` keywords assign scope to the declared variable. When programming a function similar to the one used in this exercise, it is often better to use different variable names to avoid confusion. @@ -87,7 +88,7 @@ This exercise is designed to illustrate the difference between how `var` and `le (getUserInput) => assert(!getUserInput('index').match(/var/g)); ``` -The variable `i` declared in the if statement should equal "block scope". +The variable `i` declared in the `if` statement should equal the string `block scope`. ```js (getUserInput) => @@ -96,7 +97,7 @@ The variable `i` declared in the if statement should equal "block scope". ); ``` -`checkScope()` should return "function scope" +`checkScope()` should return the string `function scope` ```js assert(checkScope() === 'function scope'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/create-a-module-script.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/create-a-module-script.md index 507602f57d..30959b42a3 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/create-a-module-script.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/create-a-module-script.md @@ -8,7 +8,7 @@ dashedName: create-a-module-script # --description-- -JavaScript started with a small role to play on an otherwise mostly HTML web. Today, it’s huge, and some websites are built almost entirely with JavaScript. In order to make JavaScript more modular, clean, and maintainable; ES6 introduced a way to easily share code among JavaScript files. This involves exporting parts of a file for use in one or more other files, and importing the parts you need, where you need them. In order to take advantage of this functionality, you need to create a script in your HTML document with a type of `module`. Here’s an example: +JavaScript started with a small role to play on an otherwise mostly HTML web. Today, it’s huge, and some websites are built almost entirely with JavaScript. In order to make JavaScript more modular, clean, and maintainable; ES6 introduced a way to easily share code among JavaScript files. This involves exporting parts of a file for use in one or more other files, and importing the parts you need, where you need them. In order to take advantage of this functionality, you need to create a script in your HTML document with a `type` of `module`. Here’s an example: ```html @@ -28,7 +28,7 @@ You should create a `script` tag. assert(code.match(/<\s*script[^>]*>\s*<\/\s*script\s*>/g)); ``` -Your `script` tag should be of type `module`. +Your `script` tag should have the `type` attribute with a value of `module`. ```js assert( diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/create-an-export-fallback-with-export-default.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/create-an-export-fallback-with-export-default.md index ac32fc0848..0f4d9c3390 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/create-an-export-fallback-with-export-default.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/create-an-export-fallback-with-export-default.md @@ -15,17 +15,17 @@ There is another `export` syntax you need to know, known as export default< Below are examples using `export default`: ```js -// named function export default function add(x, y) { return x + y; } -// anonymous function export default function(x, y) { return x + y; } ``` +The first is a named function, and the second is an anonymous function. + Since `export default` is used to declare a fallback value for a module or file, you can only have one value be a default export in each module or file. Additionally, you cannot use `export default` with `var`, `let`, or `const` # --instructions-- @@ -34,7 +34,7 @@ The following function should be the fallback value for the module. Please add t # --hints-- -Your code should use `export` fallback. +Your code should use an `export` fallback. ```js assert( diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/create-strings-using-template-literals.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/create-strings-using-template-literals.md index cd5c70bd6f..870716c3ec 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/create-strings-using-template-literals.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/create-strings-using-template-literals.md @@ -20,16 +20,14 @@ const person = { age: 56 }; -// Template literal with multi-line and string interpolation const greeting = `Hello, my name is ${person.name}! I am ${person.age} years old.`; -console.log(greeting); // prints -// Hello, my name is Zodiac Hasbro! -// I am 56 years old. - +console.log(greeting); ``` +The console will display the strings `Hello, my name is Zodiac Hasbro!` and `I am 56 years old.`. + A lot of things happened there. Firstly, the example uses backticks (`` ` ``), not quotes (`'` or `"`), to wrap the string. Secondly, notice that the string is multi-line, both in the code and the output. This saves inserting `\n` within strings. The `${variable}` syntax used above is a placeholder. Basically, you won't have to use concatenation with the `+` operator anymore. To add variables to strings, you just drop the variable in a template string and wrap it with `${` and `}`. Similarly, you can include other expressions in your string literal, for example `${a + b}`. This new way of creating strings gives you more flexibility to create robust strings. # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/declare-a-read-only-variable-with-the-const-keyword.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/declare-a-read-only-variable-with-the-const-keyword.md index a869196788..39359d0a32 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/declare-a-read-only-variable-with-the-const-keyword.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/declare-a-read-only-variable-with-the-const-keyword.md @@ -14,9 +14,11 @@ The keyword `let` is not the only new way to declare variables. In ES6, you can ```js const FAV_PET = "Cats"; -FAV_PET = "Dogs"; // returns error +FAV_PET = "Dogs"; ``` +The console will display an error due to reassigning the value of `FAV_PET`. + As you can see, trying to reassign a variable declared with `const` will throw an error. You should always name variables you don't want to reassign using the `const` keyword. This helps when you accidentally attempt to reassign a variable that is meant to stay constant. A common practice when naming constants is to use all uppercase letters, with words separated by an underscore. **Note:** It is common for developers to use uppercase variable identifiers for immutable values and lowercase or camelCase for mutable values (objects and arrays). In a later challenge you will see an example of a lowercase variable identifier being used for an array. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/explore-differences-between-the-var-and-let-keywords.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/explore-differences-between-the-var-and-let-keywords.md index 7792ee384b..f422b8c67b 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/explore-differences-between-the-var-and-let-keywords.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/explore-differences-between-the-var-and-let-keywords.md @@ -14,24 +14,27 @@ One of the biggest problems with declaring variables with the `var` keyword is t var camper = 'James'; var camper = 'David'; console.log(camper); -// logs 'David' ``` +Here the console will display the string `David`. + As you can see in the code above, the `camper` variable is originally declared as `James` and then overridden to be `David`. In a small application, you might not run into this type of problem, but when your code becomes larger, you might accidentally overwrite a variable that you did not intend to overwrite. Because this behavior does not throw an error, searching and fixing bugs becomes more difficult. A new keyword called `let` was introduced in ES6 to solve this potential issue with the `var` keyword. If you were to replace `var` with `let` in the variable declarations of the code above, the result would be an error. ```js let camper = 'James'; -let camper = 'David'; // throws an error +let camper = 'David'; ``` This error can be seen in the console of your browser. So unlike `var`, when using `let`, a variable with the same name can only be declared once. Note the `"use strict"`. This enables Strict Mode, which catches common coding mistakes and "unsafe" actions. For instance: ```js "use strict"; -x = 3.14; // throws an error because x is not declared +x = 3.14; ``` +This will display an error that `x is not defined`. + # --instructions-- Update the code so it only uses the `let` keyword. @@ -44,13 +47,13 @@ Update the code so it only uses the `let` keyword. (getUserInput) => assert(!getUserInput('index').match(/var/g)); ``` -`catName` should be `Oliver`. +`catName` should be the string `Oliver`. ```js assert(catName === 'Oliver'); ``` -`quote` should be `"Oliver says Meow!"` +`quote` should be the string `Oliver says Meow!` ```js assert(quote === 'Oliver says Meow!'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/handle-a-fulfilled-promise-with-then.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/handle-a-fulfilled-promise-with-then.md index 586153b86c..682bab1df3 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/handle-a-fulfilled-promise-with-then.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/handle-a-fulfilled-promise-with-then.md @@ -12,7 +12,7 @@ Promises are most useful when you have a process that takes an unknown amount of ```js myPromise.then(result => { - // do something with the result. + }); ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/handle-a-rejected-promise-with-catch.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/handle-a-rejected-promise-with-catch.md index aa9541a5c5..a0ac218b64 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/handle-a-rejected-promise-with-catch.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/handle-a-rejected-promise-with-catch.md @@ -12,7 +12,7 @@ dashedName: handle-a-rejected-promise-with-catch ```js myPromise.catch(error => { - // do something with the error. + }); ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/mutate-an-array-declared-with-const.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/mutate-an-array-declared-with-const.md index 90799c6bba..5f987eab1a 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/mutate-an-array-declared-with-const.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/mutate-an-array-declared-with-const.md @@ -16,11 +16,13 @@ However, it is important to understand that objects (including arrays and functi ```js const s = [5, 6, 7]; -s = [1, 2, 3]; // throws error, trying to assign a const -s[2] = 45; // works just as it would with an array declared with var or let -console.log(s); // returns [5, 6, 45] +s = [1, 2, 3]; +s[2] = 45; +console.log(s); ``` +`s = [1, 2, 3]` will result in an error. The `console.log` will display the value `[5, 6, 45]`. + As you can see, you can mutate the object `[5, 6, 7]` itself and the variable `s` will still point to the altered array `[5, 6, 45]`. Like all arrays, the array elements in `s` are mutable, but because `const` was used, you cannot use the variable identifier `s` to point to a different array using the assignment operator. # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/prevent-object-mutation.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/prevent-object-mutation.md index fb97d40308..0161194fda 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/prevent-object-mutation.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/prevent-object-mutation.md @@ -18,19 +18,20 @@ let obj = { review:"Awesome" }; Object.freeze(obj); -obj.review = "bad"; // will be ignored. Mutation not allowed -obj.newProp = "Test"; // will be ignored. Mutation not allowed +obj.review = "bad"; +obj.newProp = "Test"; console.log(obj); -// { name: "FreeCodeCamp", review:"Awesome"} ``` +The `obj.review` and `obj.newProp` assignments will result in errors, and the console will display the value `{ name: "FreeCodeCamp", review: "Awesome" }`. + # --instructions-- In this challenge you are going to use `Object.freeze` to prevent mathematical constants from changing. You need to freeze the `MATH_CONSTANTS` object so that no one is able to alter the value of `PI`, add, or delete properties. # --hints-- -You should not replace `const` keyword. +You should not replace the `const` keyword. ```js (getUserInput) => assert(getUserInput('index').match(/const/g)); @@ -43,7 +44,7 @@ You should not replace `const` keyword. assert(getUserInput('index').match(/const\s+MATH_CONSTANTS/g)); ``` -You should not change original `MATH_CONSTANTS`. +You should not change the original declaration of `MATH_CONSTANTS`. ```js (getUserInput) => diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/set-default-parameters-for-your-functions.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/set-default-parameters-for-your-functions.md index b804b67af1..0bb3fd12f2 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/set-default-parameters-for-your-functions.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/set-default-parameters-for-your-functions.md @@ -15,11 +15,13 @@ Check out this code: ```js const greeting = (name = "Anonymous") => "Hello " + name; -console.log(greeting("John")); // Hello John -console.log(greeting()); // Hello Anonymous +console.log(greeting("John")); +console.log(greeting()); ``` -The default parameter kicks in when the argument is not specified (it is undefined). As you can see in the example above, the parameter `name` will receive its default value `"Anonymous"` when you do not provide a value for the parameter. You can add default values for as many parameters as you want. +The console will display the strings `Hello John` and `Hello Anonymous`. + +The default parameter kicks in when the argument is not specified (it is undefined). As you can see in the example above, the parameter `name` will receive its default value `Anonymous` when you do not provide a value for the parameter. You can add default values for as many parameters as you want. # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-arrow-functions-to-write-concise-anonymous-functions.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-arrow-functions-to-write-concise-anonymous-functions.md index b1e92a91d2..bcf4507370 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-arrow-functions-to-write-concise-anonymous-functions.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-arrow-functions-to-write-concise-anonymous-functions.md @@ -42,7 +42,7 @@ Rewrite the function assigned to the variable `magic` which returns a `new Date( # --hints-- -User should replace `var` keyword. +You should replace the `var` keyword. ```js (getUserInput) => assert(!getUserInput('index').match(/var/g)); @@ -60,13 +60,13 @@ User should replace `var` keyword. assert(typeof magic === 'function'); ``` -`magic()` should return correct date. +`magic()` should return the correct date. ```js assert(magic().setHours(0, 0, 0, 0) === new Date().setHours(0, 0, 0, 0)); ``` -`function` keyword should not be used. +The `function` keyword should not be used. ```js (getUserInput) => assert(!getUserInput('index').match(/function/g)); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-class-syntax-to-define-a-constructor-function.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-class-syntax-to-define-a-constructor-function.md index 1a009302a0..8b847ad5fe 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-class-syntax-to-define-a-constructor-function.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-class-syntax-to-define-a-constructor-function.md @@ -12,7 +12,7 @@ ES6 provides a new syntax to create objects, using the class keyword. It should be noted that the `class` syntax is just syntax, and not a full-fledged class-based implementation of an object-oriented paradigm, unlike in languages such as Java, Python, Ruby, etc. -In ES5, we usually define a constructor function and use the `new` keyword to instantiate an object. +In ES5, we usually define a `constructor` function and use the `new` keyword to instantiate an object. ```js var SpaceShuttle = function(targetPlanet){ @@ -21,7 +21,7 @@ var SpaceShuttle = function(targetPlanet){ var zeus = new SpaceShuttle('Jupiter'); ``` -The `class` syntax simply replaces the constructor function creation: +The `class` syntax simply replaces the `constructor` function creation: ```js class SpaceShuttle { @@ -32,17 +32,17 @@ class SpaceShuttle { const zeus = new SpaceShuttle('Jupiter'); ``` -It should be noted that the `class` keyword declares a new function, to which a constructor is added. This constructor is invoked when `new` is called to create a new object. -**Notes:** +It should be noted that the `class` keyword declares a new function, to which a constructor is added. This constructor is invoked when `new` is called to create a new object. -- UpperCamelCase should be used by convention for ES6 class names, as in `SpaceShuttle` used above. -- The constructor method is a special method for creating and initializing an object created with a class. You will learn more about it in the Object Oriented Programming section of the JavaScript Algorithms And Data Structures Certification. +**Note:** UpperCamelCase should be used by convention for ES6 class names, as in `SpaceShuttle` used above. + +The `constructor` method is a special method for creating and initializing an object created with a class. You will learn more about it in the Object Oriented Programming section of the JavaScript Algorithms And Data Structures Certification. # --instructions-- -Use the `class` keyword and write a constructor to create the `Vegetable` class. +Use the `class` keyword and write a `constructor` to create the `Vegetable` class. -The `Vegetable` class allows you to create a vegetable object with a property `name` that gets passed to the constructor. +The `Vegetable` class allows you to create a vegetable object with a property `name` that gets passed to the `constructor`. # --hints-- @@ -54,7 +54,7 @@ assert( ); ``` -`class` keyword should be used. +The `class` keyword should be used. ```js assert(code.match(/class/g)); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-arrays.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-arrays.md index 1c13043c13..0660373384 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-arrays.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-arrays.md @@ -16,35 +16,39 @@ Destructuring an array lets us do exactly that: ```js const [a, b] = [1, 2, 3, 4, 5, 6]; -console.log(a, b); // 1, 2 +console.log(a, b); ``` +The console will display the values of `a` and `b` as `1, 2`. + The variable `a` is assigned the first value of the array, and `b` is assigned the second value of the array. We can also access the value at any index in an array with destructuring by using commas to reach the desired index: ```js const [a, b,,, c] = [1, 2, 3, 4, 5, 6]; -console.log(a, b, c); // 1, 2, 5 +console.log(a, b, c); ``` +The console will display the values of `a`, `b`, and `c` as `1, 2, 5`. + # --instructions-- Use destructuring assignment to swap the values of `a` and `b` so that `a` receives the value stored in `b`, and `b` receives the value stored in `a`. # --hints-- -Value of `a` should be 6, after swapping. +The value of `a` should be `6`, after swapping. ```js assert(a === 6); ``` -Value of `b` should be 8, after swapping. +The value of `b` should be `8`, after swapping. ```js assert(b === 8); ``` -You should use array destructuring to swap a and b. +You should use array destructuring to swap `a` and `b`. ```js assert(/\[\s*(\w)\s*,\s*(\w)\s*\]\s*=\s*\[\s*\2\s*,\s*\1\s*\]/g.test(code)); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-objects.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-objects.md index 0a737d8ecf..e14f1624a6 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-objects.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-objects.md @@ -20,10 +20,9 @@ Here's how you can give new variable names in the assignment: ```js const { name: userName, age: userAge } = user; -// userName = 'John Doe', userAge = 34 ``` -You may read it as "get the value of `user.name` and assign it to a new variable named `userName`" and so on. +You may read it as "get the value of `user.name` and assign it to a new variable named `userName`" and so on. The value of `userName` would be the string `John Doe`, and the value of `userAge` would be the number `34`. # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-extract-values-from-objects.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-extract-values-from-objects.md index ec873a1fa2..64232d9a25 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-extract-values-from-objects.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-extract-values-from-objects.md @@ -15,17 +15,20 @@ Consider the following ES5 code: ```js const user = { name: 'John Doe', age: 34 }; -const name = user.name; // name = 'John Doe' -const age = user.age; // age = 34 +const name = user.name; +const age = user.age; ``` +`name` would have a value of the string `John Doe`, and `age` would have the number `34`. + Here's an equivalent assignment statement using the ES6 destructuring syntax: ```js const { name, age } = user; -// name = 'John Doe', age = 34 ``` +Again, `name` would have a value of the string `John Doe`, and `age` would have the number `34`. + Here, the `name` and `age` variables will be created and assigned the values of their respective values from the `user` object. You can see how much cleaner this is. You can extract as many or few values from the object as you want. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-pass-an-object-as-a-functions-parameters.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-pass-an-object-as-a-functions-parameters.md index b142b79a75..5e5d98d9ad 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-pass-an-object-as-a-functions-parameters.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-pass-an-object-as-a-functions-parameters.md @@ -15,7 +15,7 @@ Consider the code below: ```js const profileUpdate = (profileData) => { const { name, age, nationality, location } = profileData; - // do something with these variables + } ``` @@ -23,7 +23,7 @@ This effectively destructures the object sent into the function. This can also b ```js const profileUpdate = ({ name, age, nationality, location }) => { - /* do something with these fields */ + } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-with-the-rest-parameter-to-reassign-array-elements.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-with-the-rest-parameter-to-reassign-array-elements.md index 34dd12bca2..ca574e0f17 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-with-the-rest-parameter-to-reassign-array-elements.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-with-the-rest-parameter-to-reassign-array-elements.md @@ -17,10 +17,12 @@ The result is similar to `Array.prototype.slice()`, as shown below: ```js const [a, b, ...arr] = [1, 2, 3, 4, 5, 7]; -console.log(a, b); // 1, 2 -console.log(arr); // [3, 4, 5, 7] +console.log(a, b); +console.log(arr); ``` +The console would display the values `1, 2` and `[3, 4, 5, 7]`. + Variables `a` and `b` take the first and second values from the array. After that, because of the rest parameter's presence, `arr` gets the rest of the values in the form of an array. The rest element only works correctly as the last variable in the list. As in, you cannot use the rest parameter to catch a subarray that leaves out the last element of the original array. # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-getters-and-setters-to-control-access-to-an-object.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-getters-and-setters-to-control-access-to-an-object.md index 7f9cf65691..c46878caf1 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-getters-and-setters-to-control-access-to-an-object.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-getters-and-setters-to-control-access-to-an-object.md @@ -31,16 +31,20 @@ class Book { } } const novel = new Book('anonymous'); -console.log(novel.writer); // anonymous +console.log(novel.writer); novel.writer = 'newAuthor'; -console.log(novel.writer); // newAuthor +console.log(novel.writer); ``` -Notice the syntax used to invoke the getter and setter. They do not even look like functions. Getters and setters are important because they hide internal implementation details. **Note:** It is convention to precede the name of a private variable with an underscore (`_`). However, the practice itself does not make a variable private. +The console would display the strings `anonymous` and `newAuthor`. + +Notice the syntax used to invoke the getter and setter. They do not even look like functions. Getters and setters are important because they hide internal implementation details. + +**Note:** It is convention to precede the name of a private variable with an underscore (`_`). However, the practice itself does not make a variable private. # --instructions-- -Use the `class` keyword to create a Thermostat class. The constructor accepts a Fahrenheit temperature. +Use the `class` keyword to create a `Thermostat` class. The `constructor` accepts a Fahrenheit temperature. In the class, create a `getter` to obtain the temperature in Celsius and a `setter` to set the temperature in Celsius. @@ -80,7 +84,7 @@ assert( ); ``` -When instantiated with a Fahrenheit value, `Thermostat` should set the correct temperature. +When instantiated with a Fahrenheit value, `Thermostat` should set the correct `temperature`. ```js assert( @@ -119,7 +123,7 @@ assert( ); ``` -Calling the `setter` with a Celsius value should set the temperature. +Calling the `setter` with a Celsius value should set the `temperature`. ```js assert( diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-the-rest-parameter-with-function-parameters.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-the-rest-parameter-with-function-parameters.md index 888e68da6b..2f7fe5e546 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-the-rest-parameter-with-function-parameters.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-the-rest-parameter-with-function-parameters.md @@ -16,10 +16,12 @@ Check out this code: function howMany(...args) { return "You have passed " + args.length + " arguments."; } -console.log(howMany(0, 1, 2)); // You have passed 3 arguments. -console.log(howMany("string", null, [1, 2, 3], { })); // You have passed 4 arguments. +console.log(howMany(0, 1, 2)); +console.log(howMany("string", null, [1, 2, 3], { })); ``` +The console would display the strings `You have passed 3 arguments.` and `You have passed 4 arguments.`. + The rest parameter eliminates the need to check the `args` array and allows us to apply `map()`, `filter()` and `reduce()` on the parameters array. # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-the-spread-operator-to-evaluate-arrays-in-place.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-the-spread-operator-to-evaluate-arrays-in-place.md index 9fa3b6b1b5..d2aa718923 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-the-spread-operator-to-evaluate-arrays-in-place.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-the-spread-operator-to-evaluate-arrays-in-place.md @@ -14,20 +14,24 @@ The ES5 code below uses `apply()` to compute the maximum value in an array: ```js var arr = [6, 89, 3, 45]; -var maximus = Math.max.apply(null, arr); // returns 89 +var maximus = Math.max.apply(null, arr); ``` +`maximus` would have a value of `89`. + We had to use `Math.max.apply(null, arr)` because `Math.max(arr)` returns `NaN`. `Math.max()` expects comma-separated arguments, but not an array. The spread operator makes this syntax much better to read and maintain. ```js const arr = [6, 89, 3, 45]; -const maximus = Math.max(...arr); // returns 89 +const maximus = Math.max(...arr); ``` +`maximus` would have a value of `89`. + `...arr` returns an unpacked array. In other words, it *spreads* the array. However, the spread operator only works in-place, like in an argument to a function or in an array literal. The following code will not work: ```js -const spreaded = ...arr; // will throw a syntax error +const spreaded = ...arr; ``` # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/write-arrow-functions-with-parameters.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/write-arrow-functions-with-parameters.md index 390cb0933c..1d919e2481 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/write-arrow-functions-with-parameters.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/write-arrow-functions-with-parameters.md @@ -11,26 +11,27 @@ dashedName: write-arrow-functions-with-parameters Just like a regular function, you can pass arguments into an arrow function. ```js -// doubles input value and returns it const doubler = (item) => item * 2; -doubler(4); // returns 8 +doubler(4); ``` +`doubler(4)` would return the value `8`. + If an arrow function has a single parameter, the parentheses enclosing the parameter may be omitted. ```js -// the same function, without the parameter parentheses const doubler = item => item * 2; ``` It is possible to pass more than one argument into an arrow function. ```js -// multiplies the first input value by the second and returns it const multiplier = (item, multi) => item * multi; -multiplier(4, 2); // returns 8 +multiplier(4, 2); ``` +`multiplier(4, 2)` would return the value `8`. + # --instructions-- Rewrite the `myConcat` function which appends contents of `arr2` to `arr1` so that the function uses arrow function syntax. @@ -64,7 +65,7 @@ assert( assert.deepEqual(myConcat([1, 2], [3, 4, 5]), [1, 2, 3, 4, 5]); ``` -`function` keyword should not be used. +The `function` keyword should not be used. ```js (getUserInput) => assert(!getUserInput('index').match(/function/g)); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/write-concise-declarative-functions-with-es6.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/write-concise-declarative-functions-with-es6.md index b7bd2904d8..4a0beacfc1 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/write-concise-declarative-functions-with-es6.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/write-concise-declarative-functions-with-es6.md @@ -19,7 +19,7 @@ const person = { }; ``` -With ES6, You can remove the `function` keyword and colon altogether when defining functions in objects. Here's an example of this syntax: +With ES6, you can remove the `function` keyword and colon altogether when defining functions in objects. Here's an example of this syntax: ```js const person = { diff --git a/curriculum/challenges/english/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/english/02-javascript-algorithms-and-data-structures/functional-programming/add-elements-to-the-end-of-an-array-using-concat-instead-of-push.md index 2f689c3b72..4ed68341e9 100644 --- a/curriculum/challenges/english/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/english/02-javascript-algorithms-and-data-structures/functional-programming/add-elements-to-the-end-of-an-array-using-concat-instead-of-push.md @@ -10,16 +10,16 @@ dashedName: add-elements-to-the-end-of-an-array-using-concat-instead-of-push Functional programming is all about creating and using non-mutating functions. -The last challenge introduced the `concat` method as a way to combine arrays into a new one without mutating the original arrays. Compare `concat` to the `push` method. `Push` adds an item to the end of the same array it is called on, which mutates that array. Here's an example: +The last challenge introduced the `concat` method as a way to combine arrays into a new one without mutating the original arrays. Compare `concat` to the `push` method. `push` adds an item to the end of the same array it is called on, which mutates that array. Here's an example: ```js var arr = [1, 2, 3]; arr.push([4, 5, 6]); -// arr is changed to [1, 2, 3, [4, 5, 6]] -// Not the functional programming way ``` -`Concat` offers a way to add new items to the end of an array without any mutating side effects. +`arr` would have a modified value of `[1, 2, 3, [4, 5, 6]]`, which is not the functional programming way. + +`concat` offers a way to add new items to the end of an array without any mutating side effects. # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs.md index bec46bed96..b225822761 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs.md @@ -12,7 +12,7 @@ The last several challenges covered a number of useful array and string methods Let's combine what we've learned to solve a practical problem. -Many content management sites (CMS) have the titles of a post added to part of the URL for simple bookmarking purposes. For example, if you write a Medium post titled "Stop Using Reduce", it's likely the URL would have some form of the title string in it (".../stop-using-reduce"). You may have already noticed this on the freeCodeCamp site. +Many content management sites (CMS) have the titles of a post added to part of the URL for simple bookmarking purposes. For example, if you write a Medium post titled `Stop Using Reduce`, it's likely the URL would have some form of the title string in it (`.../stop-using-reduce`). You may have already noticed this on the freeCodeCamp site. # --instructions-- @@ -34,19 +34,19 @@ Your code should not use the `replace` method for this challenge. assert(!code.match(/\.?[\s\S]*?replace/g)); ``` -`urlSlug("Winter Is Coming")` should return `"winter-is-coming"`. +`urlSlug("Winter Is Coming")` should return the string `winter-is-coming`. ```js assert(urlSlug('Winter Is Coming') === 'winter-is-coming'); ``` -`urlSlug(" Winter Is Coming")` should return `"winter-is-coming"`. +`urlSlug(" Winter Is Coming")` should return the string `winter-is-coming`. ```js assert(urlSlug(' Winter Is Coming') === 'winter-is-coming'); ``` -`urlSlug("A Mind Needs Books Like A Sword Needs A Whetstone")` should return `"a-mind-needs-books-like-a-sword-needs-a-whetstone"`. +`urlSlug("A Mind Needs Books Like A Sword Needs A Whetstone")` should return the string `a-mind-needs-books-like-a-sword-needs-a-whetstone`. ```js assert( @@ -55,7 +55,7 @@ assert( ); ``` -`urlSlug("Hold The Door")` should return `"hold-the-door"`. +`urlSlug("Hold The Door")` should return the string `hold-the-door`. ```js assert(urlSlug('Hold The Door') === 'hold-the-door'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/combine-an-array-into-a-string-using-the-join-method.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/combine-an-array-into-a-string-using-the-join-method.md index c1b662432f..350d529690 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/combine-an-array-into-a-string-using-the-join-method.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/combine-an-array-into-a-string-using-the-join-method.md @@ -15,12 +15,12 @@ Here's an example: ```js var arr = ["Hello", "World"]; var str = arr.join(" "); -// Sets str to "Hello World" ``` +`str` would have a value of the string `Hello World`. # --instructions-- -Use the `join` method (among others) inside the `sentensify` function to make a sentence from the words in the string `str`. The function should return a string. For example, "I-like-Star-Wars" would be converted to "I like Star Wars". For this challenge, do not use the `replace` method. +Use the `join` method (among others) inside the `sentensify` function to make a sentence from the words in the string `str`. The function should return a string. For example, `I-like-Star-Wars` would be converted to `I like Star Wars`. For this challenge, do not use the `replace` method. # --hints-- @@ -42,13 +42,13 @@ assert(!code.match(/\.?[\s\S]*?replace/g)); assert(typeof sentensify('May-the-force-be-with-you') === 'string'); ``` -`sentensify("May-the-force-be-with-you")` should return `"May the force be with you"`. +`sentensify("May-the-force-be-with-you")` should return the string `May the force be with you`. ```js assert(sentensify('May-the-force-be-with-you') === 'May the force be with you'); ``` -`sentensify("The.force.is.strong.with.this.one")` should return `"The force is strong with this one"`. +`sentensify("The.force.is.strong.with.this.one")` should return the string `The force is strong with this one`. ```js assert( @@ -57,7 +57,7 @@ assert( ); ``` -`sentensify("There,has,been,an,awakening")` should return `"There has been an awakening"`. +`sentensify("There,has,been,an,awakening")` should return the string `There has been an awakening`. ```js assert( diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/combine-two-arrays-using-the-concat-method.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/combine-two-arrays-using-the-concat-method.md index 4bfd0ef5c3..22afb596f1 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/combine-two-arrays-using-the-concat-method.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/combine-two-arrays-using-the-concat-method.md @@ -12,9 +12,10 @@ dashedName: combine-two-arrays-using-the-concat-method ```js [1, 2, 3].concat([4, 5, 6]); -// Returns a new array [1, 2, 3, 4, 5, 6] ``` +The returned array would be `[1, 2, 3, 4, 5, 6]`. + # --instructions-- Use the `concat` method in the `nonMutatingConcat` function to concatenate `attach` to the end of `original`. The function should return the concatenated array. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/introduction-to-currying-and-partial-application.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/introduction-to-currying-and-partial-application.md index 1d3651620f..5576adac56 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/introduction-to-currying-and-partial-application.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/introduction-to-currying-and-partial-application.md @@ -15,40 +15,38 @@ In other words, it restructures a function so it takes one argument, then return Here's an example: ```js -//Un-curried function function unCurried(x, y) { return x + y; } -//Curried function function curried(x) { return function(y) { return x + y; } } -//Alternative using ES6 + const curried = x => y => x + y -curried(1)(2) // Returns 3 +curried(1)(2) ``` +`curried(1)(2)` would return `3`. + This is useful in your program if you can't supply all the arguments to a function at one time. You can save each function call into a variable, which will hold the returned function reference that takes the next argument when it's available. Here's an example using the curried function in the example above: ```js -// Call a curried function in parts: var funcForY = curried(1); -console.log(funcForY(2)); // Prints 3 +console.log(funcForY(2)); // 3 ``` Similarly, partial application can be described as applying a few arguments to a function at a time and returning another function that is applied to more arguments. Here's an example: ```js -//Impartial function function impartial(x, y, z) { return x + y + z; } var partialFn = impartial.bind(this, 1, 2); -partialFn(10); // Returns 13 +partialFn(10); // 13 ``` # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/remove-elements-from-an-array-using-slice-instead-of-splice.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/remove-elements-from-an-array-using-slice-instead-of-splice.md index 082deb8650..e8e2542d9c 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/remove-elements-from-an-array-using-slice-instead-of-splice.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/remove-elements-from-an-array-using-slice-instead-of-splice.md @@ -12,10 +12,11 @@ A common pattern while working with arrays is when you want to remove items and ```js var cities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"]; -cities.splice(3, 1); // Returns "London" and deletes it from the cities array -// cities is now ["Chicago", "Delhi", "Islamabad", "Berlin"] +cities.splice(3, 1); ``` +Here `splice` returns the string `London` and deletes it from the cities array. `cities` will have the value `["Chicago", "Delhi", "Islamabad", "Berlin"]`. + As we saw in the last challenge, the `slice` method does not mutate the original array, but returns a new one which can be saved into a variable. Recall that the `slice` method takes two arguments for the indices to begin and end the slice (the end is non-inclusive), and returns those items in a new array. Using the `slice` method instead of `splice` helps to avoid any array-mutating side effects. # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/return-part-of-an-array-using-the-slice-method.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/return-part-of-an-array-using-the-slice-method.md index 75362aa501..2cf17e7466 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/return-part-of-an-array-using-the-slice-method.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/return-part-of-an-array-using-the-slice-method.md @@ -15,9 +15,10 @@ Here's an example: ```js var arr = ["Cat", "Dog", "Tiger", "Zebra"]; var newArray = arr.slice(1, 3); -// Sets newArray to ["Dog", "Tiger"] ``` +`newArray` would have the value `["Dog", "Tiger"]`. + # --instructions-- Use the `slice` method in the `sliceArray` function to return part of the `anim` array given the provided `beginSlice` and `endSlice` indices. The function should return an array. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/sort-an-array-alphabetically-using-the-sort-method.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/sort-an-array-alphabetically-using-the-sort-method.md index 359ea528a9..eac62b543b 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/sort-an-array-alphabetically-using-the-sort-method.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/sort-an-array-alphabetically-using-the-sort-method.md @@ -19,17 +19,21 @@ function ascendingOrder(arr) { }); } ascendingOrder([1, 5, 2, 3, 4]); -// Returns [1, 2, 3, 4, 5] +``` +This would return the value `[1, 2, 3, 4, 5]`. + +```js function reverseAlpha(arr) { return arr.sort(function(a, b) { return a === b ? 0 : a < b ? 1 : -1; }); } reverseAlpha(['l', 'h', 'z', 'b', 's']); -// Returns ['z', 's', 'l', 'h', 'b'] ``` +This would return the value `['z', 's', 'l', 'h', 'b']`. + JavaScript's default sorting method is by string Unicode point value, which may return unexpected results. Therefore, it is encouraged to provide a callback function to specify how to sort the array items. When such a callback function, normally called `compareFunction`, is supplied, the array elements are sorted according to the return value of the `compareFunction`: If `compareFunction(a,b)` returns a value less than 0 for two elements `a` and `b`, then `a` will come before `b`. If `compareFunction(a,b)` returns a value greater than 0 for two elements `a` and `b`, then `b` will come before `a`. If `compareFunction(a,b)` returns a value equal to 0 for two elements `a` and `b`, then `a` and `b` will remain unchanged. # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/split-a-string-into-an-array-using-the-split-method.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/split-a-string-into-an-array-using-the-split-method.md index 9f702386e0..d2d7eeeb9c 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/split-a-string-into-an-array-using-the-split-method.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/split-a-string-into-an-array-using-the-split-method.md @@ -15,13 +15,13 @@ Here are two examples that split one string by spaces, then another by digits us ```js var str = "Hello World"; var bySpace = str.split(" "); -// Sets bySpace to ["Hello", "World"] var otherString = "How9are7you2today"; var byDigits = otherString.split(/\d/); -// Sets byDigits to ["How", "are", "you", "today"] ``` +`bySpace` would have the value `["Hello", "World"]` and `byDigits` would have the value `["How", "are", "you", "today"]`. + Since strings are immutable, the `split` method makes it easier to work with them. # --instructions-- diff --git a/curriculum/challenges/english/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/english/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 4e63ab1df3..efea709677 100644 --- a/curriculum/challenges/english/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/english/02-javascript-algorithms-and-data-structures/functional-programming/use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria.md @@ -17,9 +17,10 @@ var numbers = [1, 5, 8, 0, 10, 11]; numbers.every(function(currentValue) { return currentValue < 10; }); -// Returns false ``` +The `every` method would return `false` here. + # --instructions-- Use the `every` method inside the `checkPositive` function to check if every element in `arr` is positive. The function should return a Boolean value. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/use-the-filter-method-to-extract-data-from-an-array.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/use-the-filter-method-to-extract-data-from-an-array.md index 0942be3924..ec50e6c5c7 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/use-the-filter-method-to-extract-data-from-an-array.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/use-the-filter-method-to-extract-data-from-an-array.md @@ -24,12 +24,14 @@ const users = [ ]; const usersUnder30 = users.filter(user => user.age < 30); -console.log(usersUnder30); // [ { name: 'Amy', age: 20 }, { name: 'camperCat', age: 10 } ] +console.log(usersUnder30); ``` +The console would display the value `[ { name: 'Amy', age: 20 }, { name: 'camperCat', age: 10 } ]`. + # --instructions-- -The variable `watchList` holds an array of objects with information on several movies. Use a combination of `filter` and `map` on `watchList` to assign a new array of objects with only `title` and `rating` keys. The new array should only include objects where `imdbRating` is greater than or equal to 8.0. Note that the rating values are saved as strings in the object and you may need to convert them into numbers to perform mathematical operations on them. +The variable `watchList` holds an array of objects with information on several movies. Use a combination of `filter` and `map` on `watchList` to assign a new array of objects with only `title` and `rating` keys. The new array should only include objects where `imdbRating` is greater than or equal to 8.0. Note that the `rating` values are saved as strings in the object and you may need to convert them into numbers to perform mathematical operations on them. # --hints-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/use-the-map-method-to-extract-data-from-an-array.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/use-the-map-method-to-extract-data-from-an-array.md index 0ddd1c3d56..7ad03df277 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/use-the-map-method-to-extract-data-from-an-array.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/use-the-map-method-to-extract-data-from-an-array.md @@ -30,9 +30,11 @@ const users = [ ]; const names = users.map(user => user.name); -console.log(names); // [ 'John', 'Amy', 'camperCat' ] +console.log(names); ``` +The console would display the value ` [ 'John', 'Amy', 'camperCat' ]`. + # --instructions-- The `watchList` array holds objects with information on several movies. Use `map` on `watchList` to assign a new array of objects with only `title` and `rating` keys to the `ratings` variable. The code in the editor currently uses a `for` loop to do this, so you should replace the loop functionality with your `map` expression. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/use-the-reduce-method-to-analyze-data.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/use-the-reduce-method-to-analyze-data.md index f9a80004a4..7c4a95e53f 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/use-the-reduce-method-to-analyze-data.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/use-the-reduce-method-to-analyze-data.md @@ -26,9 +26,11 @@ const users = [ ]; const sumOfAges = users.reduce((sum, user) => sum + user.age, 0); -console.log(sumOfAges); // 64 +console.log(sumOfAges); ``` +The console would display the value `64`. + In another example, see how an object can be returned containing the names of the users as properties with their ages as values. ```js @@ -42,12 +44,14 @@ const usersObj = users.reduce((obj, user) => { obj[user.name] = user.age; return obj; }, {}); -console.log(usersObj); // { John: 34, Amy: 20, camperCat: 10 } +console.log(usersObj); ``` +The console would display the value `{ John: 34, Amy: 20, camperCat: 10 }`. + # --instructions-- -The variable `watchList` holds an array of objects with information on several movies. Use `reduce` to find the average IMDB rating of the movies **directed by Christopher Nolan**. Recall from prior challenges how to `filter` data and `map` over it to pull what you need. You may need to create other variables, and return the average rating from `getRating` function. Note that the rating values are saved as strings in the object and need to be converted into numbers before they are used in any mathematical operations. +The variable `watchList` holds an array of objects with information on several movies. Use `reduce` to find the average IMDB rating of the movies directed by `Christopher Nolan`. Recall from prior challenges how to `filter` data and `map` over it to pull what you need. You may need to create other variables, and return the average rating from `getRating` function. Note that the rating values are saved as strings in the object and need to be converted into numbers before they are used in any mathematical operations. # --hints-- @@ -77,7 +81,7 @@ Your code should not use a `for` loop. assert(!code.match(/for\s*?\([\s\S]*?\)/g)); ``` -Your code should return correct output after modifying the `watchList` object. +Your code should return the correct output after modifying the `watchList` object. ```js assert(getRating(watchList.filter((_, i) => i < 1 || i > 2)) === 8.55); diff --git a/curriculum/challenges/english/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/english/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 3aa85c4dab..50654a12a3 100644 --- a/curriculum/challenges/english/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/english/02-javascript-algorithms-and-data-structures/functional-programming/use-the-some-method-to-check-that-any-elements-in-an-array-meet-a-criteria.md @@ -17,9 +17,10 @@ var numbers = [10, 50, 8, 220, 110, 11]; numbers.some(function(currentValue) { return currentValue < 10; }); -// Returns true ``` +The `some` method would return `true`. + # --instructions-- Use the `some` method inside the `checkPositive` function to check if any element in `arr` is positive. The function should return a Boolean value. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/arguments-optional.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/arguments-optional.md index c3c51c294d..df10073c55 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/arguments-optional.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/arguments-optional.md @@ -40,19 +40,19 @@ assert.deepEqual(addTogether(23, 30), 53); assert.deepEqual(addTogether(5)(7), 12); ``` -`addTogether("http://bit.ly/IqT6zt")` should return undefined. +`addTogether("http://bit.ly/IqT6zt")` should return `undefined`. ```js assert.isUndefined(addTogether('http://bit.ly/IqT6zt')); ``` -`addTogether(2, "3")` should return undefined. +`addTogether(2, "3")` should return `undefined`. ```js assert.isUndefined(addTogether(2, '3')); ``` -`addTogether(2)([3])` should return undefined. +`addTogether(2)([3])` should return `undefined`. ```js assert.isUndefined(addTogether(2)([3])); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/binary-agents.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/binary-agents.md index 954865c428..66194f80d7 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/binary-agents.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/binary-agents.md @@ -14,7 +14,7 @@ The binary string will be space separated. # --hints-- -`binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111")` should return "Aren't bonfires fun!?" +`binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111")` should return the string `Aren't bonfires fun!?` ```js assert.deepEqual( @@ -25,7 +25,7 @@ assert.deepEqual( ); ``` -`binaryAgent("01001001 00100000 01101100 01101111 01110110 01100101 00100000 01000110 01110010 01100101 01100101 01000011 01101111 01100100 01100101 01000011 01100001 01101101 01110000 00100001")` should return "I love FreeCodeCamp!" +`binaryAgent("01001001 00100000 01101100 01101111 01110110 01100101 00100000 01000110 01110010 01100101 01100101 01000011 01101111 01100100 01100101 01000011 01100001 01101101 01110000 00100001")` should return the string `I love FreeCodeCamp!` ```js assert.deepEqual( diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/convert-html-entities.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/convert-html-entities.md index 707290ef0c..5401c28249 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/convert-html-entities.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/convert-html-entities.md @@ -12,13 +12,13 @@ Convert the characters `&`, `<`, `>`, `"` (double quote), and `'` (apostrophe), # --hints-- -`convertHTML("Dolce & Gabbana")` should return `"Dolce & Gabbana"`. +`convertHTML("Dolce & Gabbana")` should return the string `Dolce & Gabbana`. ```js assert.match(convertHTML('Dolce & Gabbana'), /Dolce & Gabbana/); ``` -`convertHTML("Hamburgers < Pizza < Tacos")` should return `"Hamburgers < Pizza < Tacos"`. +`convertHTML("Hamburgers < Pizza < Tacos")` should return the string `Hamburgers < Pizza < Tacos`. ```js assert.match( @@ -27,13 +27,13 @@ assert.match( ); ``` -`convertHTML("Sixty > twelve")` should return `"Sixty > twelve"`. +`convertHTML("Sixty > twelve")` should return the string `Sixty > twelve`. ```js assert.match(convertHTML('Sixty > twelve'), /Sixty > twelve/); ``` -`convertHTML('Stuff in "quotation marks"')` should return `"Stuff in "quotation marks""`. +`convertHTML('Stuff in "quotation marks"')` should return the string `Stuff in "quotation marks"`. ```js assert.match( @@ -42,19 +42,19 @@ assert.match( ); ``` -`convertHTML("Schindler's List")` should return `"Schindler's List"`. +`convertHTML("Schindler's List")` should return the string `Schindler's List`. ```js assert.match(convertHTML("Schindler's List"), /Schindler's List/); ``` -`convertHTML("<>")` should return `"<>"`. +`convertHTML("<>")` should return the string `<>`. ```js assert.match(convertHTML('<>'), /<>/); ``` -`convertHTML("abc")` should return `"abc"`. +`convertHTML("abc")` should return the string `abc`. ```js assert.strictEqual(convertHTML('abc'), 'abc'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays.md index 228d55cf80..8ec9a4a02e 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays.md @@ -10,8 +10,7 @@ dashedName: diff-two-arrays Compare two arrays and return a new array with any items only found in one of the two given arrays, but not both. In other words, return the symmetric difference of the two arrays. -**Note** -You can return the array with its elements in any order. +**Note:** You can return the array with its elements in any order. # --hints-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/dna-pairing.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/dna-pairing.md index d9f36cd281..820dc6ac3e 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/dna-pairing.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/dna-pairing.md @@ -14,7 +14,7 @@ The DNA strand is missing the pairing element. Take each character, get its pair Return the provided character as the first element in each array. -For example, for the input GCG, return \[\["G", "C"], \["C","G"],\["G", "C"]] +For example, for the input `GCG`, return `[["G", "C"], ["C","G"], ["G", "C"]]` The character and its pair are paired up in an array, and all the arrays are grouped into one encapsulating array. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/everything-be-true.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/everything-be-true.md index 7a93f8ae2a..0237b81875 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/everything-be-true.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/everything-be-true.md @@ -18,7 +18,7 @@ Remember, you can access object properties through either dot notation or `[]` n # --hints-- -`truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex")` should return true. +`truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex")` should return `true`. ```js assert.strictEqual( @@ -35,7 +35,7 @@ assert.strictEqual( ); ``` -`truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex")` should return false. +`truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex")` should return `false`. ```js assert.strictEqual( @@ -52,7 +52,7 @@ assert.strictEqual( ); ``` -`truthCheck([{"user": "Tinky-Winky", "sex": "male", "age": 0}, {"user": "Dipsy", "sex": "male", "age": 3}, {"user": "Laa-Laa", "sex": "female", "age": 5}, {"user": "Po", "sex": "female", "age": 4}], "age")` should return false. +`truthCheck([{"user": "Tinky-Winky", "sex": "male", "age": 0}, {"user": "Dipsy", "sex": "male", "age": 3}, {"user": "Laa-Laa", "sex": "female", "age": 5}, {"user": "Po", "sex": "female", "age": 4}], "age")` should return `false`. ```js assert.strictEqual( @@ -69,7 +69,7 @@ assert.strictEqual( ); ``` -`truthCheck([{"name": "Pete", "onBoat": true}, {"name": "Repeat", "onBoat": true}, {"name": "FastForward", "onBoat": null}], "onBoat")` should return false +`truthCheck([{"name": "Pete", "onBoat": true}, {"name": "Repeat", "onBoat": true}, {"name": "FastForward", "onBoat": null}], "onBoat")` should return `false`. ```js assert.strictEqual( @@ -85,7 +85,7 @@ assert.strictEqual( ); ``` -`truthCheck([{"name": "Pete", "onBoat": true}, {"name": "Repeat", "onBoat": true, "alias": "Repete"}, {"name": "FastForward", "onBoat": true}], "onBoat")` should return true +`truthCheck([{"name": "Pete", "onBoat": true}, {"name": "Repeat", "onBoat": true, "alias": "Repete"}, {"name": "FastForward", "onBoat": true}], "onBoat")` should return `true`. ```js assert.strictEqual( @@ -101,13 +101,13 @@ assert.strictEqual( ); ``` -`truthCheck([{"single": "yes"}], "single")` should return true +`truthCheck([{"single": "yes"}], "single")` should return `true`. ```js assert.strictEqual(truthCheck([{ single: 'yes' }], 'single'), true); ``` -`truthCheck([{"single": ""}, {"single": "double"}], "single")` should return false +`truthCheck([{"single": ""}, {"single": "double"}], "single")` should return `false`. ```js assert.strictEqual( @@ -116,7 +116,7 @@ assert.strictEqual( ); ``` -`truthCheck([{"single": "double"}, {"single": undefined}], "single")` should return false +`truthCheck([{"single": "double"}, {"single": undefined}], "single")` should return `false`. ```js assert.strictEqual( @@ -125,7 +125,7 @@ assert.strictEqual( ); ``` -`truthCheck([{"single": "double"}, {"single": NaN}], "single")` should return false +`truthCheck([{"single": "double"}, {"single": NaN}], "single")` should return `false`. ```js assert.strictEqual( diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/make-a-person.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/make-a-person.md index b9458749e7..a01f7a9f92 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/make-a-person.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/make-a-person.md @@ -29,43 +29,43 @@ Run the tests to see the expected output for each method. The methods that take assert.deepEqual(Object.keys(bob).length, 6); ``` -`bob instanceof Person` should return true. +`bob instanceof Person` should return `true`. ```js assert.deepEqual(bob instanceof Person, true); ``` -`bob.firstName` should return undefined. +`bob.firstName` should return `undefined`. ```js assert.deepEqual(bob.firstName, undefined); ``` -`bob.lastName` should return undefined. +`bob.lastName` should return `undefined`. ```js assert.deepEqual(bob.lastName, undefined); ``` -`bob.getFirstName()` should return "Bob". +`bob.getFirstName()` should return the string `Bob`. ```js assert.deepEqual(bob.getFirstName(), 'Bob'); ``` -`bob.getLastName()` should return "Ross". +`bob.getLastName()` should return the string `Ross`. ```js assert.deepEqual(bob.getLastName(), 'Ross'); ``` -`bob.getFullName()` should return "Bob Ross". +`bob.getFullName()` should return the string `Bob Ross`. ```js assert.deepEqual(bob.getFullName(), 'Bob Ross'); ``` -`bob.getFullName()` should return "Haskell Ross" after `bob.setFirstName("Haskell")`. +`bob.getFullName()` should return the string `Haskell Ross` after `bob.setFirstName("Haskell")`. ```js assert.strictEqual( @@ -77,7 +77,7 @@ assert.strictEqual( ); ``` -`bob.getFullName()` should return "Haskell Curry" after `bob.setLastName("Curry")`. +`bob.getFullName()` should return the string `Haskell Curry` after `bob.setLastName("Curry")`. ```js assert.strictEqual( @@ -90,7 +90,7 @@ assert.strictEqual( ); ``` -`bob.getFullName()` should return "Haskell Curry" after `bob.setFullName("Haskell Curry")`. +`bob.getFullName()` should return the string `Haskell Curry` after `bob.setFullName("Haskell Curry")`. ```js assert.strictEqual( @@ -102,7 +102,7 @@ assert.strictEqual( ); ``` -`bob.getFirstName()` should return "Haskell" after `bob.setFullName("Haskell Curry")`. +`bob.getFirstName()` should return the string `Haskell` after `bob.setFullName("Haskell Curry")`. ```js assert.strictEqual( @@ -114,7 +114,7 @@ assert.strictEqual( ); ``` -`bob.getLastName()` should return "Curry" after `bob.setFullName("Haskell Curry")`. +`bob.getLastName()` should return the string `Curry` after `bob.setFullName("Haskell Curry")`. ```js assert.strictEqual( diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/missing-letters.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/missing-letters.md index c5e807a7a4..a1ecc67cbb 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/missing-letters.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/missing-letters.md @@ -10,35 +10,35 @@ dashedName: missing-letters Find the missing letter in the passed letter range and return it. -If all letters are present in the range, return undefined. +If all letters are present in the range, return `undefined`. # --hints-- -`fearNotLetter("abce")` should return "d". +`fearNotLetter("abce")` should return the string `d`. ```js assert.deepEqual(fearNotLetter('abce'), 'd'); ``` -`fearNotLetter("abcdefghjklmno")` should return "i". +`fearNotLetter("abcdefghjklmno")` should return the string `i`. ```js assert.deepEqual(fearNotLetter('abcdefghjklmno'), 'i'); ``` -`fearNotLetter("stvwx")` should return "u". +`fearNotLetter("stvwx")` should return the string `u`. ```js assert.deepEqual(fearNotLetter('stvwx'), 'u'); ``` -`fearNotLetter("bcdf")` should return "e". +`fearNotLetter("bcdf")` should return the string `e`. ```js assert.deepEqual(fearNotLetter('bcdf'), 'e'); ``` -`fearNotLetter("abcdefghijklmnopqrstuvwxyz")` should return undefined. +`fearNotLetter("abcdefghijklmnopqrstuvwxyz")` should return `undefined`. ```js assert.isUndefined(fearNotLetter('abcdefghijklmnopqrstuvwxyz')); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/pig-latin.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/pig-latin.md index af40b695bf..e355f395b3 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/pig-latin.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/pig-latin.md @@ -10,9 +10,9 @@ dashedName: pig-latin Pig Latin is a way of altering English Words. The rules are as follows: -\- If a word begins with a consonant, take the first consonant or consonant cluster, move it to the end of the word, and add "ay" to it. +\- If a word begins with a consonant, take the first consonant or consonant cluster, move it to the end of the word, and add `ay` to it. -\- If a word begins with a vowel, just add "way" at the end. +\- If a word begins with a vowel, just add `way` at the end. # --instructions-- @@ -20,43 +20,43 @@ Translate the provided string to Pig Latin. Input strings are guaranteed to be E # --hints-- -`translatePigLatin("california")` should return "aliforniacay". +`translatePigLatin("california")` should return the string `aliforniacay`. ```js assert.deepEqual(translatePigLatin('california'), 'aliforniacay'); ``` -`translatePigLatin("paragraphs")` should return "aragraphspay". +`translatePigLatin("paragraphs")` should return the string `aragraphspay`. ```js assert.deepEqual(translatePigLatin('paragraphs'), 'aragraphspay'); ``` -`translatePigLatin("glove")` should return "oveglay". +`translatePigLatin("glove")` should return the string `oveglay`. ```js assert.deepEqual(translatePigLatin('glove'), 'oveglay'); ``` -`translatePigLatin("algorithm")` should return "algorithmway". +`translatePigLatin("algorithm")` should return the string `algorithmway`. ```js assert.deepEqual(translatePigLatin('algorithm'), 'algorithmway'); ``` -`translatePigLatin("eight")` should return "eightway". +`translatePigLatin("eight")` should return the string `eightway`. ```js assert.deepEqual(translatePigLatin('eight'), 'eightway'); ``` -Should handle words where the first vowel comes in the middle of the word. `translatePigLatin("schwartz")` should return "artzschway". +Should handle words where the first vowel comes in the middle of the word. `translatePigLatin("schwartz")` should return the string `artzschway`. ```js assert.deepEqual(translatePigLatin('schwartz'), 'artzschway'); ``` -Should handle words without vowels. `translatePigLatin("rhythm")` should return "rhythmay". +Should handle words without vowels. `translatePigLatin("rhythm")` should return the string `rhythmay`. ```js assert.deepEqual(translatePigLatin('rhythm'), 'rhythmay'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/search-and-replace.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/search-and-replace.md index f4ca7362bd..1f9df37ac3 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/search-and-replace.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/search-and-replace.md @@ -16,12 +16,11 @@ Second argument is the word that you will be replacing (before). Third argument is what you will be replacing the second argument with (after). -**Note** -Preserve the case of the first character in the original word when you are replacing it. For example if you mean to replace the word "Book" with the word "dog", it should be replaced as "Dog" +**Note:** Preserve the case of the first character in the original word when you are replacing it. For example if you mean to replace the word `Book` with the word `dog`, it should be replaced as `Dog` # --hints-- -`myReplace("Let us go to the store", "store", "mall")` should return "Let us go to the mall". +`myReplace("Let us go to the store", "store", "mall")` should return the string `Let us go to the mall`. ```js assert.deepEqual( @@ -30,7 +29,7 @@ assert.deepEqual( ); ``` -`myReplace("He is Sleeping on the couch", "Sleeping", "sitting")` should return "He is Sitting on the couch". +`myReplace("He is Sleeping on the couch", "Sleeping", "sitting")` should return the string `He is Sitting on the couch`. ```js assert.deepEqual( @@ -39,7 +38,7 @@ assert.deepEqual( ); ``` -`myReplace("I think we should look up there", "up", "Down")` should return "I think we should look down there". +`myReplace("I think we should look up there", "up", "Down")` should return the string `I think we should look down there`. ```js assert.deepEqual( @@ -48,7 +47,7 @@ assert.deepEqual( ); ``` -`myReplace("This has a spellngi error", "spellngi", "spelling")` should return "This has a spelling error". +`myReplace("This has a spellngi error", "spellngi", "spelling")` should return the string `This has a spelling error`. ```js assert.deepEqual( @@ -57,7 +56,7 @@ assert.deepEqual( ); ``` -`myReplace("His name is Tom", "Tom", "john")` should return "His name is John". +`myReplace("His name is Tom", "Tom", "john")` should return the string `His name is John`. ```js assert.deepEqual( @@ -66,7 +65,7 @@ assert.deepEqual( ); ``` -`myReplace("Let us get back to more Coding", "Coding", "algorithms")` should return "Let us get back to more Algorithms". +`myReplace("Let us get back to more Coding", "Coding", "algorithms")` should return the string `Let us get back to more Algorithms`. ```js assert.deepEqual( diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/seek-and-destroy.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/seek-and-destroy.md index 5fbf7d5aa8..aa332e779e 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/seek-and-destroy.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/seek-and-destroy.md @@ -8,10 +8,9 @@ dashedName: seek-and-destroy # --description-- -You will be provided with an initial array (the first argument in the destroyer function), followed by one or more arguments. Remove all elements from the initial array that are of the same value as these arguments. +You will be provided with an initial array (the first argument in the `destroyer` function), followed by one or more arguments. Remove all elements from the initial array that are of the same value as these arguments. -**Note** -You have to use the `arguments` object. +**Note:** You have to use the `arguments` object. # --hints-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/spinal-tap-case.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/spinal-tap-case.md index c68938ce89..837188868b 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/spinal-tap-case.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/spinal-tap-case.md @@ -12,19 +12,19 @@ Convert a string to spinal case. Spinal case is all-lowercase-words-joined-by-da # --hints-- -`spinalCase("This Is Spinal Tap")` should return `"this-is-spinal-tap"`. +`spinalCase("This Is Spinal Tap")` should return the string `this-is-spinal-tap`. ```js assert.deepEqual(spinalCase('This Is Spinal Tap'), 'this-is-spinal-tap'); ``` -`spinalCase("thisIsSpinalTap")` should return `"this-is-spinal-tap"`. +`spinalCase("thisIsSpinalTap")` should return the string `this-is-spinal-tap`. ```js assert.strictEqual(spinalCase('thisIsSpinalTap'), 'this-is-spinal-tap'); ``` -`spinalCase("The_Andy_Griffith_Show")` should return `"the-andy-griffith-show"`. +`spinalCase("The_Andy_Griffith_Show")` should return the string `the-andy-griffith-show`. ```js assert.strictEqual( @@ -33,7 +33,7 @@ assert.strictEqual( ); ``` -`spinalCase("Teletubbies say Eh-oh")` should return `"teletubbies-say-eh-oh"`. +`spinalCase("Teletubbies say Eh-oh")` should return the string `teletubbies-say-eh-oh`. ```js assert.strictEqual( @@ -42,7 +42,7 @@ assert.strictEqual( ); ``` -`spinalCase("AllThe-small Things")` should return `"all-the-small-things"`. +`spinalCase("AllThe-small Things")` should return the string `all-the-small-things`. ```js assert.strictEqual(spinalCase('AllThe-small Things'), 'all-the-small-things'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/caesars-cipher.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/caesars-cipher.md index 7e0a8c9f36..b94a388ea0 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/caesars-cipher.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/caesars-cipher.md @@ -10,7 +10,7 @@ dashedName: caesars-cipher One of the simplest and most widely known ciphers is a Caesar cipher, also known as a shift cipher. In a shift cipher the meanings of the letters are shifted by some set amount. -A common modern use is the [ROT13](https://en.wikipedia.org/wiki/ROT13) cipher, where the values of the letters are shifted by 13 places. Thus 'A' ↔ 'N', 'B' ↔ 'O' and so on. +A common modern use is the [ROT13](https://en.wikipedia.org/wiki/ROT13) cipher, where the values of the letters are shifted by 13 places. Thus `A ↔ N`, `B ↔ O` and so on. Write a function which takes a [ROT13](https://en.wikipedia.org/wiki/ROT13) encoded string as input and returns a decoded string. @@ -18,25 +18,25 @@ All letters will be uppercase. Do not transform any non-alphabetic character (i. # --hints-- -`rot13("SERR PBQR PNZC")` should decode to `FREE CODE CAMP` +`rot13("SERR PBQR PNZC")` should decode to the string `FREE CODE CAMP` ```js assert(rot13('SERR PBQR PNZC') === 'FREE CODE CAMP'); ``` -`rot13("SERR CVMMN!")` should decode to `FREE PIZZA!` +`rot13("SERR CVMMN!")` should decode to the string `FREE PIZZA!` ```js assert(rot13('SERR CVMMN!') === 'FREE PIZZA!'); ``` -`rot13("SERR YBIR?")` should decode to `FREE LOVE?` +`rot13("SERR YBIR?")` should decode to the string `FREE LOVE?` ```js assert(rot13('SERR YBIR?') === 'FREE LOVE?'); ``` -`rot13("GUR DHVPX OEBJA SBK WHZCF BIRE GUR YNML QBT.")` should decode to `THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.` +`rot13("GUR DHVPX OEBJA SBK WHZCF BIRE GUR YNML QBT.")` should decode to the string `THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.` ```js assert( diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/palindrome-checker.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/palindrome-checker.md index 49ec05e0e8..e6107a26b4 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/palindrome-checker.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/palindrome-checker.md @@ -14,9 +14,9 @@ A palindrome is a word or sentence that's spelled the same way both f **Note:** You'll need to remove **all non-alphanumeric characters** (punctuation, spaces and symbols) and turn everything into the same case (lower or upper case) in order to check for palindromes. -We'll pass strings with varying formats, such as `"racecar"`, `"RaceCar"`, and `"race CAR"` among others. +We'll pass strings with varying formats, such as `racecar`, `RaceCar`, and `race CAR` among others. -We'll also pass strings with special symbols, such as `"2A3*3a2"`, `"2A3 3a2"`, and `"2_A3*3#A2"`. +We'll also pass strings with special symbols, such as `2A3*3a2`, `2A3 3a2`, and `2_A3*3#A2`. # --hints-- @@ -26,73 +26,73 @@ We'll also pass strings with special symbols, such as `"2A3*3a2"`, `"2A3 3a2"`, assert(typeof palindrome('eye') === 'boolean'); ``` -`palindrome("eye")` should return true. +`palindrome("eye")` should return `true`. ```js assert(palindrome('eye') === true); ``` -`palindrome("_eye")` should return true. +`palindrome("_eye")` should return `true`. ```js assert(palindrome('_eye') === true); ``` -`palindrome("race car")` should return true. +`palindrome("race car")` should return `true`. ```js assert(palindrome('race car') === true); ``` -`palindrome("not a palindrome")` should return false. +`palindrome("not a palindrome")` should return `false`. ```js assert(palindrome('not a palindrome') === false); ``` -`palindrome("A man, a plan, a canal. Panama")` should return true. +`palindrome("A man, a plan, a canal. Panama")` should return `true`. ```js assert(palindrome('A man, a plan, a canal. Panama') === true); ``` -`palindrome("never odd or even")` should return true. +`palindrome("never odd or even")` should return `true`. ```js assert(palindrome('never odd or even') === true); ``` -`palindrome("nope")` should return false. +`palindrome("nope")` should return `false`. ```js assert(palindrome('nope') === false); ``` -`palindrome("almostomla")` should return false. +`palindrome("almostomla")` should return `false`. ```js assert(palindrome('almostomla') === false); ``` -`palindrome("My age is 0, 0 si ega ym.")` should return true. +`palindrome("My age is 0, 0 si ega ym.")` should return `true`. ```js assert(palindrome('My age is 0, 0 si ega ym.') === true); ``` -`palindrome("1 eye for of 1 eye.")` should return false. +`palindrome("1 eye for of 1 eye.")` should return `false`. ```js assert(palindrome('1 eye for of 1 eye.') === false); ``` -`palindrome("0_0 (: /-\ :) 0-0")` should return true. +`palindrome("0_0 (: /-\ :) 0-0")` should return `true`. ```js assert(palindrome('0_0 (: /- :) 0-0') === true); ``` -`palindrome("five|\_/|four")` should return false. +`palindrome("five|\_/|four")` should return `false`. ```js assert(palindrome('five|_/|four') === false); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/roman-numeral-converter.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/roman-numeral-converter.md index 9f750e7aed..78d91a3ec9 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/roman-numeral-converter.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/roman-numeral-converter.md @@ -14,157 +14,157 @@ All [roman numerals](http://www.mathsisfun.com/roman-numerals.html) answers shou # --hints-- -`convertToRoman(2)` should return "II". +`convertToRoman(2)` should return the string `II`. ```js assert.deepEqual(convertToRoman(2), 'II'); ``` -`convertToRoman(3)` should return "III". +`convertToRoman(3)` should return the string `III`. ```js assert.deepEqual(convertToRoman(3), 'III'); ``` -`convertToRoman(4)` should return "IV". +`convertToRoman(4)` should return the string `IV`. ```js assert.deepEqual(convertToRoman(4), 'IV'); ``` -`convertToRoman(5)` should return "V". +`convertToRoman(5)` should return the string `V`. ```js assert.deepEqual(convertToRoman(5), 'V'); ``` -`convertToRoman(9)` should return "IX". +`convertToRoman(9)` should return the string `IX`. ```js assert.deepEqual(convertToRoman(9), 'IX'); ``` -`convertToRoman(12)` should return "XII". +`convertToRoman(12)` should return the string `XII`. ```js assert.deepEqual(convertToRoman(12), 'XII'); ``` -`convertToRoman(16)` should return "XVI". +`convertToRoman(16)` should return the string `XVI`. ```js assert.deepEqual(convertToRoman(16), 'XVI'); ``` -`convertToRoman(29)` should return "XXIX". +`convertToRoman(29)` should return the string `XXIX`. ```js assert.deepEqual(convertToRoman(29), 'XXIX'); ``` -`convertToRoman(44)` should return "XLIV". +`convertToRoman(44)` should return the string `XLIV`. ```js assert.deepEqual(convertToRoman(44), 'XLIV'); ``` -`convertToRoman(45)` should return "XLV" +`convertToRoman(45)` should return the string `XLV`. ```js assert.deepEqual(convertToRoman(45), 'XLV'); ``` -`convertToRoman(68)` should return "LXVIII" +`convertToRoman(68)` should return the string `LXVIII` ```js assert.deepEqual(convertToRoman(68), 'LXVIII'); ``` -`convertToRoman(83)` should return "LXXXIII" +`convertToRoman(83)` should return the string `LXXXIII` ```js assert.deepEqual(convertToRoman(83), 'LXXXIII'); ``` -`convertToRoman(97)` should return "XCVII" +`convertToRoman(97)` should return the string `XCVII` ```js assert.deepEqual(convertToRoman(97), 'XCVII'); ``` -`convertToRoman(99)` should return "XCIX" +`convertToRoman(99)` should return the string `XCIX` ```js assert.deepEqual(convertToRoman(99), 'XCIX'); ``` -`convertToRoman(400)` should return "CD" +`convertToRoman(400)` should return the string `CD` ```js assert.deepEqual(convertToRoman(400), 'CD'); ``` -`convertToRoman(500)` should return "D" +`convertToRoman(500)` should return the string `D` ```js assert.deepEqual(convertToRoman(500), 'D'); ``` -`convertToRoman(501)` should return "DI" +`convertToRoman(501)` should return the string `DI` ```js assert.deepEqual(convertToRoman(501), 'DI'); ``` -`convertToRoman(649)` should return "DCXLIX" +`convertToRoman(649)` should return the string `DCXLIX` ```js assert.deepEqual(convertToRoman(649), 'DCXLIX'); ``` -`convertToRoman(798)` should return "DCCXCVIII" +`convertToRoman(798)` should return the string `DCCXCVIII` ```js assert.deepEqual(convertToRoman(798), 'DCCXCVIII'); ``` -`convertToRoman(891)` should return "DCCCXCI" +`convertToRoman(891)` should return the string `DCCCXCI` ```js assert.deepEqual(convertToRoman(891), 'DCCCXCI'); ``` -`convertToRoman(1000)` should return "M" +`convertToRoman(1000)` should return the string `M` ```js assert.deepEqual(convertToRoman(1000), 'M'); ``` -`convertToRoman(1004)` should return "MIV" +`convertToRoman(1004)` should return the string `MIV` ```js assert.deepEqual(convertToRoman(1004), 'MIV'); ``` -`convertToRoman(1006)` should return "MVI" +`convertToRoman(1006)` should return the string `MVI` ```js assert.deepEqual(convertToRoman(1006), 'MVI'); ``` -`convertToRoman(1023)` should return "MXXIII" +`convertToRoman(1023)` should return the string `MXXIII` ```js assert.deepEqual(convertToRoman(1023), 'MXXIII'); ``` -`convertToRoman(2014)` should return "MMXIV" +`convertToRoman(2014)` should return the string `MMXIV` ```js assert.deepEqual(convertToRoman(2014), 'MMXIV'); ``` -`convertToRoman(3999)` should return "MMMCMXCIX" +`convertToRoman(3999)` should return the string `MMMCMXCIX` ```js assert.deepEqual(convertToRoman(3999), 'MMMCMXCIX'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/telephone-number-validator.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/telephone-number-validator.md index 67d1515d0f..035f3c80ee 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/telephone-number-validator.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/telephone-number-validator.md @@ -24,157 +24,157 @@ For this challenge you will be presented with a string such as `800-692-7753` or assert(typeof telephoneCheck('555-555-5555') === 'boolean'); ``` -`telephoneCheck("1 555-555-5555")` should return true. +`telephoneCheck("1 555-555-5555")` should return `true`. ```js assert(telephoneCheck('1 555-555-5555') === true); ``` -`telephoneCheck("1 (555) 555-5555")` should return true. +`telephoneCheck("1 (555) 555-5555")` should return `true`. ```js assert(telephoneCheck('1 (555) 555-5555') === true); ``` -`telephoneCheck("5555555555")` should return true. +`telephoneCheck("5555555555")` should return `true`. ```js assert(telephoneCheck('5555555555') === true); ``` -`telephoneCheck("555-555-5555")` should return true. +`telephoneCheck("555-555-5555")` should return `true`. ```js assert(telephoneCheck('555-555-5555') === true); ``` -`telephoneCheck("(555)555-5555")` should return true. +`telephoneCheck("(555)555-5555")` should return `true`. ```js assert(telephoneCheck('(555)555-5555') === true); ``` -`telephoneCheck("1(555)555-5555")` should return true. +`telephoneCheck("1(555)555-5555")` should return `true`. ```js assert(telephoneCheck('1(555)555-5555') === true); ``` -`telephoneCheck("555-5555")` should return false. +`telephoneCheck("555-5555")` should return `false`. ```js assert(telephoneCheck('555-5555') === false); ``` -`telephoneCheck("5555555")` should return false. +`telephoneCheck("5555555")` should return `false`. ```js assert(telephoneCheck('5555555') === false); ``` -`telephoneCheck("1 555)555-5555")` should return false. +`telephoneCheck("1 555)555-5555")` should return `false`. ```js assert(telephoneCheck('1 555)555-5555') === false); ``` -`telephoneCheck("1 555 555 5555")` should return true. +`telephoneCheck("1 555 555 5555")` should return `true`. ```js assert(telephoneCheck('1 555 555 5555') === true); ``` -`telephoneCheck("1 456 789 4444")` should return true. +`telephoneCheck("1 456 789 4444")` should return `true`. ```js assert(telephoneCheck('1 456 789 4444') === true); ``` -`telephoneCheck("123**&!!asdf#")` should return false. +`telephoneCheck("123**&!!asdf#")` should return `false`. ```js assert(telephoneCheck('123**&!!asdf#') === false); ``` -`telephoneCheck("55555555")` should return false. +`telephoneCheck("55555555")` should return `false`. ```js assert(telephoneCheck('55555555') === false); ``` -`telephoneCheck("(6054756961)")` should return false +`telephoneCheck("(6054756961)")` should return `false`. ```js assert(telephoneCheck('(6054756961)') === false); ``` -`telephoneCheck("2 (757) 622-7382")` should return false. +`telephoneCheck("2 (757) 622-7382")` should return `false`. ```js assert(telephoneCheck('2 (757) 622-7382') === false); ``` -`telephoneCheck("0 (757) 622-7382")` should return false. +`telephoneCheck("0 (757) 622-7382")` should return `false`. ```js assert(telephoneCheck('0 (757) 622-7382') === false); ``` -`telephoneCheck("-1 (757) 622-7382")` should return false +`telephoneCheck("-1 (757) 622-7382")` should return `false`. ```js assert(telephoneCheck('-1 (757) 622-7382') === false); ``` -`telephoneCheck("2 757 622-7382")` should return false. +`telephoneCheck("2 757 622-7382")` should return `false`. ```js assert(telephoneCheck('2 757 622-7382') === false); ``` -`telephoneCheck("10 (757) 622-7382")` should return false. +`telephoneCheck("10 (757) 622-7382")` should return `false`. ```js assert(telephoneCheck('10 (757) 622-7382') === false); ``` -`telephoneCheck("27576227382")` should return false. +`telephoneCheck("27576227382")` should return `false`. ```js assert(telephoneCheck('27576227382') === false); ``` -`telephoneCheck("(275)76227382")` should return false. +`telephoneCheck("(275)76227382")` should return `false`. ```js assert(telephoneCheck('(275)76227382') === false); ``` -`telephoneCheck("2(757)6227382")` should return false. +`telephoneCheck("2(757)6227382")` should return `false`. ```js assert(telephoneCheck('2(757)6227382') === false); ``` -`telephoneCheck("2(757)622-7382")` should return false. +`telephoneCheck("2(757)622-7382")` should return `false`. ```js assert(telephoneCheck('2(757)622-7382') === false); ``` -`telephoneCheck("555)-555-5555")` should return false. +`telephoneCheck("555)-555-5555")` should return `false`. ```js assert(telephoneCheck('555)-555-5555') === false); ``` -`telephoneCheck("(555-555-5555")` should return false. +`telephoneCheck("(555-555-5555")` should return `false`. ```js assert(telephoneCheck('(555-555-5555') === false); ``` -`telephoneCheck("(555)5(55?)-5555")` should return false. +`telephoneCheck("(555)5(55?)-5555")` should return `false`. ```js assert(telephoneCheck('(555)5(55?)-5555') === false); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/add-methods-after-inheritance.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/add-methods-after-inheritance.md index 4475a902b1..0d5df49cc5 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/add-methods-after-inheritance.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/add-methods-after-inheritance.md @@ -34,13 +34,15 @@ Now instances of `Bird` will have both `eat()` and `fly()` methods: ```js let duck = new Bird(); -duck.eat(); // prints "nom nom nom" -duck.fly(); // prints "I'm flying!" +duck.eat(); +duck.fly(); ``` +`duck.eat()` would display the string `nom nom nom` in the console, and `duck.fly()` would display the string `I'm flying!`. + # --instructions-- -Add all necessary code so the `Dog` object inherits from `Animal` and the `Dog's` `prototype` constructor is set to Dog. Then add a `bark()` method to the `Dog` object so that `beagle` can both `eat()` and `bark()`. The `bark()` method should print "Woof!" to the console. +Add all necessary code so the `Dog` object inherits from `Animal` and the `Dog`'s `prototype` constructor is set to `Dog`. Then add a `bark()` method to the `Dog` object so that `beagle` can both `eat()` and `bark()`. The `bark()` method should print `Woof!` to the console. # --hints-- @@ -74,7 +76,7 @@ The constructor for `beagle` should be set to `Dog`. assert(beagle.constructor === Dog); ``` -`beagle.eat()` should log `"nom nom nom"` +`beagle.eat()` should log the string `nom nom nom` ```js console.log = function (msg) { @@ -83,7 +85,7 @@ console.log = function (msg) { assert.throws(() => beagle.eat(), 'nom nom nom'); ``` -`beagle.bark()` should log `"Woof!"` +`beagle.bark()` should log the string `Woof!` ```js console.log = function (msg) { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/create-a-basic-javascript-object.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/create-a-basic-javascript-object.md index c71fb6cd85..c58ecb52ce 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/create-a-basic-javascript-object.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/create-a-basic-javascript-object.md @@ -23,7 +23,7 @@ let duck = { }; ``` -This `duck` object has two property/value pairs: a `name` of "Aflac" and a `numLegs` of 2. +This `duck` object has two property/value pairs: a `name` of `Aflac` and a `numLegs` of 2. # --instructions-- @@ -37,13 +37,13 @@ Create a `dog` object with `name` and `numLegs` properties, and set them to a st assert(typeof dog === 'object'); ``` -`dog` should have a `name` property set to a `string`. +`dog` should have a `name` property set to a string. ```js assert(typeof dog.name === 'string'); ``` -`dog` should have a `numLegs` property set to a `number`. +`dog` should have a `numLegs` property set to a number. ```js assert(typeof dog.numLegs === 'number'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/create-a-method-on-an-object.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/create-a-method-on-an-object.md index 0399c52c15..38b5cdb233 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/create-a-method-on-an-object.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/create-a-method-on-an-object.md @@ -19,14 +19,13 @@ let duck = { sayName: function() {return "The name of this duck is " + duck.name + ".";} }; duck.sayName(); -// Returns "The name of this duck is Aflac." ``` The example adds the `sayName` method, which is a function that returns a sentence giving the name of the `duck`. Notice that the method accessed the `name` property in the return statement using `duck.name`. The next challenge will cover another way to do this. # --instructions-- -Using the `dog` object, give it a method called `sayLegs`. The method should return the sentence "This dog has 4 legs." +Using the `dog` object, give it a method called `sayLegs`. The method should return the sentence `This dog has 4 legs.` # --hints-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/extend-constructors-to-receive-arguments.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/extend-constructors-to-receive-arguments.md index 99a679937a..5f803b1d61 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/extend-constructors-to-receive-arguments.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/extend-constructors-to-receive-arguments.md @@ -8,7 +8,7 @@ dashedName: extend-constructors-to-receive-arguments # --description-- -The `Bird` and `Dog` constructors from last challenge worked well. However, notice that all `Birds` that are created with the `Bird` constructor are automatically named Albert, are blue in color, and have two legs. What if you want birds with different values for name and color? It's possible to change the properties of each bird manually but that would be a lot of work: +The `Bird` and `Dog` constructors from the last challenge worked well. However, notice that all `Birds` that are created with the `Bird` constructor are automatically named Albert, are blue in color, and have two legs. What if you want birds with different values for name and color? It's possible to change the properties of each bird manually but that would be a lot of work: ```js let swan = new Bird(); @@ -26,12 +26,12 @@ function Bird(name, color) { } ``` -Then pass in the values as arguments to define each unique bird into the `Bird` constructor: `let cardinal = new Bird("Bruce", "red");` This gives a new instance of `Bird` with name and color properties set to Bruce and red, respectively. The `numLegs` property is still set to 2. The `cardinal` has these properties: +Then pass in the values as arguments to define each unique bird into the `Bird` constructor: `let cardinal = new Bird("Bruce", "red");` This gives a new instance of `Bird` with `name` and `color` properties set to `Bruce` and `red`, respectively. The `numLegs` property is still set to 2. The `cardinal` has these properties: ```js -cardinal.name // => Bruce -cardinal.color // => red -cardinal.numLegs // => 2 +cardinal.name +cardinal.color +cardinal.numLegs ``` The constructor is more flexible. It's now possible to define the properties for each `Bird` at the time it is created, which is one way that JavaScript constructors are so useful. They group objects together based on shared characteristics and behavior and define a blueprint that automates their creation. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/inherit-behaviors-from-a-supertype.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/inherit-behaviors-from-a-supertype.md index 357fdeab57..15c7cb78f2 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/inherit-behaviors-from-a-supertype.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/inherit-behaviors-from-a-supertype.md @@ -32,10 +32,12 @@ let animal = Object.create(Animal.prototype); `Object.create(obj)` creates a new object, and sets `obj` as the new object's `prototype`. Recall that the `prototype` is like the "recipe" for creating an object. By setting the `prototype` of `animal` to be `Animal's` `prototype`, you are effectively giving the `animal` instance the same "recipe" as any other instance of `Animal`. ```js -animal.eat(); // prints "nom nom nom" -animal instanceof Animal; // => true +animal.eat(); +animal instanceof Animal; ``` +The `instanceof` method here would return `true`. + # --instructions-- Use `Object.create` to make two instances of `Animal` named `duck` and `beagle`. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/iterate-over-all-properties.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/iterate-over-all-properties.md index bc6aa77d26..e41a97d36f 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/iterate-over-all-properties.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/iterate-over-all-properties.md @@ -34,23 +34,25 @@ for (let property in duck) { } } -console.log(ownProps); // prints ["name"] -console.log(prototypeProps); // prints ["numLegs"] +console.log(ownProps); +console.log(prototypeProps); ``` +`console.log(ownProps)` would display `["name"]` in the console, and `console.log(prototypeProps)` would display `["numLegs"]`. + # --instructions-- Add all of the `own` properties of `beagle` to the array `ownProps`. Add all of the `prototype` properties of `Dog` to the array `prototypeProps`. # --hints-- -The `ownProps` array should only contain `"name"`. +The `ownProps` array should only contain `name`. ```js assert.deepEqual(ownProps, ['name']); ``` -The `prototypeProps` array should only contain `"numLegs"`. +The `prototypeProps` array should only contain `numLegs`. ```js assert.deepEqual(prototypeProps, ['numLegs']); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/override-inherited-methods.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/override-inherited-methods.md index 24ee9ad513..c6975b6b86 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/override-inherited-methods.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/override-inherited-methods.md @@ -29,10 +29,8 @@ Animal.prototype.eat = function() { }; function Bird() { } -// Inherit all methods from Animal Bird.prototype = Object.create(Animal.prototype); -// Bird.eat() overrides Animal.eat() Bird.prototype.eat = function() { return "peck peck peck"; }; @@ -40,24 +38,24 @@ Bird.prototype.eat = function() { If you have an instance `let duck = new Bird();` and you call `duck.eat()`, this is how JavaScript looks for the method on `duck’s` `prototype` chain: -1. duck => Is eat() defined here? No. -2. Bird => Is eat() defined here? => Yes. Execute it and stop searching. -3. Animal => eat() is also defined, but JavaScript stopped searching before reaching this level. +1. `duck` => Is `eat()` defined here? No. +2. `Bird` => Is `eat()` defined here? => Yes. Execute it and stop searching. +3. `Animal` => `eat()` is also defined, but JavaScript stopped searching before reaching this level. 4. Object => JavaScript stopped searching before reaching this level. # --instructions-- -Override the `fly()` method for `Penguin` so that it returns "Alas, this is a flightless bird." +Override the `fly()` method for `Penguin` so that it returns the string `Alas, this is a flightless bird.` # --hints-- -`penguin.fly()` should return the string "Alas, this is a flightless bird." +`penguin.fly()` should return the string `Alas, this is a flightless bird.` ```js assert(penguin.fly() === 'Alas, this is a flightless bird.'); ``` -The `bird.fly()` method should return "I am flying!" +The `bird.fly()` method should return the string `I am flying!` ```js assert(new Bird().fly() === 'I am flying!'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/remember-to-set-the-constructor-property-when-changing-the-prototype.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/remember-to-set-the-constructor-property-when-changing-the-prototype.md index 76874fedec..cd44cdceb3 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/remember-to-set-the-constructor-property-when-changing-the-prototype.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/remember-to-set-the-constructor-property-when-changing-the-prototype.md @@ -11,16 +11,18 @@ dashedName: remember-to-set-the-constructor-property-when-changing-the-prototype There is one crucial side effect of manually setting the prototype to a new object. It erases the `constructor` property! This property can be used to check which constructor function created the instance, but since the property has been overwritten, it now gives false results: ```js -duck.constructor === Bird; // false -- Oops -duck.constructor === Object; // true, all objects inherit from Object.prototype -duck instanceof Bird; // true, still works +duck.constructor === Bird; +duck.constructor === Object; +duck instanceof Bird; ``` +In order, these expressions would evaluate to `false`, `true`, and `true`. + To fix this, whenever a prototype is manually set to a new object, remember to define the `constructor` property: ```js Bird.prototype = { - constructor: Bird, // define the constructor property + constructor: Bird, numLegs: 2, eat: function() { console.log("nom nom nom"); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/reset-an-inherited-constructor-property.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/reset-an-inherited-constructor-property.md index ce051f75a2..7360ef215f 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/reset-an-inherited-constructor-property.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/reset-an-inherited-constructor-property.md @@ -16,14 +16,14 @@ Here's an example: function Bird() { } Bird.prototype = Object.create(Animal.prototype); let duck = new Bird(); -duck.constructor // function Animal(){...} +duck.constructor ``` But `duck` and all instances of `Bird` should show that they were constructed by `Bird` and not `Animal`. To do so, you can manually set `Bird's` constructor property to the `Bird` object: ```js Bird.prototype.constructor = Bird; -duck.constructor // function Bird(){...} +duck.constructor ``` # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/set-the-childs-prototype-to-an-instance-of-the-parent.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/set-the-childs-prototype-to-an-instance-of-the-parent.md index 6e450e1bfe..16bdccd2e3 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/set-the-childs-prototype-to-an-instance-of-the-parent.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/set-the-childs-prototype-to-an-instance-of-the-parent.md @@ -20,7 +20,7 @@ Remember that the `prototype` is like the "recipe" for creating an object. In a ```js let duck = new Bird("Donald"); -duck.eat(); // prints "nom nom nom" +duck.eat(); ``` `duck` inherits all of `Animal`'s properties, including the `eat` method. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/understand-own-properties.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/understand-own-properties.md index f4f369581c..ea9ea2eb7a 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/understand-own-properties.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/understand-own-properties.md @@ -31,16 +31,18 @@ for (let property in duck) { } } -console.log(ownProps); // prints [ "name", "numLegs" ] +console.log(ownProps); ``` +The console would display the value `["name", "numLegs"]`. + # --instructions-- Add the `own` properties of `canary` to the array `ownProps`. # --hints-- -`ownProps` should include the values `"numLegs"` and `"name"`. +`ownProps` should include the values `numLegs` and `name`. ```js assert(ownProps.indexOf('name') !== -1 && ownProps.indexOf('numLegs') !== -1); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/understand-the-constructor-property.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/understand-the-constructor-property.md index 6d1fd731db..17b2bf8359 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/understand-the-constructor-property.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/understand-the-constructor-property.md @@ -14,10 +14,12 @@ There is a special `constructor` property located on the object instances `duck` let duck = new Bird(); let beagle = new Dog(); -console.log(duck.constructor === Bird); //prints true -console.log(beagle.constructor === Dog); //prints true +console.log(duck.constructor === Bird); +console.log(beagle.constructor === Dog); ``` +Both of these `console.log` calls would display `true` in the console. + Note that the `constructor` property is a reference to the constructor function that created the instance. The advantage of the `constructor` property is that it's possible to check for this property to find out what kind of object it is. Here's an example of how this could be used: ```js @@ -30,8 +32,7 @@ function joinBirdFraternity(candidate) { } ``` -**Note** -Since the `constructor` property can be overwritten (which will be covered in the next two challenges) it’s generally better to use the `instanceof` method to check the type of an object. +**Note:** Since the `constructor` property can be overwritten (which will be covered in the next two challenges) it’s generally better to use the `instanceof` method to check the type of an object. # --instructions-- @@ -45,7 +46,7 @@ Write a `joinDogFraternity` function that takes a `candidate` parameter and, usi assert(typeof joinDogFraternity === 'function'); ``` -`joinDogFraternity` should return true if`candidate` is an instance of `Dog`. +`joinDogFraternity` should return `true` if `candidate` is an instance of `Dog`. ```js assert(joinDogFraternity(new Dog('')) === true); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/understand-the-immediately-invoked-function-expression-iife.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/understand-the-immediately-invoked-function-expression-iife.md index cc33fc1883..67ebe4d0e7 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/understand-the-immediately-invoked-function-expression-iife.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/understand-the-immediately-invoked-function-expression-iife.md @@ -13,10 +13,11 @@ A common pattern in JavaScript is to execute a function as soon as it is declare ```js (function () { console.log("Chirp, chirp!"); -})(); // this is an anonymous function expression that executes right away -// Outputs "Chirp, chirp!" immediately +})(); ``` +This is an anonymous function expression that executes right away, and outputs `Chirp, chirp!` immediately. + Note that the function has no name and is not stored in a variable. The two parentheses () at the end of the function expression cause it to be immediately executed or invoked. This pattern is known as an immediately invoked function expression or IIFE. # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/understand-the-prototype-chain.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/understand-the-prototype-chain.md index 7632ddb4b3..1ee203a745 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/understand-the-prototype-chain.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/understand-the-prototype-chain.md @@ -15,20 +15,20 @@ function Bird(name) { this.name = name; } -typeof Bird.prototype; // yields 'object' +typeof Bird.prototype; ``` Because a `prototype` is an object, a `prototype` can have its own `prototype`! In this case, the `prototype` of `Bird.prototype` is `Object.prototype`: ```js -Object.prototype.isPrototypeOf(Bird.prototype); // returns true +Object.prototype.isPrototypeOf(Bird.prototype); ``` How is this useful? You may recall the `hasOwnProperty` method from a previous challenge: ```js let duck = new Bird("Donald"); -duck.hasOwnProperty("name"); // yields true +duck.hasOwnProperty("name"); ``` The `hasOwnProperty` method is defined in `Object.prototype`, which can be accessed by `Bird.prototype`, which can then be accessed by `duck`. This is an example of the `prototype` chain. In this `prototype` chain, `Bird` is the `supertype` for `duck`, while `duck` is the `subtype`. `Object` is a `supertype` for both `Bird` and `duck`. `Object` is a `supertype` for all objects in JavaScript. Therefore, any object can use the `hasOwnProperty` method. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/understand-where-an-objects-prototype-comes-from.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/understand-where-an-objects-prototype-comes-from.md index 5644bfa873..ce7ed680ff 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/understand-where-an-objects-prototype-comes-from.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/understand-where-an-objects-prototype-comes-from.md @@ -22,9 +22,10 @@ let duck = new Bird("Donald"); ```js Bird.prototype.isPrototypeOf(duck); -// returns true ``` +This would return `true`. + # --instructions-- Use `isPrototypeOf` to check the `prototype` of `beagle`. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/use-a-constructor-to-create-objects.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/use-a-constructor-to-create-objects.md index d26baffb1a..122fcb9a59 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/use-a-constructor-to-create-objects.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/use-a-constructor-to-create-objects.md @@ -15,25 +15,26 @@ function Bird() { this.name = "Albert"; this.color = "blue"; this.numLegs = 2; - // "this" inside the constructor always refers to the object being created } let blueBird = new Bird(); ``` +**NOTE:** `this` inside the constructor always refers to the object being created. + Notice that the `new` operator is used when calling a constructor. This tells JavaScript to create a new instance of `Bird` called `blueBird`. Without the `new` operator, `this` inside the constructor would not point to the newly created object, giving unexpected results. Now `blueBird` has all the properties defined inside the `Bird` constructor: ```js -blueBird.name; // => Albert -blueBird.color; // => blue -blueBird.numLegs; // => 2 +blueBird.name; +blueBird.color; +blueBird.numLegs; ``` Just like any other object, its properties can be accessed and modified: ```js blueBird.name = 'Elvira'; -blueBird.name; // => Elvira +blueBird.name; ``` # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/use-a-mixin-to-add-common-behavior-between-unrelated-objects.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/use-a-mixin-to-add-common-behavior-between-unrelated-objects.md index 5664c1e414..d4d627fbc8 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/use-a-mixin-to-add-common-behavior-between-unrelated-objects.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/use-a-mixin-to-add-common-behavior-between-unrelated-objects.md @@ -40,10 +40,12 @@ flyMixin(plane); Here `bird` and `plane` are passed into `flyMixin`, which then assigns the `fly` function to each object. Now `bird` and `plane` can both fly: ```js -bird.fly(); // prints "Flying, wooosh!" -plane.fly(); // prints "Flying, wooosh!" +bird.fly(); +plane.fly(); ``` +The console would display the string `Flying, wooosh!` twice, once for each `.fly()` call. + Note how the mixin allows for the same `fly` method to be reused by unrelated objects `bird` and `plane`. # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/use-an-iife-to-create-a-module.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/use-an-iife-to-create-a-module.md index 6f5a69f157..ba842fa313 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/use-an-iife-to-create-a-module.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/use-an-iife-to-create-a-module.md @@ -39,7 +39,7 @@ let motionModule = (function () { }; } } -})(); // The two parentheses cause the function to be immediately invoked +})(); ``` Note that you have an immediately invoked function expression (IIFE) that returns an object `motionModule`. This returned object contains all of the mixin behaviors as properties of the object. The advantage of the module pattern is that all of the motion behaviors can be packaged into a single object that can then be used by other parts of your code. Here is an example using it: diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/use-closure-to-protect-properties-within-an-object-from-being-modified-externally.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/use-closure-to-protect-properties-within-an-object-from-being-modified-externally.md index 66a8df7f12..db936ea17d 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/use-closure-to-protect-properties-within-an-object-from-being-modified-externally.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/use-closure-to-protect-properties-within-an-object-from-being-modified-externally.md @@ -23,15 +23,14 @@ The simplest way to make this public property private is by creating a variable ```js function Bird() { - let hatchedEgg = 10; // private variable + let hatchedEgg = 10; - /* publicly available method that a bird object can use */ this.getHatchedEggCount = function() { return hatchedEgg; }; } let ducky = new Bird(); -ducky.getHatchedEggCount(); // returns 10 +ducky.getHatchedEggCount(); ``` Here `getHatchedEggCount` is a privileged method, because it has access to the private variable `hatchedEgg`. This is possible because `hatchedEgg` is declared in the same context as `getHatchedEggCount`. In JavaScript, a function always has access to the context in which it was created. This is called `closure`. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/use-dot-notation-to-access-the-properties-of-an-object.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/use-dot-notation-to-access-the-properties-of-an-object.md index b4e34f42f9..c2a6b1700b 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/use-dot-notation-to-access-the-properties-of-an-object.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/use-dot-notation-to-access-the-properties-of-an-object.md @@ -16,10 +16,9 @@ let duck = { numLegs: 2 }; console.log(duck.name); -// This prints "Aflac" to the console ``` -Dot notation is used on the object name, `duck`, followed by the name of the property, `name`, to access the value of "Aflac". +Dot notation is used on the object name, `duck`, followed by the name of the property, `name`, to access the value of `Aflac`. # --instructions-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/use-prototype-properties-to-reduce-duplicate-code.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/use-prototype-properties-to-reduce-duplicate-code.md index 2f0875f8c3..db31b19898 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/use-prototype-properties-to-reduce-duplicate-code.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/use-prototype-properties-to-reduce-duplicate-code.md @@ -21,8 +21,8 @@ Bird.prototype.numLegs = 2; Now all instances of `Bird` have the `numLegs` property. ```js -console.log(duck.numLegs); // prints 2 -console.log(canary.numLegs); // prints 2 +console.log(duck.numLegs); +console.log(canary.numLegs); ``` Since all instances automatically have the properties on the `prototype`, think of a `prototype` as a "recipe" for creating objects. Note that the `prototype` for `duck` and `canary` is part of the `Bird` constructor as `Bird.prototype`. Nearly every object in JavaScript has a `prototype` property which is part of the constructor function that created it. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/verify-an-objects-constructor-with-instanceof.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/verify-an-objects-constructor-with-instanceof.md index 5c4258a1b4..232e29ed51 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/verify-an-objects-constructor-with-instanceof.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/verify-an-objects-constructor-with-instanceof.md @@ -19,9 +19,11 @@ let Bird = function(name, color) { let crow = new Bird("Alexis", "black"); -crow instanceof Bird; // => true +crow instanceof Bird; ``` +This `instanceof` method would return `true`. + If an object is created without using a constructor, `instanceof` will verify that it is not an instance of that constructor: ```js @@ -31,9 +33,11 @@ let canary = { numLegs: 2 }; -canary instanceof Bird; // => false +canary instanceof Bird; ``` +This `instanceof` method would return `false`. + # --instructions-- Create a new instance of the `House` constructor, calling it `myHouse` and passing a number of bedrooms. Then, use `instanceof` to verify that it is an instance of `House`. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/check-for-all-or-none.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/check-for-all-or-none.md index 2b8ee673e9..8bed443ac0 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/check-for-all-or-none.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/check-for-all-or-none.md @@ -18,13 +18,15 @@ For example, there are slight differences in American and British English and yo let american = "color"; let british = "colour"; let rainbowRegex= /colou?r/; -rainbowRegex.test(american); // Returns true -rainbowRegex.test(british); // Returns true +rainbowRegex.test(american); +rainbowRegex.test(british); ``` +Both uses of the `test` method would return `true`. + # --instructions-- -Change the regex `favRegex` to match both the American English (favorite) and the British English (favourite) version of the word. +Change the regex `favRegex` to match both the American English (`favorite`) and the British English (`favourite`) version of the word. # --hints-- @@ -35,21 +37,21 @@ favRegex.lastIndex = 0; assert(favRegex.source.match(/\?/).length > 0); ``` -Your regex should match `"favorite"` +Your regex should match the string `favorite` ```js favRegex.lastIndex = 0; assert(favRegex.test('favorite')); ``` -Your regex should match `"favourite"` +Your regex should match the string `favourite` ```js favRegex.lastIndex = 0; assert(favRegex.test('favourite')); ``` -Your regex should not match `"fav"` +Your regex should not match the string `fav` ```js favRegex.lastIndex = 0; diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/check-for-mixed-grouping-of-characters.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/check-for-mixed-grouping-of-characters.md index 1b47e0c90e..6f388d1462 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/check-for-mixed-grouping-of-characters.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/check-for-mixed-grouping-of-characters.md @@ -18,9 +18,10 @@ Then check whether the desired string groups are in the test string by using the let testStr = "Pumpkin"; let testRegex = /P(engu|umpk)in/; testRegex.test(testStr); -// Returns true ``` +The `test` method here would return `true`. + # --instructions-- Fix the regex so that it checks for the names of `Franklin Roosevelt` or `Eleanor Roosevelt` in a case sensitive manner and it should make concessions for middle names. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/extract-matches.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/extract-matches.md index 293eb6da97..887f6e3629 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/extract-matches.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/extract-matches.md @@ -16,13 +16,13 @@ Here's an example: ```js "Hello, World!".match(/Hello/); -// Returns ["Hello"] let ourStr = "Regular expressions"; let ourRegex = /expressions/; ourStr.match(ourRegex); -// Returns ["expressions"] ``` +Here the first `match` would return `["Hello"]` and the second would return `["expressions"]`. + Note that the `.match` syntax is the "opposite" of the `.test` method you have been using thus far: ```js @@ -32,17 +32,17 @@ Note that the `.match` syntax is the "opposite" of the `.test` method you have b # --instructions-- -Apply the `.match()` method to extract the word `coding`. +Apply the `.match()` method to extract the string `coding`. # --hints-- -The `result` should have the word `coding` +The `result` should have the string `coding` ```js assert(result.join() === 'coding'); ``` -Your regex `codingRegex` should search for `coding` +Your regex `codingRegex` should search for the string `coding` ```js assert(codingRegex.source === 'coding'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/find-characters-with-lazy-matching.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/find-characters-with-lazy-matching.md index df05cd9717..a4dfbbf1d1 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/find-characters-with-lazy-matching.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/find-characters-with-lazy-matching.md @@ -16,8 +16,7 @@ Regular expressions are by default greedy, so the match would return `["titani"] However, you can use the `?` character to change it to lazy matching. `"titanic"` matched against the adjusted regex of `/t[a-z]*?i/` returns `["ti"]`. -**Note** -Parsing HTML with regular expressions should be avoided, but pattern matching an HTML string with regular expressions is completely fine. +**Note:** Parsing HTML with regular expressions should be avoided, but pattern matching an HTML string with regular expressions is completely fine. # --instructions-- @@ -37,7 +36,7 @@ assert(result[0] == '

'); assert(/\?/g.test(myRegex)); ``` -`myRegex` should not include the string 'h1' +`myRegex` should not include the string `h1` ```js assert(!myRegex.source.match('h1')); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/find-more-than-the-first-match.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/find-more-than-the-first-match.md index cb76eff45d..e9e55893d6 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/find-more-than-the-first-match.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/find-more-than-the-first-match.md @@ -14,20 +14,22 @@ So far, you have only been able to extract or search a pattern once. let testStr = "Repeat, Repeat, Repeat"; let ourRegex = /Repeat/; testStr.match(ourRegex); -// Returns ["Repeat"] ``` +Here `match` would return `["Repeat"]`. + To search or extract a pattern more than once, you can use the `g` flag. ```js let repeatRegex = /Repeat/g; testStr.match(repeatRegex); -// Returns ["Repeat", "Repeat", "Repeat"] ``` +And here `match` returns the value `["Repeat", "Repeat", "Repeat"]` + # --instructions-- -Using the regex `starRegex`, find and extract both `"Twinkle"` words from the string `twinkleStar`. +Using the regex `starRegex`, find and extract both `Twinkle` words from the string `twinkleStar`. **Note** You can have multiple flags on your regex like `/search/gi` @@ -46,7 +48,7 @@ Your regex `starRegex` should use the case insensitive flag `i` assert(starRegex.flags.match(/i/).length == 1); ``` -Your match should match both occurrences of the word `"Twinkle"` +Your match should match both occurrences of the word `Twinkle` ```js assert( diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/find-one-or-more-criminals-in-a-hunt.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/find-one-or-more-criminals-in-a-hunt.md index 79d25fe5c5..553c581b89 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/find-one-or-more-criminals-in-a-hunt.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/find-one-or-more-criminals-in-a-hunt.md @@ -36,13 +36,13 @@ Write a greedy regex that finds one or more criminals within a group of other pe # --hints-- -Your regex should match one criminal (`C`) in `"C"` +Your regex should match one criminal (`C`) in the string `C` ```js assert('C'.match(reCriminals) && 'C'.match(reCriminals)[0] == 'C'); ``` -Your regex should match two criminals (`CC`) in `"CC"` +Your regex should match two criminals (`CC`) in the string `CC` ```js assert('CC'.match(reCriminals) && 'CC'.match(reCriminals)[0] == 'CC'); @@ -57,7 +57,7 @@ assert( ); ``` -Your regex should match five criminals (`CCCCC`) in `"P6P2P7P4P5CCCCCP3P1"` +Your regex should match five criminals (`CCCCC`) in the string `P6P2P7P4P5CCCCCP3P1` ```js assert( @@ -66,19 +66,19 @@ assert( ); ``` -Your regex should not match any criminals in `""` +Your regex should not match any criminals in the empty string `""` ```js assert(!reCriminals.test('')); ``` -Your regex should not match any criminals in `"P1P2P3"` +Your regex should not match any criminals in the string `P1P2P3` ```js assert(!reCriminals.test('P1P2P3')); ``` -Your regex should match fifty criminals (`CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC`) in `"P2P1P5P4CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCP3"`. +Your regex should match fifty criminals (`CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC`) in the string `P2P1P5P4CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCP3`. ```js assert( diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/ignore-case-while-matching.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/ignore-case-while-matching.md index 8ea7f4218e..84ad9636ad 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/ignore-case-while-matching.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/ignore-case-while-matching.md @@ -10,71 +10,71 @@ dashedName: ignore-case-while-matching Up until now, you've looked at regexes to do literal matches of strings. But sometimes, you might want to also match case differences. -Case (or sometimes letter case) is the difference between uppercase letters and lowercase letters. Examples of uppercase are `"A"`, `"B"`, and `"C"`. Examples of lowercase are `"a"`, `"b"`, and `"c"`. +Case (or sometimes letter case) is the difference between uppercase letters and lowercase letters. Examples of uppercase are `A`, `B`, and `C`. Examples of lowercase are `a`, `b`, and `c`. -You can match both cases using what is called a flag. There are other flags but here you'll focus on the flag that ignores case - the `i` flag. You can use it by appending it to the regex. An example of using this flag is `/ignorecase/i`. This regex can match the strings `"ignorecase"`, `"igNoreCase"`, and `"IgnoreCase"`. +You can match both cases using what is called a flag. There are other flags but here you'll focus on the flag that ignores case - the `i` flag. You can use it by appending it to the regex. An example of using this flag is `/ignorecase/i`. This regex can match the strings `ignorecase`, `igNoreCase`, and `IgnoreCase`. # --instructions-- -Write a regex `fccRegex` to match `"freeCodeCamp"`, no matter its case. Your regex should not match any abbreviations or variations with spaces. +Write a regex `fccRegex` to match `freeCodeCamp`, no matter its case. Your regex should not match any abbreviations or variations with spaces. # --hints-- -Your regex should match `freeCodeCamp` +Your regex should match the string `freeCodeCamp` ```js assert(fccRegex.test('freeCodeCamp')); ``` -Your regex should match `FreeCodeCamp` +Your regex should match the string `FreeCodeCamp` ```js assert(fccRegex.test('FreeCodeCamp')); ``` -Your regex should match `FreecodeCamp` +Your regex should match the string `FreecodeCamp` ```js assert(fccRegex.test('FreecodeCamp')); ``` -Your regex should match `FreeCodecamp` +Your regex should match the string `FreeCodecamp` ```js assert(fccRegex.test('FreeCodecamp')); ``` -Your regex should not match `Free Code Camp` +Your regex should not match the string `Free Code Camp` ```js assert(!fccRegex.test('Free Code Camp')); ``` -Your regex should match `FreeCOdeCamp` +Your regex should match the string `FreeCOdeCamp` ```js assert(fccRegex.test('FreeCOdeCamp')); ``` -Your regex should not match `FCC` +Your regex should not match the string `FCC` ```js assert(!fccRegex.test('FCC')); ``` -Your regex should match `FrEeCoDeCamp` +Your regex should match the string `FrEeCoDeCamp` ```js assert(fccRegex.test('FrEeCoDeCamp')); ``` -Your regex should match `FrEeCodECamp` +Your regex should match the string `FrEeCodECamp` ```js assert(fccRegex.test('FrEeCodECamp')); ``` -Your regex should match `FReeCodeCAmp` +Your regex should match the string `FReeCodeCAmp` ```js assert(fccRegex.test('FReeCodeCAmp')); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-a-literal-string-with-different-possibilities.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-a-literal-string-with-different-possibilities.md index c98f45b851..5a970259d2 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-a-literal-string-with-different-possibilities.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-a-literal-string-with-different-possibilities.md @@ -8,57 +8,57 @@ dashedName: match-a-literal-string-with-different-possibilities # --description-- -Using regexes like `/coding/`, you can look for the pattern `"coding"` in another string. +Using regexes like `/coding/`, you can look for the pattern `coding` in another string. This is powerful to search single strings, but it's limited to only one pattern. You can search for multiple patterns using the `alternation` or `OR` operator: `|`. -This operator matches patterns either before or after it. For example, if you wanted to match `"yes"` or `"no"`, the regex you want is `/yes|no/`. +This operator matches patterns either before or after it. For example, if you wanted to match the strings `yes` or `no`, the regex you want is `/yes|no/`. You can also search for more than just two patterns. You can do this by adding more patterns with more `OR` operators separating them, like `/yes|no|maybe/`. # --instructions-- -Complete the regex `petRegex` to match the pets `"dog"`, `"cat"`, `"bird"`, or `"fish"`. +Complete the regex `petRegex` to match the pets `dog`, `cat`, `bird`, or `fish`. # --hints-- -Your regex `petRegex` should return `true` for the string `"John has a pet dog."` +Your regex `petRegex` should return `true` for the string `John has a pet dog.` ```js assert(petRegex.test('John has a pet dog.')); ``` -Your regex `petRegex` should return `false` for the string `"Emma has a pet rock."` +Your regex `petRegex` should return `false` for the string `Emma has a pet rock.` ```js assert(!petRegex.test('Emma has a pet rock.')); ``` -Your regex `petRegex` should return `true` for the string `"Emma has a pet bird."` +Your regex `petRegex` should return `true` for the string `Emma has a pet bird.` ```js assert(petRegex.test('Emma has a pet bird.')); ``` -Your regex `petRegex` should return `true` for the string `"Liz has a pet cat."` +Your regex `petRegex` should return `true` for the string `Liz has a pet cat.` ```js assert(petRegex.test('Liz has a pet cat.')); ``` -Your regex `petRegex` should return `false` for the string `"Kara has a pet dolphin."` +Your regex `petRegex` should return `false` for the string `Kara has a pet dolphin.` ```js assert(!petRegex.test('Kara has a pet dolphin.')); ``` -Your regex `petRegex` should return `true` for the string `"Alice has a pet fish."` +Your regex `petRegex` should return `true` for the string `Alice has a pet fish.` ```js assert(petRegex.test('Alice has a pet fish.')); ``` -Your regex `petRegex` should return `false` for the string `"Jimmy has a pet computer."` +Your regex `petRegex` should return `false` for the string `Jimmy has a pet computer.` ```js assert(!petRegex.test('Jimmy has a pet computer.')); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-all-letters-and-numbers.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-all-letters-and-numbers.md index 70cb70395a..716adc5104 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-all-letters-and-numbers.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-all-letters-and-numbers.md @@ -17,12 +17,14 @@ let longHand = /[A-Za-z0-9_]+/; let shortHand = /\w+/; let numbers = "42"; let varNames = "important_var"; -longHand.test(numbers); // Returns true -shortHand.test(numbers); // Returns true -longHand.test(varNames); // Returns true -shortHand.test(varNames); // Returns true +longHand.test(numbers); +shortHand.test(numbers); +longHand.test(varNames); +shortHand.test(varNames); ``` +All four of these `test` calls would return `true`. + These shortcut character classes are also known as shorthand character classes. # --instructions-- @@ -43,7 +45,7 @@ Your regex should use the shorthand character `\w` to match all characters which assert(/\\w/.test(alphabetRegexV2.source)); ``` -Your regex should find 31 alphanumeric characters in `"The five boxing wizards jump quickly."` +Your regex should find 31 alphanumeric characters in the string `The five boxing wizards jump quickly.` ```js assert( @@ -51,7 +53,7 @@ assert( ); ``` -Your regex should find 32 alphanumeric characters in `"Pack my box with five dozen liquor jugs."` +Your regex should find 32 alphanumeric characters in the string `Pack my box with five dozen liquor jugs.` ```js assert( @@ -60,7 +62,7 @@ assert( ); ``` -Your regex should find 30 alphanumeric characters in `"How vexingly quick daft zebras jump!"` +Your regex should find 30 alphanumeric characters in the string `How vexingly quick daft zebras jump!` ```js assert( @@ -68,7 +70,7 @@ assert( ); ``` -Your regex should find 36 alphanumeric characters in `"123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ."` +Your regex should find 36 alphanumeric characters in the string `123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.` ```js assert( diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-all-non-numbers.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-all-non-numbers.md index 2290a226d9..3eed2453f2 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-all-non-numbers.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-all-non-numbers.md @@ -30,37 +30,37 @@ Your regex should use the global flag. assert(noNumRegex.global); ``` -Your regex should find no non-digits in `"9"`. +Your regex should find no non-digits in the string `9`. ```js assert('9'.match(noNumRegex) == null); ``` -Your regex should find 6 non-digits in `"Catch 22"`. +Your regex should find 6 non-digits in the string `Catch 22`. ```js assert('Catch 22'.match(noNumRegex).length == 6); ``` -Your regex should find 11 non-digits in `"101 Dalmatians"`. +Your regex should find 11 non-digits in the string `101 Dalmatians`. ```js assert('101 Dalmatians'.match(noNumRegex).length == 11); ``` -Your regex should find 15 non-digits in `"One, Two, Three"`. +Your regex should find 15 non-digits in the string `One, Two, Three`. ```js assert('One, Two, Three'.match(noNumRegex).length == 15); ``` -Your regex should find 12 non-digits in `"21 Jump Street"`. +Your regex should find 12 non-digits in the string `21 Jump Street`. ```js assert('21 Jump Street'.match(noNumRegex).length == 12); ``` -Your regex should find 17 non-digits in `"2001: A Space Odyssey"`. +Your regex should find 17 non-digits in the string `2001: A Space Odyssey`. ```js assert('2001: A Space Odyssey'.match(noNumRegex).length == 17); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-all-numbers.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-all-numbers.md index 86c84f015a..f4a6505e86 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-all-numbers.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-all-numbers.md @@ -30,37 +30,37 @@ Your regex should use the global flag. assert(numRegex.global); ``` -Your regex should find 1 digit in `"9"`. +Your regex should find 1 digit in the string `9`. ```js assert('9'.match(numRegex).length == 1); ``` -Your regex should find 2 digits in `"Catch 22"`. +Your regex should find 2 digits in the string `Catch 22`. ```js assert('Catch 22'.match(numRegex).length == 2); ``` -Your regex should find 3 digits in `"101 Dalmatians"`. +Your regex should find 3 digits in the string `101 Dalmatians`. ```js assert('101 Dalmatians'.match(numRegex).length == 3); ``` -Your regex should find no digits in `"One, Two, Three"`. +Your regex should find no digits in the string `One, Two, Three`. ```js assert('One, Two, Three'.match(numRegex) == null); ``` -Your regex should find 2 digits in `"21 Jump Street"`. +Your regex should find 2 digits in the string `21 Jump Street`. ```js assert('21 Jump Street'.match(numRegex).length == 2); ``` -Your regex should find 4 digits in `"2001: A Space Odyssey"`. +Your regex should find 4 digits in the string `2001: A Space Odyssey`. ```js assert('2001: A Space Odyssey'.match(numRegex).length == 4); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-anything-with-wildcard-period.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-anything-with-wildcard-period.md index 64c17e62a6..3306cfb8c7 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-anything-with-wildcard-period.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-anything-with-wildcard-period.md @@ -10,19 +10,21 @@ dashedName: match-anything-with-wildcard-period Sometimes you won't (or don't need to) know the exact characters in your patterns. Thinking of all words that match, say, a misspelling would take a long time. Luckily, you can save time using the wildcard character: `.` -The wildcard character `.` will match any one character. The wildcard is also called `dot` and `period`. You can use the wildcard character just like any other character in the regex. For example, if you wanted to match `"hug"`, `"huh"`, `"hut"`, and `"hum"`, you can use the regex `/hu./` to match all four words. +The wildcard character `.` will match any one character. The wildcard is also called `dot` and `period`. You can use the wildcard character just like any other character in the regex. For example, if you wanted to match `hug`, `huh`, `hut`, and `hum`, you can use the regex `/hu./` to match all four words. ```js let humStr = "I'll hum a song"; let hugStr = "Bear hug"; let huRegex = /hu./; -huRegex.test(humStr); // Returns true -huRegex.test(hugStr); // Returns true +huRegex.test(humStr); +huRegex.test(hugStr); ``` +Both of these `test` calls would return `true`. + # --instructions-- -Complete the regex `unRegex` so that it matches the strings `"run"`, `"sun"`, `"fun"`, `"pun"`, `"nun"`, and `"bun"`. Your regex should use the wildcard character. +Complete the regex `unRegex` so that it matches the strings `run`, `sun`, `fun`, `pun`, `nun`, and `bun`. Your regex should use the wildcard character. # --hints-- @@ -38,42 +40,42 @@ You should use the wildcard character in your regex `unRegex` assert(/\./.test(unRegex.source)); ``` -Your regex `unRegex` should match `"run"` in `"Let us go on a run."` +Your regex `unRegex` should match `run` in the string `Let us go on a run.` ```js unRegex.lastIndex = 0; assert(unRegex.test('Let us go on a run.')); ``` -Your regex `unRegex` should match `"sun"` in `"The sun is out today."` +Your regex `unRegex` should match `sun` in the string `The sun is out today.` ```js unRegex.lastIndex = 0; assert(unRegex.test('The sun is out today.')); ``` -Your regex `unRegex` should match `"fun"` in `"Coding is a lot of fun."` +Your regex `unRegex` should match `fun` in the string `Coding is a lot of fun.` ```js unRegex.lastIndex = 0; assert(unRegex.test('Coding is a lot of fun.')); ``` -Your regex `unRegex` should match `"pun"` in `"Seven days without a pun makes one weak."` +Your regex `unRegex` should match `pun` in the string `Seven days without a pun makes one weak.` ```js unRegex.lastIndex = 0; assert(unRegex.test('Seven days without a pun makes one weak.')); ``` -Your regex `unRegex` should match `"nun"` in `"One takes a vow to be a nun."` +Your regex `unRegex` should match `nun` in the string `One takes a vow to be a nun.` ```js unRegex.lastIndex = 0; assert(unRegex.test('One takes a vow to be a nun.')); ``` -Your regex `unRegex` should match `"bun"` in `"She got fired from the hot dog stand for putting her hair in a bun."` +Your regex `unRegex` should match `bun` in the string `She got fired from the hot dog stand for putting her hair in a bun.` ```js unRegex.lastIndex = 0; @@ -84,14 +86,14 @@ assert( ); ``` -Your regex `unRegex` should not match `"There is a bug in my code."` +Your regex `unRegex` should not match the string `There is a bug in my code.` ```js unRegex.lastIndex = 0; assert(!unRegex.test('There is a bug in my code.')); ``` -Your regex `unRegex` should not match `"Catch me if you can."` +Your regex `unRegex` should not match the string `Catch me if you can.` ```js unRegex.lastIndex = 0; diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-beginning-string-patterns.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-beginning-string-patterns.md index 099238eebf..6d2b1dec50 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-beginning-string-patterns.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-beginning-string-patterns.md @@ -16,19 +16,19 @@ In an earlier challenge, you used the caret character (`^`) inside a character s let firstString = "Ricky is first and can be found."; let firstRegex = /^Ricky/; firstRegex.test(firstString); -// Returns true let notFirst = "You can't find Ricky now."; firstRegex.test(notFirst); -// Returns false ``` +The first `test` call would return `true`, while the second would return `false`. + # --instructions-- -Use the caret character in a regex to find `"Cal"` only in the beginning of the string `rickyAndCal`. +Use the caret character in a regex to find `Cal` only in the beginning of the string `rickyAndCal`. # --hints-- -Your regex should search for `"Cal"` with a capital letter. +Your regex should search for the string `Cal` with a capital letter. ```js assert(calRegex.source == '^Cal'); @@ -40,13 +40,13 @@ Your regex should not use any flags. assert(calRegex.flags == ''); ``` -Your regex should match `"Cal"` at the beginning of the string. +Your regex should match the string `Cal` at the beginning of the string. ```js assert(calRegex.test('Cal and Ricky both like racing.')); ``` -Your regex should not match `"Cal"` in the middle of a string. +Your regex should not match the string `Cal` in the middle of a string. ```js assert(!calRegex.test('Ricky and Cal both like racing.')); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-characters-that-occur-one-or-more-times.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-characters-that-occur-one-or-more-times.md index cf54e942ff..c9d82ef7f7 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-characters-that-occur-one-or-more-times.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-characters-that-occur-one-or-more-times.md @@ -12,13 +12,13 @@ Sometimes, you need to match a character (or group of characters) that appears o You can use the `+` character to check if that is the case. Remember, the character or pattern has to be present consecutively. That is, the character has to repeat one after the other. -For example, `/a+/g` would find one match in `"abc"` and return `["a"]`. Because of the `+`, it would also find a single match in `"aabc"` and return `["aa"]`. +For example, `/a+/g` would find one match in `abc` and return `["a"]`. Because of the `+`, it would also find a single match in `aabc` and return `["aa"]`. -If it were instead checking the string `"abab"`, it would find two matches and return `["a", "a"]` because the `a` characters are not in a row - there is a `b` between them. Finally, since there is no `"a"` in the string `"bcd"`, it wouldn't find a match. +If it were instead checking the string `abab`, it would find two matches and return `["a", "a"]` because the `a` characters are not in a row - there is a `b` between them. Finally, since there is no `a` in the string `bcd`, it wouldn't find a match. # --instructions-- -You want to find matches when the letter `s` occurs one or more times in `"Mississippi"`. Write a regex that uses the `+` sign. +You want to find matches when the letter `s` occurs one or more times in `Mississippi`. Write a regex that uses the `+` sign. # --hints-- @@ -34,7 +34,7 @@ Your regex `myRegex` should match 2 items. assert(result.length == 2); ``` -The `result` variable should be an array with two matches of `"ss"` +The `result` variable should be an array with two matches of `ss` ```js assert(result[0] == 'ss' && result[1] == 'ss'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-characters-that-occur-zero-or-more-times.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-characters-that-occur-zero-or-more-times.md index 745202e5fe..aaa4fdba5a 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-characters-that-occur-zero-or-more-times.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-characters-that-occur-zero-or-more-times.md @@ -17,14 +17,16 @@ let soccerWord = "gooooooooal!"; let gPhrase = "gut feeling"; let oPhrase = "over the moon"; let goRegex = /go*/; -soccerWord.match(goRegex); // Returns ["goooooooo"] -gPhrase.match(goRegex); // Returns ["g"] -oPhrase.match(goRegex); // Returns null +soccerWord.match(goRegex); +gPhrase.match(goRegex); +oPhrase.match(goRegex); ``` +In order, the three `match` calls would return the values `["goooooooo"]`, `["g"]`, and `null`. + # --instructions-- -For this challenge, `chewieQuote` has been initialized as "Aaaaaaaaaaaaaaaarrrgh!" behind the scenes. Create a regex `chewieRegex` that uses the `*` character to match an uppercase `"A"` character immediately followed by zero or more lowercase `"a"` characters in `chewieQuote`. Your regex does not need flags or character classes, and it should not match any of the other quotes. +For this challenge, `chewieQuote` has been initialized as the string `Aaaaaaaaaaaaaaaarrrgh!` behind the scenes. Create a regex `chewieRegex` that uses the `*` character to match an uppercase `A` character immediately followed by zero or more lowercase `a` characters in `chewieQuote`. Your regex does not need flags or character classes, and it should not match any of the other quotes. # --hints-- @@ -34,13 +36,13 @@ Your regex `chewieRegex` should use the `*` character to match zero or more `a` assert(/\*/.test(chewieRegex.source)); ``` -Your regex should match `"A"` in `chewieQuote`. +Your regex should match the string `A` in `chewieQuote`. ```js assert(result[0][0] === 'A'); ``` -Your regex should match `"Aaaaaaaaaaaaaaaa"` in `chewieQuote`. +Your regex should match the string `Aaaaaaaaaaaaaaaa` in `chewieQuote`. ```js assert(result[0] === 'Aaaaaaaaaaaaaaaa'); @@ -52,7 +54,7 @@ Your regex `chewieRegex` should match 16 characters in `chewieQuote`. assert(result[0].length === 16); ``` -Your regex should not match any characters in "He made a fair move. Screaming about it can't help you." +Your regex should not match any characters in the string `He made a fair move. Screaming about it can't help you.` ```js assert( @@ -60,7 +62,7 @@ assert( ); ``` -Your regex should not match any characters in "Let him have it. It's not wise to upset a Wookiee." +Your regex should not match any characters in the string `Let him have it. It's not wise to upset a Wookiee.` ```js assert( diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-ending-string-patterns.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-ending-string-patterns.md index 60e1638ce7..28a0024ffc 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-ending-string-patterns.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-ending-string-patterns.md @@ -16,20 +16,19 @@ You can search the end of strings using the dollar sign character `$` at the end let theEnding = "This is a never ending story"; let storyRegex = /story$/; storyRegex.test(theEnding); -// Returns true let noEnding = "Sometimes a story will have to end"; storyRegex.test(noEnding); -// Returns false - ``` +The first `test` call would return `true`, while the second would return `false`. + # --instructions-- -Use the anchor character (`$`) to match the string `"caboose"` at the end of the string `caboose`. +Use the anchor character (`$`) to match the string `caboose` at the end of the string `caboose`. # --hints-- -You should search for `"caboose"` with the dollar sign `$` anchor in your regex. +You should search for `caboose` with the dollar sign `$` anchor in your regex. ```js assert(lastRegex.source == 'caboose$'); @@ -41,7 +40,7 @@ Your regex should not use any flags. assert(lastRegex.flags == ''); ``` -You should match `"caboose"` at the end of the string `"The last car on a train is the caboose"` +You should match `caboose` at the end of the string `The last car on a train is the caboose` ```js assert(lastRegex.test('The last car on a train is the caboose')); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-everything-but-letters-and-numbers.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-everything-but-letters-and-numbers.md index 541817a663..ac2c15b427 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-everything-but-letters-and-numbers.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-everything-but-letters-and-numbers.md @@ -16,10 +16,12 @@ You can search for the opposite of the `\w` with `\W`. Note, the opposite patter let shortHand = /\W/; let numbers = "42%"; let sentence = "Coding!"; -numbers.match(shortHand); // Returns ["%"] -sentence.match(shortHand); // Returns ["!"] +numbers.match(shortHand); +sentence.match(shortHand); ``` +The first `match` call would return the value `["%"]` and the second would return `["!"]`. + # --instructions-- Use the shorthand character class `\W` to count the number of non-alphanumeric characters in various quotes and strings. @@ -32,7 +34,7 @@ Your regex should use the global flag. assert(nonAlphabetRegex.global); ``` -Your regex should find 6 non-alphanumeric characters in `"The five boxing wizards jump quickly."`. +Your regex should find 6 non-alphanumeric characters in the string `The five boxing wizards jump quickly.`. ```js assert( @@ -46,7 +48,7 @@ Your regex should use the shorthand character to match characters which are non- assert(/\\W/.test(nonAlphabetRegex.source)); ``` -Your regex should find 8 non-alphanumeric characters in `"Pack my box with five dozen liquor jugs."` +Your regex should find 8 non-alphanumeric characters in the string `Pack my box with five dozen liquor jugs.` ```js assert( @@ -54,7 +56,7 @@ assert( ); ``` -Your regex should find 6 non-alphanumeric characters in `"How vexingly quick daft zebras jump!"` +Your regex should find 6 non-alphanumeric characters in the string `How vexingly quick daft zebras jump!` ```js assert( @@ -62,7 +64,7 @@ assert( ); ``` -Your regex should find 12 non-alphanumeric characters in `"123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ."` +Your regex should find 12 non-alphanumeric characters in the string `123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.` ```js assert( diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-letters-of-the-alphabet.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-letters-of-the-alphabet.md index 7b48c2b89d..7e5d5d86e4 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-letters-of-the-alphabet.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-letters-of-the-alphabet.md @@ -19,11 +19,13 @@ let catStr = "cat"; let batStr = "bat"; let matStr = "mat"; let bgRegex = /[a-e]at/; -catStr.match(bgRegex); // Returns ["cat"] -batStr.match(bgRegex); // Returns ["bat"] -matStr.match(bgRegex); // Returns null +catStr.match(bgRegex); +batStr.match(bgRegex); +matStr.match(bgRegex); ``` +In order, the three `match` calls would return the values `["cat"]`, `["bat"]`, and `null`. + # --instructions-- Match all the letters in the string `quoteSample`. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-literal-strings.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-literal-strings.md index 132c48dbe4..5cdea6123e 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-literal-strings.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-literal-strings.md @@ -8,23 +8,25 @@ dashedName: match-literal-strings # --description-- -In the last challenge, you searched for the word `"Hello"` using the regular expression `/Hello/`. That regex searched for a literal match of the string `"Hello"`. Here's another example searching for a literal match of the string `"Kevin"`: +In the last challenge, you searched for the word `Hello` using the regular expression `/Hello/`. That regex searched for a literal match of the string `Hello`. Here's another example searching for a literal match of the string `Kevin`: ```js let testStr = "Hello, my name is Kevin."; let testRegex = /Kevin/; testRegex.test(testStr); -// Returns true ``` -Any other forms of `"Kevin"` will not match. For example, the regex `/Kevin/` will not match `"kevin"` or `"KEVIN"`. +This `test` call will return `true`. + +Any other forms of `Kevin` will not match. For example, the regex `/Kevin/` will not match `kevin` or `KEVIN`. ```js let wrongRegex = /kevin/; wrongRegex.test(testStr); -// Returns false ``` +This `test` call will return `false`. + A future challenge will show how to match those other forms as well. # --instructions-- @@ -33,7 +35,7 @@ Complete the regex `waldoRegex` to find `"Waldo"` in the string `waldoIsHiding` # --hints-- -Your regex `waldoRegex` should find `"Waldo"` +Your regex `waldoRegex` should find the string `Waldo` ```js assert(waldoRegex.test(waldoIsHiding)); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-non-whitespace-characters.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-non-whitespace-characters.md index 9607d58cc9..a35a8aa487 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-non-whitespace-characters.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-non-whitespace-characters.md @@ -15,9 +15,11 @@ Search for non-whitespace using `\S`, which is an uppercase `s`. This pattern wi ```js let whiteSpace = "Whitespace. Whitespace everywhere!" let nonSpaceRegex = /\S/g; -whiteSpace.match(nonSpaceRegex).length; // Returns 32 +whiteSpace.match(nonSpaceRegex).length; ``` +The value returned by the `.length` method would be `32`. + # --instructions-- Change the regex `countNonWhiteSpace` to look for multiple non-whitespace characters in a string. @@ -36,7 +38,7 @@ Your regex should use the shorthand character `\S` to match all non-whitespace c assert(/\\S/.test(countNonWhiteSpace.source)); ``` -Your regex should find 35 non-spaces in `"Men are from Mars and women are from Venus."` +Your regex should find 35 non-spaces in the string `Men are from Mars and women are from Venus.` ```js assert( @@ -45,13 +47,13 @@ assert( ); ``` -Your regex should find 23 non-spaces in `"Space: the final frontier."` +Your regex should find 23 non-spaces in the string `Space: the final frontier.` ```js assert('Space: the final frontier.'.match(countNonWhiteSpace).length == 23); ``` -Your regex should find 21 non-spaces in `"MindYourPersonalSpace"` +Your regex should find 21 non-spaces in the string `MindYourPersonalSpace` ```js assert('MindYourPersonalSpace'.match(countNonWhiteSpace).length == 21); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-numbers-and-letters-of-the-alphabet.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-numbers-and-letters-of-the-alphabet.md index 1702acbad8..bfc04f2661 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-numbers-and-letters-of-the-alphabet.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-numbers-and-letters-of-the-alphabet.md @@ -17,7 +17,6 @@ Also, it is possible to combine a range of letters and numbers in a single chara ```js let jennyStr = "Jenny8675309"; let myRegex = /[a-z0-9]/ig; -// matches all letters and numbers in jennyStr jennyStr.match(myRegex); ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-single-character-with-multiple-possibilities.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-single-character-with-multiple-possibilities.md index 097ded3a04..ba055ac4c1 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-single-character-with-multiple-possibilities.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-single-character-with-multiple-possibilities.md @@ -12,7 +12,7 @@ You learned how to match literal patterns (`/literal/`) and wildcard character ( You can search for a literal pattern with some flexibility with character classes. Character classes allow you to define a group of characters you wish to match by placing them inside square (`[` and `]`) brackets. -For example, you want to match `"bag"`, `"big"`, and `"bug"` but not `"bog"`. You can create the regex `/b[aiu]g/` to do this. The `[aiu]` is the character class that will only match the characters `"a"`, `"i"`, or `"u"`. +For example, you want to match `bag`, `big`, and `bug` but not `bog`. You can create the regex `/b[aiu]g/` to do this. The `[aiu]` is the character class that will only match the characters `a`, `i`, or `u`. ```js let bigStr = "big"; @@ -20,18 +20,19 @@ let bagStr = "bag"; let bugStr = "bug"; let bogStr = "bog"; let bgRegex = /b[aiu]g/; -bigStr.match(bgRegex); // Returns ["big"] -bagStr.match(bgRegex); // Returns ["bag"] -bugStr.match(bgRegex); // Returns ["bug"] -bogStr.match(bgRegex); // Returns null +bigStr.match(bgRegex); +bagStr.match(bgRegex); +bugStr.match(bgRegex); +bogStr.match(bgRegex); ``` +In order, the four `match` calls would return the values `["big"]`, `["bag"]`, `["bug"]`, and `null`. + # --instructions-- Use a character class with vowels (`a`, `e`, `i`, `o`, `u`) in your regex `vowelRegex` to find all the vowels in the string `quoteSample`. -**Note** -Be sure to match both upper- and lowercase vowels. +**Note:** Be sure to match both upper- and lowercase vowels. # --hints-- diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-whitespace.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-whitespace.md index b59d501509..f055b0d4a9 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-whitespace.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/match-whitespace.md @@ -16,9 +16,9 @@ You can search for whitespace using `\s`, which is a lowercase `s`. This pattern let whiteSpace = "Whitespace. Whitespace everywhere!" let spaceRegex = /\s/g; whiteSpace.match(spaceRegex); -// Returns [" ", " "] ``` +This `match` call would return `[" ", " "]`. # --instructions-- Change the regex `countWhiteSpace` to look for multiple whitespace characters in a string. @@ -37,7 +37,7 @@ Your regex should use the shorthand character `\s` to match all whitespace chara assert(/\\s/.test(countWhiteSpace.source)); ``` -Your regex should find eight spaces in `"Men are from Mars and women are from Venus."` +Your regex should find eight spaces in the string `Men are from Mars and women are from Venus.` ```js assert( @@ -46,13 +46,13 @@ assert( ); ``` -Your regex should find three spaces in `"Space: the final frontier."` +Your regex should find three spaces in the string `Space: the final frontier.` ```js assert('Space: the final frontier.'.match(countWhiteSpace).length == 3); ``` -Your regex should find no spaces in `"MindYourPersonalSpace"` +Your regex should find no spaces in the string `MindYourPersonalSpace` ```js assert('MindYourPersonalSpace'.match(countWhiteSpace) == null); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/positive-and-negative-lookahead.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/positive-and-negative-lookahead.md index e7b4814726..0065d0cdf5 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/positive-and-negative-lookahead.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/positive-and-negative-lookahead.md @@ -23,16 +23,18 @@ let quit = "qu"; let noquit = "qt"; let quRegex= /q(?=u)/; let qRegex = /q(?!u)/; -quit.match(quRegex); // Returns ["q"] -noquit.match(qRegex); // Returns ["q"] +quit.match(quRegex); +noquit.match(qRegex); ``` +Both of these `match` calls would return `["q"]`. + A more practical use of lookaheads is to check two or more patterns in one string. Here is a (naively) simple password checker that looks for between 3 and 6 characters and at least one number: ```js let password = "abc123"; let checkPass = /(?=\w{3,6})(?=\D*\d)/; -checkPass.test(password); // Returns true +checkPass.test(password); ``` # --instructions-- @@ -47,49 +49,49 @@ Your regex should use two positive `lookaheads`. assert(pwRegex.source.match(/\(\?=.*?\)\(\?=.*?\)/) !== null); ``` -Your regex should not match `"astronaut"` +Your regex should not match the string `astronaut` ```js assert(!pwRegex.test('astronaut')); ``` -Your regex should not match `"banan1"` +Your regex should not match the string `banan1` ```js assert(!pwRegex.test('banan1')); ``` -Your regex should match `"bana12"` +Your regex should match the string `bana12` ```js assert(pwRegex.test('bana12')); ``` -Your regex should match `"abc123"` +Your regex should match the string `abc123` ```js assert(pwRegex.test('abc123')); ``` -Your regex should not match `"12345"` +Your regex should not match the string `12345` ```js assert(!pwRegex.test('12345')); ``` -Your regex should match `"8pass99"` +Your regex should match the string `8pass99` ```js assert(pwRegex.test('8pass99')); ``` -Your regex should not match `"1a2bcde"` +Your regex should not match the string `1a2bcde` ```js assert(!pwRegex.test('1a2bcde')); ``` -Your regex should match `"astr1on11aut"` +Your regex should match the string `astr1on11aut` ```js assert(pwRegex.test('astr1on11aut')); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/remove-whitespace-from-start-and-end.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/remove-whitespace-from-start-and-end.md index 63496d7733..dfac829bd7 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/remove-whitespace-from-start-and-end.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/remove-whitespace-from-start-and-end.md @@ -18,7 +18,7 @@ Write a regex and use the appropriate string methods to remove whitespace at the # --hints-- -`result` should equal to `"Hello, World!"` +`result` should be equal to the string `Hello, World!` ```js assert(result == 'Hello, World!'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/restrict-possible-usernames.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/restrict-possible-usernames.md index cb9b99b8da..e109816c5a 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/restrict-possible-usernames.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/restrict-possible-usernames.md @@ -26,79 +26,79 @@ Change the regex `userCheck` to fit the constraints listed above. # --hints-- -Your regex should match `JACK` +Your regex should match the string `JACK` ```js assert(userCheck.test('JACK')); ``` -Your regex should not match `J` +Your regex should not match the string `J` ```js assert(!userCheck.test('J')); ``` -Your regex should match `Jo` +Your regex should match the string `Jo` ```js assert(userCheck.test('Jo')); ``` -Your regex should match `Oceans11` +Your regex should match the string `Oceans11` ```js assert(userCheck.test('Oceans11')); ``` -Your regex should match `RegexGuru` +Your regex should match the string `RegexGuru` ```js assert(userCheck.test('RegexGuru')); ``` -Your regex should not match `007` +Your regex should not match the string `007` ```js assert(!userCheck.test('007')); ``` -Your regex should not match `9` +Your regex should not match the string `9` ```js assert(!userCheck.test('9')); ``` -Your regex should not match `A1` +Your regex should not match the string `A1` ```js assert(!userCheck.test('A1')); ``` -Your regex should not match `BadUs3rnam3` +Your regex should not match the string `BadUs3rnam3` ```js assert(!userCheck.test('BadUs3rnam3')); ``` -Your regex should match `Z97` +Your regex should match the string `Z97` ```js assert(userCheck.test('Z97')); ``` -Your regex should not match `c57bT3` +Your regex should not match the string `c57bT3` ```js assert(!userCheck.test('c57bT3')); ``` -Your regex should match `AB1` +Your regex should match the string `AB1` ```js assert(userCheck.test('AB1')); ``` -Your regex should not match `J%4` +Your regex should not match the string `J%4` ```js assert(!userCheck.test('J%4')) diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/reuse-patterns-using-capture-groups.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/reuse-patterns-using-capture-groups.md index c12d2eb0c8..2558509c76 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/reuse-patterns-using-capture-groups.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/reuse-patterns-using-capture-groups.md @@ -19,10 +19,12 @@ The example below matches any word that occurs twice separated by a space: ```js let repeatStr = "regex regex"; let repeatRegex = /(\w+)\s\1/; -repeatRegex.test(repeatStr); // Returns true -repeatStr.match(repeatRegex); // Returns ["regex regex", "regex"] +repeatRegex.test(repeatStr); +repeatStr.match(repeatRegex); ``` +The `test` call would return `true`, and the `match` call would return `["regex regex", "regex"]`. + Using the `.match()` method on a string will return an array with the string it matches, along with its capture group. # --instructions-- @@ -43,43 +45,43 @@ Your regex should reuse a capture group twice. assert(reRegex.source.match(/\\1|\\2/g).length >= 2); ``` -Your regex should match `"42 42 42"`. +Your regex should match the string `42 42 42`. ```js assert(reRegex.test('42 42 42')); ``` -Your regex should match `"100 100 100"`. +Your regex should match the string `100 100 100`. ```js assert(reRegex.test('100 100 100')); ``` -Your regex should not match `"42 42 42 42"`. +Your regex should not match the string `42 42 42 42`. ```js assert.equal('42 42 42 42'.match(reRegex.source), null); ``` -Your regex should not match `"42 42"`. +Your regex should not match the string `42 42`. ```js assert.equal('42 42'.match(reRegex.source), null); ``` -Your regex should not match `"101 102 103"`. +Your regex should not match the string `101 102 103`. ```js assert(!reRegex.test('101 102 103')); ``` -Your regex should not match `"1 2 3"`. +Your regex should not match the string `1 2 3`. ```js assert(!reRegex.test('1 2 3')); ``` -Your regex should match `"10 10 10"`. +Your regex should match the string `10 10 10`. ```js assert(reRegex.test('10 10 10')); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/specify-exact-number-of-matches.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/specify-exact-number-of-matches.md index 8f7a68cc7b..427d8d6daf 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/specify-exact-number-of-matches.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/specify-exact-number-of-matches.md @@ -12,21 +12,23 @@ You can specify the lower and upper number of patterns with quantity specifiers To specify a certain number of patterns, just have that one number between the curly brackets. -For example, to match only the word `"hah"` with the letter `a` `3` times, your regex would be `/ha{3}h/`. +For example, to match only the word `hah` with the letter `a` `3` times, your regex would be `/ha{3}h/`. ```js let A4 = "haaaah"; let A3 = "haaah"; let A100 = "h" + "a".repeat(100) + "h"; let multipleHA = /ha{3}h/; -multipleHA.test(A4); // Returns false -multipleHA.test(A3); // Returns true -multipleHA.test(A100); // Returns false +multipleHA.test(A4); +multipleHA.test(A3); +multipleHA.test(A100); ``` +In order, the three `test` calls would return `false`, `true`, and `false`. + # --instructions-- -Change the regex `timRegex` to match the word `"Timber"` only when it has four letter `m`'s. +Change the regex `timRegex` to match the word `Timber` only when it has four letter `m`'s. # --hints-- @@ -36,35 +38,35 @@ Your regex should use curly brackets. assert(timRegex.source.match(/{.*?}/).length > 0); ``` -Your regex should not match `"Timber"` +Your regex should not match the string `Timber` ```js timRegex.lastIndex = 0; assert(!timRegex.test('Timber')); ``` -Your regex should not match `"Timmber"` +Your regex should not match the string `Timmber` ```js timRegex.lastIndex = 0; assert(!timRegex.test('Timmber')); ``` -Your regex should not match `"Timmmber"` +Your regex should not match the string `Timmmber` ```js timRegex.lastIndex = 0; assert(!timRegex.test('Timmmber')); ``` -Your regex should match `"Timmmmber"` +Your regex should match the string `Timmmmber` ```js timRegex.lastIndex = 0; assert(timRegex.test('Timmmmber')); ``` -Your regex should not match `"Timber"` with 30 `m`'s in it. +Your regex should not match the string `Timber` with 30 `m`'s in it. ```js timRegex.lastIndex = 0; diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/specify-only-the-lower-number-of-matches.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/specify-only-the-lower-number-of-matches.md index f75994614f..358f095a71 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/specify-only-the-lower-number-of-matches.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/specify-only-the-lower-number-of-matches.md @@ -12,21 +12,23 @@ You can specify the lower and upper number of patterns with quantity specifiers To only specify the lower number of patterns, keep the first number followed by a comma. -For example, to match only the string `"hah"` with the letter `a` appearing at least `3` times, your regex would be `/ha{3,}h/`. +For example, to match only the string `hah` with the letter `a` appearing at least `3` times, your regex would be `/ha{3,}h/`. ```js let A4 = "haaaah"; let A2 = "haah"; let A100 = "h" + "a".repeat(100) + "h"; let multipleA = /ha{3,}h/; -multipleA.test(A4); // Returns true -multipleA.test(A2); // Returns false -multipleA.test(A100); // Returns true +multipleA.test(A4); +multipleA.test(A2); +multipleA.test(A100); ``` +In order, the three `test` calls would return `true`, `false`, and `true`. + # --instructions-- -Change the regex `haRegex` to match the word `"Hazzah"` only when it has four or more letter `z`'s. +Change the regex `haRegex` to match the word `Hazzah` only when it has four or more letter `z`'s. # --hints-- @@ -36,37 +38,37 @@ Your regex should use curly brackets. assert(haRegex.source.match(/{.*?}/).length > 0); ``` -Your regex should not match `"Hazzah"` +Your regex should not match the string `Hazzah` ```js assert(!haRegex.test('Hazzah')); ``` -Your regex should not match `"Hazzzah"` +Your regex should not match the string `Hazzzah` ```js assert(!haRegex.test('Hazzzah')); ``` -Your regex should match `"Hazzzzah"` +Your regex should match the string `Hazzzzah` ```js assert('Hazzzzah'.match(haRegex)[0].length === 8); ``` -Your regex should match `"Hazzzzzah"` +Your regex should match the string `Hazzzzzah` ```js assert('Hazzzzzah'.match(haRegex)[0].length === 9); ``` -Your regex should match `"Hazzzzzzah"` +Your regex should match the string `Hazzzzzzah` ```js assert('Hazzzzzzah'.match(haRegex)[0].length === 10); ``` -Your regex should match `"Hazzah"` with 30 `z`'s in it. +Your regex should match the string `Hazzah` with 30 `z`'s in it. ```js assert('Hazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzah'.match(haRegex)[0].length === 34); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/specify-upper-and-lower-number-of-matches.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/specify-upper-and-lower-number-of-matches.md index 83ed14cecc..aac7dedad2 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/specify-upper-and-lower-number-of-matches.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/specify-upper-and-lower-number-of-matches.md @@ -12,19 +12,21 @@ Recall that you use the plus sign `+` to look for one or more characters and the You can specify the lower and upper number of patterns with quantity specifiers. Quantity specifiers are used with curly brackets (`{` and `}`). You put two numbers between the curly brackets - for the lower and upper number of patterns. -For example, to match only the letter `a` appearing between `3` and `5` times in the string `"ah"`, your regex would be `/a{3,5}h/`. +For example, to match only the letter `a` appearing between `3` and `5` times in the string `ah`, your regex would be `/a{3,5}h/`. ```js let A4 = "aaaah"; let A2 = "aah"; let multipleA = /a{3,5}h/; -multipleA.test(A4); // Returns true -multipleA.test(A2); // Returns false +multipleA.test(A4); +multipleA.test(A2); ``` +The first `test` call would return `true`, while the second would return `false`. + # --instructions-- -Change the regex `ohRegex` to match the entire phrase `"Oh no"` only when it has `3` to `6` letter `h`'s. +Change the regex `ohRegex` to match the entire phrase `Oh no` only when it has `3` to `6` letter `h`'s. # --hints-- @@ -34,37 +36,37 @@ Your regex should use curly brackets. assert(ohRegex.source.match(/{.*?}/).length > 0); ``` -Your regex should not match `"Ohh no"` +Your regex should not match the string `Ohh no` ```js assert(!ohRegex.test('Ohh no')); ``` -Your regex should match `"Ohhh no"` +Your regex should match the string `Ohhh no` ```js assert('Ohhh no'.match(ohRegex)[0].length === 7); ``` -Your regex should match `"Ohhhh no"` +Your regex should match the string `Ohhhh no` ```js assert('Ohhhh no'.match(ohRegex)[0].length === 8); ``` -Your regex should match `"Ohhhhh no"` +Your regex should match the string `Ohhhhh no` ```js assert('Ohhhhh no'.match(ohRegex)[0].length === 9); ``` -Your regex should match `"Ohhhhhh no"` +Your regex should match the string `Ohhhhhh no` ```js assert('Ohhhhhh no'.match(ohRegex)[0].length === 10); ``` -Your regex should not match `"Ohhhhhhh no"` +Your regex should not match the string `Ohhhhhhh no` ```js assert(!ohRegex.test('Ohhhhhhh no')); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/use-capture-groups-to-search-and-replace.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/use-capture-groups-to-search-and-replace.md index d7d2771dae..6b1d6b0592 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/use-capture-groups-to-search-and-replace.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/use-capture-groups-to-search-and-replace.md @@ -16,19 +16,21 @@ You can search and replace text in a string using `.replace()` on a string. The let wrongText = "The sky is silver."; let silverRegex = /silver/; wrongText.replace(silverRegex, "blue"); -// Returns "The sky is blue." ``` +The `replace` call would return the string `The sky is blue.`. + You can also access capture groups in the replacement string with dollar signs (`$`). ```js "Code Camp".replace(/(\w+)\s(\w+)/, '$2 $1'); -// Returns "Camp Code" ``` +The `replace` call would return the string `Camp Code`. + # --instructions-- -Write a regex `fixRegex` using three capture groups that will search for each word in the string "one two three". Then update the `replaceText` variable to replace "one two three" with the string "three two one" and assign the result to the `result` variable. Make sure you are utilizing capture groups in the replacement string using the dollar sign (`$`) syntax. +Write a regex `fixRegex` using three capture groups that will search for each word in the string `one two three`. Then update the `replaceText` variable to replace `one two three` with the string `three two one` and assign the result to the `result` variable. Make sure you are utilizing capture groups in the replacement string using the dollar sign (`$`) syntax. # --hints-- @@ -38,7 +40,7 @@ You should use `.replace()` to search and replace. assert(code.match(/\.replace\(.*\)/)); ``` -Your regex should change `"one two three"` to `"three two one"` +Your regex should change the string `one two three` to the string `three two one` ```js assert(result === 'three two one'); diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/using-the-test-method.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/using-the-test-method.md index e39467f661..dddb321ec5 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/using-the-test-method.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/using-the-test-method.md @@ -10,7 +10,7 @@ dashedName: using-the-test-method Regular expressions are used in programming languages to match parts of strings. You create patterns to help you do that matching. -If you want to find the word `"the"` in the string `"The dog chased the cat"`, you could use the following regular expression: `/the/`. Notice that quote marks are not required within the regular expression. +If you want to find the word `the` in the string `The dog chased the cat`, you could use the following regular expression: `/the/`. Notice that quote marks are not required within the regular expression. JavaScript has multiple ways to use regexes. One way to test a regex is using the `.test()` method. The `.test()` method takes the regex, applies it to a string (which is placed inside the parentheses), and returns `true` or `false` if your pattern finds something or not. @@ -18,9 +18,10 @@ JavaScript has multiple ways to use regexes. One way to test a regex is using th let testStr = "freeCodeCamp"; let testRegex = /Code/; testRegex.test(testStr); -// Returns true ``` +The `test` method here returns `true`. + # --instructions-- Apply the regex `myRegex` on the string `myString` using the `.test()` method.