diff --git a/challenges/01-front-end-development-certification/basic-javascript.json b/challenges/01-front-end-development-certification/basic-javascript.json
index 58b810ec54..0e93d4581f 100644
--- a/challenges/01-front-end-development-certification/basic-javascript.json
+++ b/challenges/01-front-end-development-certification/basic-javascript.json
@@ -19,6 +19,9 @@
"challengeSeed": [
" "
],
+ "solutions": [
+ "// Fake Comment\n/* Another Comment */"
+ ],
"tests": [
"assert(code.match(/(\\/\\/)...../g), 'message: Create a //
style comment that contains at least five letters.');",
"assert(code.match(/(\\/\\*)[\\w\\W]{5,}(?=\\*\\/)/gm), 'message: Create a /* */
style comment that contains at least five letters.');",
@@ -37,10 +40,6 @@
"
welcomeToBooleans
function so that it returns true
instead of false
when the run button is clicked."
],
- "tests": [
- "assert(typeof(welcomeToBooleans()) === 'boolean', 'message: The welcomeToBooleans()
function should return a boolean (true/false) value.');",
- "assert(welcomeToBooleans() === true, 'message: welcomeToBooleans()
should return true.');"
- ],
"challengeSeed": [
"function welcomeToBooleans() {",
"",
@@ -54,6 +53,13 @@
"tail": [
"welcomeToBooleans();"
],
+ "solutions": [
+ "function welcomeToBooleans() {\n return true; // Change this line\n}"
+ ],
+ "tests": [
+ "assert(typeof(welcomeToBooleans()) === 'boolean', 'message: The welcomeToBooleans()
function should return a boolean (true/false) value.');",
+ "assert(welcomeToBooleans() === true, 'message: welcomeToBooleans()
should return true.');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -70,9 +76,6 @@
"Hint",
"Look at the ourName
example if you get stuck."
],
- "tests": [
- "assert((function(){if(typeof(myName) !== \"undefined\" && typeof(myName) === \"string\" && myName.length > 0){return true;}else{return false;}})(), 'message: myName
should be a string that contains at least one character in it.');"
- ],
"challengeSeed": [
"// Example",
"var ourName = \"Free Code Camp\";",
@@ -83,6 +86,12 @@
"tail": [
"if(typeof(myName) !== \"undefined\"){(function(v){return v;})(myName);}"
],
+ "solutions": [
+ "var myName = \"Test Testerson\";"
+ ],
+ "tests": [
+ "assert((function(){if(typeof(myName) !== \"undefined\" && typeof(myName) === \"string\" && myName.length > 0){return true;}else{return false;}})(), 'message: myName
should be a string that contains at least one character in it.');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -102,12 +111,6 @@
"Assign the contents of a
to variable b
."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(/var a;/.test(code) && /var b = 2;/.test(code), 'message: Do not change code above the line');",
- "assert(typeof a === 'number' && a === 7, 'message: a
should have a value of 7');",
- "assert(typeof b === 'number' && b === 7, 'message: b
should have a value of 7');",
- "assert(/b\\s*=\\s*a\\s*;/g.test(code) > 0, 'message: a
should be assigned to b
with =
');"
- ],
"challengeSeed": [
"// Setup",
"var a;",
@@ -122,6 +125,12 @@
"solutions": [
"var a;\nvar b = 2;\na = 7;\nb = a;"
],
+ "tests": [
+ "assert(/var a;/.test(code) && /var b = 2;/.test(code), 'message: Do not change code above the line');",
+ "assert(typeof a === 'number' && a === 7, 'message: a
should have a value of 7');",
+ "assert(typeof b === 'number' && b === 7, 'message: b
should have a value of 7');",
+ "assert(/b\\s*=\\s*a\\s*;/g.test(code) > 0, 'message: a
should be assigned to b
with =
');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -143,9 +152,6 @@
"Define a variable a
with var
and initialize it to a value of 9
."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(/var\\s+a\\s*=\\s*9\\s*/.test(code), 'message: Initialize a
to a value of 9
');"
- ],
"challengeSeed": [
"// Example",
"var ourVar = 19;",
@@ -159,6 +165,9 @@
"solutions": [
"var a = 9;"
],
+ "tests": [
+ "assert(/var\\s+a\\s*=\\s*9\\s*/.test(code), 'message: Initialize a
to a value of 9
');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -176,12 +185,6 @@
"Initialize the three variables a
, b
, and c
with 5
, 10
, and \"I am a\"
respectively so that they will not be undefined
."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(typeof a === 'number' && a === 6, 'message: a
should be defined and have a value of 6
');",
- "assert(typeof b === 'number' && b === 15, 'message: b
should be defined and have a value of 15
');",
- "assert(!/undefined/.test(c) && c === \"I am a String!\", 'message: c
should not contain undefined
and should have a value of \"I am a String!\"');",
- "assert(/a = a \\+ 1;/.test(code) && /b = b \\+ 5;/.test(code) && /c = c \\+ \" String!\";/.test(code), 'message: Do not change code below the line');"
- ],
"challengeSeed": [
"// Initialize these three variables",
"var a;",
@@ -201,6 +204,12 @@
"solutions": [
"var a = 5;\nvar b = 10;\nvar c = \"I am a\";\na = a + 1;\nb = b + 5;\nc = c + \" String!\";"
],
+ "tests": [
+ "assert(typeof a === 'number' && a === 6, 'message: a
should be defined and have a value of 6
');",
+ "assert(typeof b === 'number' && b === 15, 'message: b
should be defined and have a value of 15
');",
+ "assert(!/undefined/.test(c) && c === \"I am a String!\", 'message: c
should not contain undefined
and should have a value of \"I am a String!\"');",
+ "assert(/a = a \\+ 1;/.test(code) && /b = b \\+ 5;/.test(code) && /c = c \\+ \" String!\";/.test(code), 'message: Do not change code below the line');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -223,11 +232,6 @@
"Correct the variable assignments so their names match their variable declarations above."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(StUdLyCapVaR === 10, 'message: StUdLyCapVaR has the correct case');",
- "assert(properCamelCase === \"A String\", 'message: properCamelCase has the correct case');",
- "assert(TitleCaseOver === 9000, 'message: TitleCaseOver has the correct case');"
- ],
"challengeSeed": [
"// Setup",
"var StUdLyCapVaR;",
@@ -244,6 +248,11 @@
"solutions": [
"var StUdLyCapVaR;\nvar properCamelCase;\nvar TitleCaseOver;\n\nStUdLyCapVaR = 10;\nproperCamelCase = \"A String\";\nTitleCaseOver = 9000;"
],
+ "tests": [
+ "assert(StUdLyCapVaR === 10, 'message: StUdLyCapVaR has the correct case');",
+ "assert(properCamelCase === \"A String\", 'message: properCamelCase has the correct case');",
+ "assert(TitleCaseOver === 9000, 'message: TitleCaseOver has the correct case');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -266,10 +275,6 @@
"0
so that sum will equal 20
."
],
- "tests": [
- "assert(sum === 20, 'message: sum
should equal 20
');",
- "assert(/\\+/.test(code), 'message: Use the +
operator');"
- ],
"challengeSeed": [
"var sum = 10 + 0;",
""
@@ -277,6 +282,13 @@
"tail": [
"(function(z){return 'sum='+z;})(sum);"
],
+ "solutions": [
+ "var sum = 10 + 10;"
+ ],
+ "tests": [
+ "assert(sum === 20, 'message: sum
should equal 20
');",
+ "assert(/\\+/.test(code), 'message: Use the +
operator');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -293,10 +305,6 @@
"0
so the difference is 12
."
],
- "tests": [
- "assert(difference === 12, 'message: Make the variable difference
equal 12.');",
- "assert(/\\d+\\s*-\\s*\\d+/.test(code),'message: User the -
operator');"
- ],
"challengeSeed": [
"var difference = 45 - 0;",
"",
@@ -308,6 +316,10 @@
"solutions": [
"var difference = 45 - 33;"
],
+ "tests": [
+ "assert(difference === 12, 'message: Make the variable difference
equal 12.');",
+ "assert(/\\d+\\s*-\\s*\\d+/.test(code),'message: User the -
operator');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -324,10 +336,6 @@
"0
so that product will equal 80
."
],
- "tests": [
- "assert(product === 80,'message: Make the variable product
equal 80');",
- "assert(/\\*/.test(code), 'message: Use the *
operator');"
- ],
"challengeSeed": [
"var product = 8 * 0;",
"",
@@ -339,6 +347,10 @@
"solutions": [
"var product = 8 * 10;"
],
+ "tests": [
+ "assert(product === 80,'message: Make the variable product
equal 80');",
+ "assert(/\\*/.test(code), 'message: Use the *
operator');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -355,10 +367,6 @@
"0
so that the quotient
is equal to 2
."
],
- "tests": [
- "assert(quotient === 2, 'message: Make the variable quotient
equal to 2.');",
- "assert(/\\d+\\s*\\/\\s*\\d+/.test(code), 'message: Use the /
operator');"
- ],
"challengeSeed": [
"var quotient = 66 / 0;",
"",
@@ -367,6 +375,13 @@
"tail": [
"(function(z){return 'quotient = '+z;})(quotient);"
],
+ "solutions": [
+ "var quotient = 66 / 33;"
+ ],
+ "tests": [
+ "assert(quotient === 2, 'message: Make the variable quotient
equal to 2.');",
+ "assert(/\\d+\\s*\\/\\s*\\d+/.test(code), 'message: Use the /
operator');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -382,11 +397,6 @@
"Change the code to use the ++
operator on myVar
"
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(myVar === 88, 'message: myVar
should equal 88
');",
- "assert(/[+]{2}/.test(code), 'message: Use the ++
operator');",
- "assert(/var myVar = 87;/.test(code), 'message: Do not change code above the line');"
- ],
"challengeSeed": [
"var myVar = 87;",
"",
@@ -400,6 +410,11 @@
"solutions": [
"var myVar = 87;\nmyVar++;"
],
+ "tests": [
+ "assert(myVar === 88, 'message: myVar
should equal 88
');",
+ "assert(/[+]{2}/.test(code), 'message: Use the ++
operator');",
+ "assert(/var myVar = 87;/.test(code), 'message: Do not change code above the line');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -420,11 +435,6 @@
"Change the code to use the --
operator on myVar
"
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(myVar === 10, 'message: myVar
should equal 10
');",
- "assert(/myVar[-]{2}/.test(code), 'message: Use the --
operator on myVar
');",
- "assert(/var myVar = 11;/.test(code), 'message: Do not change code above the line');"
- ],
"challengeSeed": [
"var myVar = 11;",
"",
@@ -438,6 +448,11 @@
"solutions": [
"var myVar = 11;\nmyVar--;"
],
+ "tests": [
+ "assert(myVar === 10, 'message: myVar
should equal 10
');",
+ "assert(/myVar[-]{2}/.test(code), 'message: Use the --
operator on myVar
');",
+ "assert(/var myVar = 11;/.test(code), 'message: Do not change code above the line');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -456,10 +471,6 @@
"myDecimal
and give it a decimal value."
],
- "tests": [
- "assert(typeof myDecimal === \"number\", 'message: myDecimal
should be a number.');",
- "assert(code.match(/\\d+\\.\\d+/g).length >= 2, 'message: myDecimal
should have a decimal point'); "
- ],
"challengeSeed": [
"var ourDecimal = 5.7;",
"",
@@ -468,7 +479,14 @@
""
],
"tail": [
- "(function(){if(typeof(myDecimal) !== \"undefined\"){return myDecimal;}})();"
+ "(function(){if(typeof myDecimal !== \"undefined\"){return myDecimal;}})();"
+ ],
+ "solutions": [
+ "var myDecimal = 9.9;"
+ ],
+ "tests": [
+ "assert(typeof myDecimal === \"number\", 'message: myDecimal
should be a number.');",
+ "assert(myDecimal % 1 != 0, 'message: myDecimal
should have a decimal point'); "
],
"type": "waypoint",
"challengeType": "1"
@@ -482,18 +500,21 @@
"0.0
so that product will equal 5.0
."
],
- "tests": [
- "assert(product === 5.0, 'message: The variable product
should equal 5.0
.');",
- "assert(/\\*/.test(code), 'message: You should use the *
operator');"
- ],
- "tail": [
- "(function(y){return 'product = '+y;})(product);"
- ],
"challengeSeed": [
"var product = 2.0 * 0.0;",
"",
""
],
+ "tail": [
+ "(function(y){return 'product = '+y;})(product);"
+ ],
+ "solutions": [
+ "var product = 2.0 * 2.5;"
+ ],
+ "tests": [
+ "assert(product === 5.0, 'message: The variable product
should equal 5.0
.');",
+ "assert(/\\*/.test(code), 'message: You should use the *
operator');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -505,10 +526,6 @@
"0.0
so that quotient
will equal to 2.2
."
],
- "tests": [
- "assert(quotient === 2.2, 'message: The variable quotient
should equal 2.2
.');",
- "assert(/\\//.test(code), 'message: You should use the /
operator');"
- ],
"challengeSeed": [
"var quotient = 0.0 / 2.0;",
"",
@@ -517,6 +534,13 @@
"tail": [
"(function(y){return 'quotient = '+y;})(quotient);"
],
+ "solutions": [
+ "var quotient = 4.4 / 2.0;"
+ ],
+ "tests": [
+ "assert(quotient === 2.2, 'message: The variable quotient
should equal 2.2
.');",
+ "assert(/\\//.test(code), 'message: You should use the /
operator');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -536,10 +560,6 @@
"Set remainder
equal to the remainder of 11
divided by 3
using the remainder (%
) operator."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(remainder === 2, 'message: The value of remainder
should be 2
');",
- "assert(/\\d+\\s*%\\s*\\d+/.test(code), 'message: You should use the %
operator');"
- ],
"challengeSeed": [
"// Only change code below this line",
"",
@@ -552,6 +572,10 @@
"solutions": [
"var remainder = 11 % 3;"
],
+ "tests": [
+ "assert(remainder === 2, 'message: The value of remainder
should be 2
');",
+ "assert(/\\d+\\s*%\\s*\\d+/.test(code), 'message: You should use the %
operator');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -573,13 +597,6 @@
"Convert the assignments for a
, b
, and c
to use the +=
operator."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(a === 15, 'message: a
should equal 15
');",
- "assert(b === 26, 'message: b
should equal 26
');",
- "assert(c === 19, 'message: c
should equal 19
');",
- "assert(code.match(/\\+=/g).length === 3, 'message: You should use the +=
operator for each variable');",
- "assert(/var a = 3;/.test(code) && /var b = 17;/.test(code) && /var c = 12;/.test(code), 'message: Do not modify the code above the line');"
- ],
"challengeSeed": [
"var a = 3;",
"var b = 17;",
@@ -598,6 +615,13 @@
"solutions": [
"var a = 3;\nvar b = 17;\nvar c = 12;\n\na += 12;\nb += 9;\nc += 7;"
],
+ "tests": [
+ "assert(a === 15, 'message: a
should equal 15
');",
+ "assert(b === 26, 'message: b
should equal 26
');",
+ "assert(c === 19, 'message: c
should equal 19
');",
+ "assert(code.match(/\\+=/g).length === 3, 'message: You should use the +=
operator for each variable');",
+ "assert(/var a = 3;/.test(code) && /var b = 17;/.test(code) && /var c = 12;/.test(code), 'message: Do not modify the code above the line');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -618,13 +642,6 @@
"Convert the assignments for a
, b
, and c
to use the -=
operator."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(a === 5, 'message: a
should equal 5
');",
- "assert(b === -6, 'message: b
should equal -6
');",
- "assert(c === 2, 'message: c
should equal 2
');",
- "assert(code.match(/-=/g).length === 3, 'message: You should use the -=
operator for each variable');",
- "assert(/var a = 11;/.test(code) && /var b = 9;/.test(code) && /var c = 3;/.test(code), 'message: Do not modify the code above the line');"
- ],
"challengeSeed": [
"var a = 11;",
"var b = 9;",
@@ -644,6 +661,13 @@
"solutions": [
"var a = 11;\nvar b = 9;\nvar c = 3;\n\na -= 6;\nb -= 15;\nc -= 1;\n\n"
],
+ "tests": [
+ "assert(a === 5, 'message: a
should equal 5
');",
+ "assert(b === -6, 'message: b
should equal -6
');",
+ "assert(c === 2, 'message: c
should equal 2
');",
+ "assert(code.match(/-=/g).length === 3, 'message: You should use the -=
operator for each variable');",
+ "assert(/var a = 11;/.test(code) && /var b = 9;/.test(code) && /var c = 3;/.test(code), 'message: Do not modify the code above the line');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -664,13 +688,6 @@
"Convert the assignments for a
, b
, and c
to use the *=
operator."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(a === 25, 'message: a
should equal 25
');",
- "assert(b === 36, 'message: b
should equal 36
');",
- "assert(c === 46, 'message: c
should equal 46
');",
- "assert(code.match(/\\*=/g).length === 3, 'message: You should use the *=
operator for each variable');",
- "assert(/var a = 5;/.test(code) && /var b = 12;/.test(code) && /var c = 4\\.6;/.test(code), 'message: Do not modify the code above the line');"
- ],
"challengeSeed": [
"var a = 5;",
"var b = 12;",
@@ -690,6 +707,13 @@
"solutions": [
"var a = 5;\nvar b = 12;\nvar c = 4.6;\n\na *= 5;\nb *= 3;\nc *= 10;"
],
+ "tests": [
+ "assert(a === 25, 'message: a
should equal 25
');",
+ "assert(b === 36, 'message: b
should equal 36
');",
+ "assert(c === 46, 'message: c
should equal 46
');",
+ "assert(code.match(/\\*=/g).length === 3, 'message: You should use the *=
operator for each variable');",
+ "assert(/var a = 5;/.test(code) && /var b = 12;/.test(code) && /var c = 4\\.6;/.test(code), 'message: Do not modify the code above the line');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -710,13 +734,6 @@
"Convert the assignments for a
, b
, and c
to use the /=
operator."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(a === 4, 'message: a
should equal 4
');",
- "assert(b === 27, 'message: b
should equal 27
');",
- "assert(c === 3, 'message: c
should equal 3
');",
- "assert(code.match(/\\/=/g).length === 3, 'message: You should use the /=
operator for each variable');",
- "assert(/var a = 48;/.test(code) && /var b = 108;/.test(code) && /var c = 33;/.test(code), 'message: Do not modify the code above the line');"
- ],
"challengeSeed": [
"var a = 48;",
"var b = 108;",
@@ -735,6 +752,13 @@
"solutions": [
"var a = 48;\nvar b = 108;\nvar c = 33;\n\na /= 12;\nb /= 4;\nc /= 11;"
],
+ "tests": [
+ "assert(a === 4, 'message: a
should equal 4
');",
+ "assert(b === 27, 'message: b
should equal 27
');",
+ "assert(c === 3, 'message: c
should equal 3
');",
+ "assert(code.match(/\\/=/g).length === 3, 'message: You should use the /=
operator for each variable');",
+ "assert(/var a = 48;/.test(code) && /var b = 108;/.test(code) && /var c = 33;/.test(code), 'message: Do not modify the code above the line');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -752,14 +776,6 @@
"You are given a variable Tc
representing a temperature in Celsius. Create a variable Tf
and apply the algorithm to assign it the corresponding temperature in Fahrenheit."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(typeof convert(0) === 'number', 'message: convert(0)
should return a number');",
- "assert(convert(-30) === -22, 'message: convert(-30)
should return a value of -22
');",
- "assert(convert(-10) === 14, 'message: convert(-10)
should return a value of 14
');",
- "assert(convert(0) === 32, 'message: convert(0)
should return a value of 32
');",
- "assert(convert(20) === 68, 'message: convert(20)
should return a value of 68
');",
- "assert(convert(30) === 86, 'message: convert(30)
should return a value of 86
');"
- ],
"challengeSeed": [
"function convert(Tc) {",
" // Only change code below this line",
@@ -779,6 +795,14 @@
"solutions": [
"function convert(Tc) {\n var Tf = Tc * 9/5 + 32;\n if(typeof Tf !== 'undefined') {\n return Tf;\n } else {\n return \"Tf not defined\";\n }\n}"
],
+ "tests": [
+ "assert(typeof convert(0) === 'number', 'message: convert(0)
should return a number');",
+ "assert(convert(-30) === -22, 'message: convert(-30)
should return a value of -22
');",
+ "assert(convert(-10) === 14, 'message: convert(-10)
should return a value of 14
');",
+ "assert(convert(0) === 32, 'message: convert(0)
should return a value of 32
');",
+ "assert(convert(20) === 68, 'message: convert(20)
should return a value of 68
');",
+ "assert(convert(30) === 86, 'message: convert(30)
should return a value of 86
');"
+ ],
"type": "bonfire",
"challengeType": "5",
"nameCn": "",
@@ -797,10 +821,6 @@
"string
variables: myFirstName
and myLastName
and assign them the values of your first and last name, respectively."
],
- "tests": [
- "assert((function(){if(typeof(myFirstName) !== \"undefined\" && typeof(myFirstName) === \"string\" && myFirstName.length > 0){return true;}else{return false;}})(), 'message: myFirstName
should be a string with at least one character in it.');",
- "assert((function(){if(typeof(myLastName) !== \"undefined\" && typeof(myLastName) === \"string\" && myLastName.length > 0){return true;}else{return false;}})(), 'message: myLastName
should be a string with at least one character in it.');"
- ],
"challengeSeed": [
"// Example",
"var firstName = \"Alan\";",
@@ -817,6 +837,10 @@
"solutions": [
"var myFirstName = \"Alan\";\nvar myLastName = \"Turing\";"
],
+ "tests": [
+ "assert((function(){if(typeof(myFirstName) !== \"undefined\" && typeof(myFirstName) === \"string\" && myFirstName.length > 0){return true;}else{return false;}})(), 'message: myFirstName
should be a string with at least one character in it.');",
+ "assert((function(){if(typeof(myLastName) !== \"undefined\" && typeof(myLastName) === \"string\" && myLastName.length > 0){return true;}else{return false;}})(), 'message: myLastName
should be a string with at least one character in it.');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -833,9 +857,6 @@
"\"I am a \"double quoted\" string inside \"double quotes\"\"
"
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(code.match(/\\\\\"/g).length === 4 && code.match(/[^\\\\]\"/g).length === 2, 'message: You should use two double quotes ("
) and four escaped double quotes (\"
) ');"
- ],
"challengeSeed": [
"var myStr; // Change this line",
"",
@@ -844,6 +865,9 @@
"solutions": [
"var myStr = \"I am a \\\"double quoted\\\" string inside \\\"double quotes\\\"\";"
],
+ "tests": [
+ "assert(code.match(/\\\\\"/g).length === 4 && code.match(/[^\\\\]\"/g).length === 2, 'message: You should use two double quotes ("
) and four escaped double quotes (\"
) ');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -864,11 +888,6 @@
"Change the provided string from double to single quotes and remove the escaping."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(!/\\\\/g.test(code), 'message: Remove all the backslashes
(\\
)');",
- "assert(code.match(/\"/g).length === 4 && code.match(/'/g).length === 2, 'message: You should have two single quotes '
and four double quotes "
');",
- "assert(myStr === 'Link', 'message: Only remove the backslashes \\
used to escape quotes.');"
- ],
"challengeSeed": [
"var myStr = \"Link\";",
"",
@@ -880,6 +899,11 @@
"solutions": [
"var myStr = 'Link';"
],
+ "tests": [
+ "assert(!/\\\\/g.test(code), 'message: Remove all the backslashes
(\\
)');",
+ "assert(code.match(/\"/g).length === 4 && code.match(/'/g).length === 2, 'message: You should have two single quotes '
and four double quotes "
');",
+ "assert(myStr === 'Link', 'message: Only remove the backslashes \\
used to escape quotes.');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -899,9 +923,6 @@
"Encode the following sequence, separated by spaces:backslash tab tab carriage-return new-line
and assign it to myStr
"
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(myStr === \"\\\\ \\t \\t \\r \\n\", 'message: myStr
should have the escape sequences for backslash tab tab carriage-return new-line
separated by spaces');"
- ],
"challengeSeed": [
"var myStr; // Change this line",
"",
@@ -910,6 +931,9 @@
"solutions": [
"var myStr = \"\\\\ \\t \\t \\r \\n\";"
],
+ "tests": [
+ "assert(myStr === \"\\\\ \\t \\t \\r \\n\", 'message: myStr
should have the escape sequences for backslash tab tab carriage-return new-line
separated by spaces');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -929,10 +953,6 @@
"Build myStr
from the strings \"This is the start. \"
and \"This is the end.\"
using the +
operator."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(myStr === \"This is the start. This is the end.\", 'message: myStr
should have a value of This is the start. This is the end.
');",
- "assert(code.match(/\"\\s*\\+\\s*\"/g).length > 1, 'message: Use the +
operator to build myStr
');"
- ],
"challengeSeed": [
"// Example",
"var ourStr = \"I come first. \" + \"I come second.\";",
@@ -946,6 +966,10 @@
"solutions": [
"var ourStr = \"I come first. \" + \"I come second.\";\nvar myStr = \"This is the start. \" + \"This is the end.\";"
],
+ "tests": [
+ "assert(myStr === \"This is the start. This is the end.\", 'message: myStr
should have a value of This is the start. This is the end.
');",
+ "assert(code.match(/\"\\s*\\+\\s*\"/g).length > 1, 'message: Use the +
operator to build myStr
');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -963,10 +987,6 @@
"Build myStr
over several lines by concatenating these two strings:\"This is the first sentance. \"
and \"This is the second sentance.\"
using the +=
operator."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(myStr === \"This is the first sentance. This is the second sentance.\", 'message: myStr
should have a value of This is the first sentance. This is the second sentance.
');",
- "assert(code.match(/\\w\\s*\\+=\\s*\"/g).length > 1 && code.match(/\\w\\s*\\=\\s*\"/g).length > 1, 'message: Use the +=
operator to build myStr
');"
- ],
"challengeSeed": [
"// Example",
"var ourStr = \"I come first. \";",
@@ -981,6 +1001,10 @@
"solutions": [
"var ourStr = \"I come first. \";\nourStr += \"I come second.\";\n\nvar myStr = \"This is the first sentance. \";\nmyStr += \"This is the second sentance.\";"
],
+ "tests": [
+ "assert(myStr === \"This is the first sentance. This is the second sentance.\", 'message: myStr
should have a value of This is the first sentance. This is the second sentance.
');",
+ "assert(code.match(/\\w\\s*\\+=\\s*\"/g).length > 1 && code.match(/\\w\\s*\\=\\s*\"/g).length > 1, 'message: Use the +=
operator to build myStr
');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -998,10 +1022,6 @@
"Set myName
and build myStr
with myName
between the strings \"My name is \"
and \" and I am swell!\"
"
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(typeof myName !== 'undefined' && myName.length > 2, 'message: myName
should be set to a string at least 3 characters long');",
- "assert(code.match(/\"\\s*\\+\\s*myName\\s*\\+\\s*\"/g).length > 0, 'message: Use two +
operators to build myStr
with myName inside it');"
- ],
"challengeSeed": [
"// Example",
"var ourName = \"Free Code Camp\";",
@@ -1016,6 +1036,10 @@
"solutions": [
"var myName = \"Bob\";\nvar myStr = \"My name is \" + myName + \" and I am swell!\";"
],
+ "tests": [
+ "assert(typeof myName !== 'undefined' && myName.length > 2, 'message: myName
should be set to a string at least 3 characters long');",
+ "assert(code.match(/\"\\s*\\+\\s*myName\\s*\\+\\s*\"/g).length > 0, 'message: Use two +
operators to build myStr
with myName inside it');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -1033,10 +1057,6 @@
"Set someAdjective
and append it to myStr
using the +=
operator."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(typeof someAdjective !== 'undefined' && someAdjective.length > 2, 'message: someAdjective
should be set to a string at least 3 characters long');",
- "assert(code.match(/\\w\\s*\\+=\\s*someAdjective\\s*;/).length > 0, 'message: Append someAdjective
to myStr
using the +=
operator');"
- ],
"challengeSeed": [
"// Example",
"var anAdjective = \"awesome!\";",
@@ -1052,6 +1072,10 @@
"solutions": [
"var anAdjective = \"awesome!\";\nvar ourStr = \"Free Code Camp is \";\nourStr += anAdjective;\n\nvar someAdjective = \"neat\";\nvar myStr = \"Learning to code is \";\nmyStr += someAdjective;"
],
+ "tests": [
+ "assert(typeof someAdjective !== 'undefined' && someAdjective.length > 2, 'message: someAdjective
should be set to a string at least 3 characters long');",
+ "assert(code.match(/\\w\\s*\\+=\\s*someAdjective\\s*;/).length > 0, 'message: Append someAdjective
to myStr
using the +=
operator');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -1070,10 +1094,6 @@
"Instructions
",
"Use the .length
property to count the number of characters in the lastName
variable and assign it to lastNameLength
."
],
- "tests": [
- "assert((function(){if(typeof(lastNameLength) !== \"undefined\" && typeof(lastNameLength) === \"number\" && lastNameLength === 8){return true;}else{return false;}})(), 'message: lastNameLength
should be equal to eight.');",
- "assert((function(){if(code.match(/\\.length/gi) && code.match(/\\.length/gi).length >= 2 && code.match(/var lastNameLength \\= 0;/gi) && code.match(/var lastNameLength \\= 0;/gi).length >= 1){return true;}else{return false;}})(), 'message: You should be getting the length of lastName
by using .length
like this: lastName.length
.');"
- ],
"challengeSeed": [
"// Example",
"var firstNameLength = 0;",
@@ -1094,7 +1114,13 @@
"tail": [
"if(typeof(lastNameLength) !== \"undefined\"){(function(){return lastNameLength;})();}"
],
- "solution": "var lastNameLength = 0;\nvar lastName = \"Lovelace\";\nlastNameLength = lastName.length;",
+ "solutions": [
+ "var firstNameLength = 0;\nvar firstName = \"Ada\";\nfirstNameLength = firstName.length;\n\nvar lastNameLength = 0;\nvar lastName = \"Lovelace\";\nlastNameLength = lastName.length;"
+ ],
+ "tests": [
+ "assert((function(){if(typeof(lastNameLength) !== \"undefined\" && typeof(lastNameLength) === \"number\" && lastNameLength === 8){return true;}else{return false;}})(), 'message: lastNameLength
should be equal to eight.');",
+ "assert((function(){if(code.match(/\\.length/gi) && code.match(/\\.length/gi).length >= 2 && code.match(/var lastNameLength \\= 0;/gi) && code.match(/var lastNameLength \\= 0;/gi).length >= 1){return true;}else{return false;}})(), 'message: You should be getting the length of lastName
by using .length
like this: lastName.length
.');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -1110,9 +1136,6 @@
"Hint",
"
Try looking at the firstLetterOfFirstName
variable declaration if you get stuck."
],
- "tests": [
- "assert((function(){if(typeof(firstLetterOfLastName) !== \"undefined\" && code.match(/\\[0\\]/gi) && typeof(firstLetterOfLastName) === \"string\" && firstLetterOfLastName === \"L\"){return true;}else{return false;}})(), 'message: The firstLetterOfLastName
variable should have the value of L
.');"
- ],
"challengeSeed": [
"// Example",
"var firstLetterOfFirstName = \"\";",
@@ -1134,6 +1157,9 @@
"solutions": [
"var firstLetterOfLastName = \"\";\nvar lastName = \"Lovelace\";\n\n// Only change code below this line\nfirstLetterOfLastName = lastName[0];"
],
+ "tests": [
+ "assert((function(){if(typeof(firstLetterOfLastName) !== \"undefined\" && code.match(/\\[0\\]/gi) && typeof(firstLetterOfLastName) === \"string\" && firstLetterOfLastName === \"L\"){return true;}else{return false;}})(), 'message: The firstLetterOfLastName
variable should have the value of L
.');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -1150,13 +1176,6 @@
"Correct the assignment to myStr
to achieve the desired effect."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(myStr === \"Hello World\", 'message: myStr
should have a value of Hello World
');",
- "assert(/myStr = \"Jello World\"/.test(code), 'message: Do not change the code above the line');"
- ],
- "tail": [
- "(function(v){return \"myStr = \" + v;})(myStr);"
- ],
"challengeSeed": [
"// Setup",
"var myStr = \"Jello World\";",
@@ -1167,9 +1186,16 @@
"",
""
],
+ "tail": [
+ "(function(v){return \"myStr = \" + v;})(myStr);"
+ ],
"solutions": [
"var myStr = \"Jello World\";\nmyStr = \"Hello World\";"
],
+ "tests": [
+ "assert(myStr === \"Hello World\", 'message: myStr
should have a value of Hello World
');",
+ "assert(/myStr = \"Jello World\"/.test(code), 'message: Do not change the code above the line');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -1189,9 +1215,6 @@
"Hint",
"
Try looking at the secondLetterOfFirstName
variable declaration if you get stuck."
],
- "tests": [
- "assert(thirdLetterOfLastName === 'v', 'message: The thirdLetterOfLastName
variable should have the value of v
.');"
- ],
"challengeSeed": [
"// Example",
"var firstName = \"Ada\";",
@@ -1211,6 +1234,9 @@
"solutions": [
"var lastName = \"Lovelace\";\nvar thirdLetterOfLastName = lastName[2];"
],
+ "tests": [
+ "assert(thirdLetterOfLastName === 'v', 'message: The thirdLetterOfLastName
variable should have the value of v
.');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -1225,10 +1251,6 @@
"Hint",
"
Try looking at the lastLetterOfFirstName
variable declaration if you get stuck."
],
- "tests": [
- "assert(lastLetterOfLastName === \"e\", 'message: lastLetterOfLastName
should be \"e\".');",
- "assert(code.match(/\\.length/g).length === 2, 'message: You have to use .length
to get the last letter.');"
- ],
"challengeSeed": [
"// Example",
"var firstName = \"Ada\";",
@@ -1248,6 +1270,10 @@
"solutions": [
"var firstName = \"Ada\";\nvar lastLetterOfFirstName = firstName[firstName.length - 1];\n\nvar lastName = \"Lovelace\";\nvar lastLetterOfLastName = lastName[lastName.length - 1];"
],
+ "tests": [
+ "assert(lastLetterOfLastName === \"e\", 'message: lastLetterOfLastName
should be \"e\".');",
+ "assert(code.match(/\\.length/g).length === 2, 'message: You have to use .length
to get the last letter.');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -1262,10 +1288,6 @@
" Hint",
"
Try looking at the thirdToLastLetterOfFirstName
variable declaration if you get stuck."
],
- "tests": [
- "assert(secondToLastLetterOfLastName === 'c', 'message: secondToLastLetterOfLastName
should be \"c\".');",
- "assert(code.match(/\\.length/g).length === 2, 'message: You have to use .length
to get the second last letter.');"
- ],
"challengeSeed": [
"// Example",
"var firstName = \"Ada\";",
@@ -1285,6 +1307,10 @@
"solutions": [
"var firstName = \"Ada\";\nvar thirdToLastLetterOfFirstName = firstName[firstName.length - 3];\n\nvar lastName = \"Lovelace\";\nvar secondToLastLetterOfLastName = lastName[lastName.length - 2];"
],
+ "tests": [
+ "assert(secondToLastLetterOfLastName === 'c', 'message: secondToLastLetterOfLastName
should be \"c\".');",
+ "assert(code.match(/\\.length/g).length === 2, 'message: You have to use .length
to get the second last letter.');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -1298,12 +1324,6 @@
"The tests will run your function with several different inputs to make sure it works properly."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(typeof wordBlanks(\"\",\"\",\"\",\"\") === 'string', 'message: wordBlanks(\"\",\"\",\"\",\"\")
should return a string');",
- "assert(wordBlanks(\"\",\"\",\"\",\"\").length > 30, 'message: wordBlanks(\"\",\"\",\"\",\"\")
should return at least 30 characters with empty inputs');",
- "assert(/dog/.test(test1) && /big/.test(test1) && /ran/.test(test1) && /quickly/.test(test1),'message: wordBlanks(\"dog\", \"big\", \"ran\", \"quickly\")
should contain all of the passed words.');",
- "assert(/cat/.test(test2) && /little/.test(test2) && /hit/.test(test2) && /slowly/.test(test2),'message: wordBlanks(\"cat\", \"little\", \"hit\", \"slowly\")
should contain all of the passed words.');"
- ],
"challengeSeed": [
"function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {",
" var result = \"\";",
@@ -1324,6 +1344,12 @@
"solutions": [
"function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {\n var result = \"\";\n\n result = \"Once there was a \" + myNoun + \" which was very \" + myAdjective + \". \";\n result += \"It \" + myVerb + \" \" + myAdverb + \" around the yard.\";\n\n return result;\n}"
],
+ "tests": [
+ "assert(typeof wordBlanks(\"\",\"\",\"\",\"\") === 'string', 'message: wordBlanks(\"\",\"\",\"\",\"\")
should return a string');",
+ "assert(wordBlanks(\"\",\"\",\"\",\"\").length > 30, 'message: wordBlanks(\"\",\"\",\"\",\"\")
should return at least 30 characters with empty inputs');",
+ "assert(/dog/.test(test1) && /big/.test(test1) && /ran/.test(test1) && /quickly/.test(test1),'message: wordBlanks(\"dog\", \"big\", \"ran\", \"quickly\")
should contain all of the passed words.');",
+ "assert(/cat/.test(test2) && /little/.test(test2) && /hit/.test(test2) && /slowly/.test(test2),'message: wordBlanks(\"cat\", \"little\", \"hit\", \"slowly\")
should contain all of the passed words.');"
+ ],
"type": "bonfire",
"challengeType": "5",
"nameCn": "",
@@ -1343,11 +1369,6 @@
"Hint",
"
Refer to the example code in the text editor if you get stuck."
],
- "tests": [
- "assert(typeof(myArray) == 'object', 'message: myArray
should be an array
.');",
- "assert(typeof(myArray[0]) !== 'undefined' && typeof(myArray[0]) == 'string', 'message: The first item in myArray
should be a string
.');",
- "assert(typeof(myArray[1]) !== 'undefined' && typeof(myArray[1]) == 'number', 'message: The second item in myArray
should be a number
.');"
- ],
"challengeSeed": [
"// Example",
"var array = [\"John\", 23];",
@@ -1362,6 +1383,11 @@
"solutions": [
"var myArray = [\"The Answer\", 42];"
],
+ "tests": [
+ "assert(typeof(myArray) == 'object', 'message: myArray
should be an array
.');",
+ "assert(typeof(myArray[0]) !== 'undefined' && typeof(myArray[0]) == 'string', 'message: The first item in myArray
should be a string
.');",
+ "assert(typeof(myArray[1]) !== 'undefined' && typeof(myArray[1]) == 'number', 'message: The second item in myArray
should be a number
.');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -1373,9 +1399,6 @@
"Instructions
",
"Create a nested array called myArray
."
],
- "tests": [
- "assert(Array.isArray(myArray) && myArray.some(Array.isArray), 'message: myArray
should have at least one array nested within another array.');"
- ],
"challengeSeed": [
"// Example",
"var ourArray = [[\"the universe\", \"everything\", 42]];",
@@ -1390,6 +1413,9 @@
"solutions": [
"var myArray = [[1,2,3]];"
],
+ "tests": [
+ "assert(Array.isArray(myArray) && myArray.some(Array.isArray), 'message: myArray
should have at least one array nested within another array.');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -1404,9 +1430,6 @@
"Instructions
",
"Create a variable called myData
and set it to equal the first value of myArray
."
],
- "tests": [
- "assert((function(){if(typeof(myArray) != 'undefined' && typeof(myData) != 'undefined' && myArray[0] == myData){return true;}else{return false;}})(), 'message: The variable myData
should equal the first value of myArray
.');"
- ],
"challengeSeed": [
"// Example",
"var ourArray = [1,2,3];",
@@ -1424,6 +1447,9 @@
"solutions": [
"var myArray = [1,2,3];\nvar myData = myArray[0];"
],
+ "tests": [
+ "assert((function(){if(typeof(myArray) != 'undefined' && typeof(myData) != 'undefined' && myArray[0] == myData){return true;}else{return false;}})(), 'message: The variable myData
should equal the first value of myArray
.');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -1437,10 +1463,6 @@
"Instructions
",
"Modify the data stored at index 0
of myArray
to a value of 3
."
],
- "tests": [
- "assert((function(){if(typeof(myArray) != 'undefined' && myArray[0] == 3 && myArray[1] == 2 && myArray[2] == 3){return true;}else{return false;}})(), 'message: myArray
should now be [3,2,3].');",
- "assert((function(){if(code.match(/myArray\\[0\\]\\s?=\\s?/g)){return true;}else{return false;}})(), 'message: You should be using correct index to modify the value in myArray
.');"
- ],
"challengeSeed": [
"// Example",
"var ourArray = [1,2,3];",
@@ -1459,6 +1481,10 @@
"solutions": [
"var myArray = [1,2,3];\nmyArray[0] = 3;"
],
+ "tests": [
+ "assert((function(){if(typeof(myArray) != 'undefined' && myArray[0] == 3 && myArray[1] == 2 && myArray[2] == 3){return true;}else{return false;}})(), 'message: myArray
should now be [3,2,3].');",
+ "assert((function(){if(code.match(/myArray\\[0\\]\\s?=\\s?/g)){return true;}else{return false;}})(), 'message: You should be using correct index to modify the value in myArray
.');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -1473,10 +1499,6 @@
"Read from myArray
using bracket notation so that myData is equal to 8
"
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(myData === 8, 'message: myData
should be equal to 8
.');",
- "assert(/myArray\\[2\\]\\[1\\]/g.test(code), 'message: You should be using bracket notation to read the value from myArray
.');"
- ],
"challengeSeed": [
"// Setup",
"var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]];",
@@ -1491,6 +1513,10 @@
"solutions": [
"var myArray = [[1,2,3],[4,5,6], [7,8,9], [[10,11,12], 13, 14]];\nvar myData = myArray[2][1];"
],
+ "tests": [
+ "assert(myData === 8, 'message: myData
should be equal to 8
.');",
+ "assert(/myArray\\[2\\]\\[1\\]/g.test(code), 'message: You should be using bracket notation to read the value from myArray
.');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -1506,9 +1532,6 @@
"Instructions
",
"Push [\"dog\", 3]
onto the end of the myArray
variable."
],
- "tests": [
- "assert((function(d){if(d[2] != undefined && d[0][0] == 'John' && d[0][1] == 23 && d[2][0] == 'dog' && d[2][1] == 3 && d[2].length == 2){return true;}else{return false;}})(myArray), 'message: myArray
should now equal [[\"John\", 23], [\"cat\", 2], [\"dog\", 3]]
.');"
- ],
"challengeSeed": [
"// Example",
"var ourArray = [\"Stimpson\", \"J\", \"cat\"];",
@@ -1528,6 +1551,9 @@
"solutions": [
"var myArray = [[\"John\", 23], [\"cat\", 2]];\nmyArray.push([\"dog\",3]);"
],
+ "tests": [
+ "assert((function(d){if(d[2] != undefined && d[0][0] == 'John' && d[0][1] == 23 && d[2][0] == 'dog' && d[2][1] == 3 && d[2].length == 2){return true;}else{return false;}})(myArray), 'message: myArray
should now equal [[\"John\", 23], [\"cat\", 2], [\"dog\", 3]]
.');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -1542,10 +1568,6 @@
"Instructions
",
"Use the .pop()
function to remove the last item from myArray
, assigning the \"popped off\" value to removedFromMyArray
."
],
- "tests": [
- "assert((function(d){if(d[0][0] == 'John' && d[0][1] == 23 && d[2] == undefined){return true;}else{return false;}})(myArray), 'message: myArray
should only contain [[\"John\", 23]]
.');",
- "assert((function(d){if(d[0] == 'cat' && d[1] == 2 && d[2] == undefined){return true;}else{return false;}})(removedFromMyArray), 'message: removedFromMyArray
should only contain [\"cat\", 2]
.');"
- ],
"challengeSeed": [
"// Example",
"var ourArray = [1,2,3];",
@@ -1566,6 +1588,10 @@
"solutions": [
"var myArray = [[\"John\", 23], [\"cat\", 2]];\nvar removedFromMyArray = myArray.pop();"
],
+ "tests": [
+ "assert((function(d){if(d[0][0] == 'John' && d[0][1] == 23 && d[2] == undefined){return true;}else{return false;}})(myArray), 'message: myArray
should only contain [[\"John\", 23]]
.');",
+ "assert((function(d){if(d[0] == 'cat' && d[1] == 2 && d[2] == undefined){return true;}else{return false;}})(removedFromMyArray), 'message: removedFromMyArray
should only contain [\"cat\", 2]
.');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -1578,10 +1604,6 @@
"Instructions
",
"Use the .shift()
function to remove the first item from myArray
, assigning the \"shifted off\" value to removedFromMyArray
."
],
- "tests": [
- "assert((function(d){if(d[0][0] == 'dog' && d[0][1] == 3 && d[1] == undefined){return true;}else{return false;}})(myArray), 'message: myArray
should now equal [[\"dog\", 3]]
.');",
- "assert((function(d){if(d[0] === 'John' && d[1] === 23 && typeof(removedFromMyArray) === 'object'){return true;}else{return false;}})(removedFromMyArray), 'message: removedFromMyArray
should contain [\"John\", 23]
.');"
- ],
"challengeSeed": [
"// Example",
"var ourArray = [\"Stimpson\", \"J\", [\"cat\"]];",
@@ -1602,6 +1624,10 @@
"solutions": [
"var myArray = [[\"John\", 23], [\"dog\", 3]];\n\n// Only change code below this line.\nvar removedFromMyArray = myArray.shift();"
],
+ "tests": [
+ "assert((function(d){if(d[0][0] == 'dog' && d[0][1] == 3 && d[1] == undefined){return true;}else{return false;}})(myArray), 'message: myArray
should now equal [[\"dog\", 3]]
.');",
+ "assert((function(d){if(d[0] === 'John' && d[1] === 23 && typeof(removedFromMyArray) === 'object'){return true;}else{return false;}})(removedFromMyArray), 'message: removedFromMyArray
should contain [\"John\", 23]
.');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -1614,9 +1640,6 @@
"Instructions
",
"Add [\"Paul\",35]
to the beginning of the myArray
variable using unshift()
."
],
- "tests": [
- "assert((function(d){if(typeof(d[0]) === \"object\" && d[0][0].toLowerCase() == 'paul' && d[0][1] == 35 && d[1][0] != undefined && d[1][0] == 'dog' && d[1][1] != undefined && d[1][1] == 3){return true;}else{return false;}})(myArray), 'message: myArray
should now have [[\"Paul\", 35], [\"dog\", 3]]).');"
- ],
"challengeSeed": [
"// Example",
"var ourArray = [\"Stimpson\", \"J\", \"cat\"];",
@@ -1638,6 +1661,9 @@
"solutions": [
"var myArray = [[\"John\", 23], [\"dog\", 3]];\nmyArray.shift();\nmyArray.unshift([\"Paul\", 35]);"
],
+ "tests": [
+ "assert((function(d){if(typeof(d[0]) === \"object\" && d[0][0].toLowerCase() == 'paul' && d[0][1] == 35 && d[1][0] != undefined && d[1][0] == 'dog' && d[1][1] != undefined && d[1][1] == 3){return true;}else{return false;}})(myArray), 'message: myArray
should now have [[\"Paul\", 35], [\"dog\", 3]]).');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -1651,12 +1677,6 @@
"There should be at least 5 sub-arrays in the list."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(isArray, 'message: myList
should be an array');",
- "assert(hasString, 'message: The first elements in each of your sub-arrays must all be strings');",
- "assert(hasNumber, 'message: The second elements in each of your sub-arrays must all be numbers');",
- "assert(count > 4, 'message: You must have at least 5 items in your list');"
- ],
"challengeSeed": [
"var myList = [];",
"",
@@ -1689,6 +1709,12 @@
"solutions": [
"var myList = [\n [\"Candy\", 10],\n [\"Potatoes\", 12],\n [\"Eggs\", 12],\n [\"Catfood\", 1],\n [\"Toads\", 9]\n];"
],
+ "tests": [
+ "assert(isArray, 'message: myList
should be an array');",
+ "assert(hasString, 'message: The first elements in each of your sub-arrays must all be strings');",
+ "assert(hasNumber, 'message: The second elements in each of your sub-arrays must all be numbers');",
+ "assert(count > 4, 'message: You must have at least 5 items in your list');"
+ ],
"type": "bonfire",
"challengeType": "5",
"nameCn": "",
@@ -1710,11 +1736,6 @@
"Instructions
",
"- Create a function called
myFunction
which prints \"Hi World\"
to the dev console. - Call the function.
"
],
- "tests": [
- "assert(typeof myFunction === 'function', 'message: myFunction
should be a function');",
- "assert(\"Hi World\" === logOutput, 'message: myFunction
should output \"Hi World\" to the dev console');",
- "assert(/^\\s*myFunction\\(\\)\\s*;/m.test(code), 'message: Call myFunction
after you define it');"
- ],
"challengeSeed": [
"// Example",
"function ourFunction() {",
@@ -1753,6 +1774,11 @@
"solutions": [
"function myFunction() {\n console.log(\"Hi World\");\n}\nmyFunction();"
],
+ "tests": [
+ "assert(typeof myFunction === 'function', 'message: myFunction
should be a function');",
+ "assert(\"Hi World\" === logOutput, 'message: myFunction
should output \"Hi World\" to the dev console');",
+ "assert(/^\\s*myFunction\\(\\)\\s*;/m.test(code), 'message: Call myFunction
after you define it');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -1770,12 +1796,6 @@
"- Create a function called
myFunction
that accepts two arguments and outputs their sum to the dev console. - Call the function.
"
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(typeof myFunction === 'function', 'message: myFunction
should be a function');",
- "capture(); myFunction(1,2); uncapture(); assert(logOutput == 3, 'message: myFunction(1,2)
should output 3
');",
- "capture(); myFunction(7,9); uncapture(); assert(logOutput == 16, 'message: myFunction(7,9)
should output 16
');",
- "assert(/^\\s*myFunction\\(\\s*\\d+\\s*,\\s*\\d+\\s*\\)\\s*;/m.test(code), 'message: Call myFunction
after you define it');"
- ],
"head": [
"var logOutput = \"\";",
"var oldLog = console.log;",
@@ -1813,7 +1833,13 @@
"}"
],
"solutions": [
- ""
+ "function myFunction(a, b) {\n console.log(a + b);\n}\nmyFunction(10, 5);"
+ ],
+ "tests": [
+ "assert(typeof myFunction === 'function', 'message: myFunction
should be a function');",
+ "capture(); myFunction(1,2); uncapture(); assert(logOutput == 3, 'message: myFunction(1,2)
should output 3
');",
+ "capture(); myFunction(7,9); uncapture(); assert(logOutput == 16, 'message: myFunction(7,9)
should output 16
');",
+ "assert(/^\\s*myFunction\\(\\s*\\d+\\s*,\\s*\\d+\\s*\\)\\s*;/m.test(code), 'message: Call myFunction
after you define it');"
],
"type": "waypoint",
"challengeType": "1",
@@ -1834,13 +1860,6 @@
"Inside function fun1
, assign 5
to oopsGlobal
without using the var
keyword."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(typeof myGlobal != \"undefined\", 'message: myGlobal
should be defined');",
- "assert(myGlobal === 10, 'message: myGlobal
should have a value of 10
');",
- "assert(/var\\s+myGlobal/.test(code), 'message: myGlobal
should be declared using the var
keyword');",
- "assert(typeof oopsGlobal != \"undefined\" && oopsGlobal === 5, 'message: oopsGlobal
should have a value of 5
');",
- "assert(!/var\\s+oopsGlobal/.test(code), 'message: Do not decalre oopsGlobal
using the var
keyword');"
- ],
"head": [
"var logOutput = \"\";",
"var oldLog = console.log;",
@@ -1854,7 +1873,7 @@
"function uncapture() {",
" console.log = oldLog;",
"}",
- "",
+ "var oopsGlobal;",
"capture();"
],
"challengeSeed": [
@@ -1885,7 +1904,14 @@
"(function() { return logOutput || \"console.log never called\"; })();"
],
"solutions": [
- ""
+ "// Declare your variable here\nvar myGlobal = 10;\n\nfunction fun1() {\n // Assign 5 to oopsGlobal Here\n oopsGlobal = 5;\n}\n\n// Only change code above this line\nfunction fun2() {\n var output = \"\";\n if(typeof myGlobal != \"undefined\") {\n output += \"myGlobal: \" + myGlobal;\n }\n if(typeof oopsGlobal != \"undefined\") {\n output += \" oopsGlobal: \" + oopsGlobal;\n }\n console.log(output);\n}"
+ ],
+ "tests": [
+ "assert(typeof myGlobal != \"undefined\", 'message: myGlobal
should be defined');",
+ "assert(myGlobal === 10, 'message: myGlobal
should have a value of 10
');",
+ "assert(/var\\s+myGlobal/.test(code), 'message: myGlobal
should be declared using the var
keyword');",
+ "assert(typeof oopsGlobal != \"undefined\" && oopsGlobal === 5, 'message: oopsGlobal
should have a value of 5
');",
+ "assert(!/var\\s+oopsGlobal/.test(code), 'message: Do not decalre oopsGlobal
using the var
keyword');"
],
"type": "waypoint",
"challengeType": "1",
@@ -1907,9 +1933,6 @@
"Declare a local variable myVar
inside myFunction
"
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(code.match(/console\\.log/gi).length === 1, 'message: Remove the second console log');"
- ],
"challengeSeed": [
"function myFunction() {",
" ",
@@ -1930,6 +1953,9 @@
"solutions": [
"function myFunction() {\n var myVar;\n console.log(myVar);\n}\nmyFunction();"
],
+ "tests": [
+ "assert(code.match(/console\\.log/gi).length === 1, 'message: Remove the second console log');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -1950,11 +1976,6 @@
"Add a local variable to myFunction
to override the value of outerWear
with \"sweater\"
."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(outerWear === \"T-Shirt\", 'message: Do not change the value of the global outerWear
');",
- "assert(myFunction() === \"sweater\", 'message: myFunction
should return \"sweater\"
');",
- "assert(/return outerWear/.test(code), 'message: Do not change the return statement');"
- ],
"challengeSeed": [
"// Setup",
"var outerWear = \"T-Shirt\";",
@@ -1973,6 +1994,11 @@
"solutions": [
"var outerWear = \"T-Shirt\";\nfunction myFunction() {\n var outerWear = \"sweater\";\n return outerWear;\n}"
],
+ "tests": [
+ "assert(outerWear === \"T-Shirt\", 'message: Do not change the value of the global outerWear
');",
+ "assert(myFunction() === \"sweater\", 'message: myFunction
should return \"sweater\"
');",
+ "assert(/return outerWear/.test(code), 'message: Do not change the return statement');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -1993,12 +2019,6 @@
"Create a function timesFive
that accepts one argument, multiplies it by 5
, and returns the new value."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(typeof timesFive === 'function', 'message: timesFive
should be a function');",
- "assert(timesFive(5) === 25, 'message: timesFive(5)
should return 25
');",
- "assert(timesFive(2) === 10, 'message: timesFive(2)
should return 10
');",
- "assert(timesFive(0) === 0, 'message: timesFive(0)
should return 0
');"
- ],
"challengeSeed": [
"// Example",
"function minusSeven(num) {",
@@ -2015,6 +2035,12 @@
"solutions": [
"function timesFive(num) {\n return num * 5;\n}"
],
+ "tests": [
+ "assert(typeof timesFive === 'function', 'message: timesFive
should be a function');",
+ "assert(timesFive(5) === 25, 'message: timesFive(5)
should return 25
');",
+ "assert(timesFive(2) === 10, 'message: timesFive(2)
should return 10
');",
+ "assert(timesFive(0) === 0, 'message: timesFive(0)
should return 0
');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -2035,10 +2061,6 @@
"Call the process
function with an argument of 7
and assign its return value to the variable processed
."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(processed === 2, 'message: processed
should have a value of 2
');",
- "assert(/processed\\s*=\\s*process\\(\\s*7\\s*\\)\\s*;/.test(code), 'message: You should assign process
to processed
');"
- ],
"challengeSeed": [
"// Setup",
"var processed = 0;",
@@ -2057,6 +2079,10 @@
"solutions": [
"var processed = 0;\n\nfunction process(num) {\n return (num + 3) / 5;\n}\n\nprocessed = process(7);"
],
+ "tests": [
+ "assert(processed === 2, 'message: processed
should have a value of 2
');",
+ "assert(/processed\\s*=\\s*process\\(\\s*7\\s*\\)\\s*;/.test(code), 'message: You should assign process
to processed
');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -2073,11 +2099,6 @@
"Write a function queue
which takes an \"array\" and an \"item\" as arguments. Add the item onto the end of the array, then remove and return the item at the front of the queue."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(queue([],1) === 1, 'message: queue([], 1)
should return 1
');",
- "assert(queue([2],1) === 2, 'message: queue([2], 1)
should return 2
');",
- "queue(myArr, 10); assert(myArr[4] === 10, 'message: After queue(myArr, 10)
, myArr[4]
should be 10
');"
- ],
"head": [
"var logOutput = [];",
"var oldLog = console.log;",
@@ -2117,6 +2138,11 @@
"solutions": [
"var myArr = [ 1,2,3,4,5];\n\nfunction queue(myArr, item) {\n myArr.push(item);\n return myArr.shift();\n}"
],
+ "tests": [
+ "assert(queue([],1) === 1, 'message: queue([], 1)
should return 1
');",
+ "assert(queue([2],1) === 2, 'message: queue([2], 1)
should return 2
');",
+ "queue(myArr, 10); assert(myArr[4] === 10, 'message: After queue(myArr, 10)
, myArr[4]
should be 10
');"
+ ],
"type": "bonfire",
"challengeType": "5",
"nameCn": "",
@@ -2137,14 +2163,6 @@
"Instructions
",
"Create an if
statement inside the function to return \"Yes\"
if testMe
is greater than 5
. Return \"No\"
if it is less than or equal to 5
."
],
- "tests": [
- "assert(typeof myFunction === \"function\", 'message: myFunction
should be a function');",
- "assert(typeof myFunction(4) === \"string\", 'message: myFunction(4)
should return a string');",
- "assert(typeof myFunction(6) === \"string\", 'message: myFunction(6)
should return a string');",
- "assert(myFunction(4) === \"No\", 'message: myFunction(4)
should \"No\"');",
- "assert(myFunction(5) === \"No\", 'message: myFunction(5)
should \"No\"');",
- "assert(myFunction(6) === \"Yes\", 'message: myFunction(6)
should \"Yes\"');"
- ],
"challengeSeed": [
"// Example",
"function ourFunction(testMe) {",
@@ -2171,6 +2189,14 @@
"solutions": [
"function myFunction(testMe) {\n if (testMe > 5) {\n return 'Yes';\n }\n return 'No';\n}"
],
+ "tests": [
+ "assert(typeof myFunction === \"function\", 'message: myFunction
should be a function');",
+ "assert(typeof myFunction(4) === \"string\", 'message: myFunction(4)
should return a string');",
+ "assert(typeof myFunction(6) === \"string\", 'message: myFunction(6)
should return a string');",
+ "assert(myFunction(4) === \"No\", 'message: myFunction(4)
should \"No\"');",
+ "assert(myFunction(5) === \"No\", 'message: myFunction(5)
should \"No\"');",
+ "assert(myFunction(6) === \"Yes\", 'message: myFunction(6)
should \"Yes\"');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -2188,12 +2214,6 @@
"Add the equality operator
to the indicated line so that the function will return \"Equal\" when val
is equivalent to 12
"
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(myTest(10) === \"Not Equal\", 'message: myTest(10)
should return \"Not Equal\"');",
- "assert(myTest(12) === \"Equal\", 'message: myTest(12)
should return \"Equal\"');",
- "assert(myTest(\"12\") === \"Equal\", 'message: myTest(\"12\")
should return \"Equal\"');",
- "assert(code.match(/val\\s*==\\s*\\d+/g).length > 0, 'message: You should use the ==
operator');"
- ],
"challengeSeed": [
"// Setup",
"function myTest(val) {",
@@ -2209,6 +2229,12 @@
"solutions": [
"function myTest(val) {\n if (val == 12) {\n return \"Equal\";\n }\n return \"Not Equal\";\n}"
],
+ "tests": [
+ "assert(myTest(10) === \"Not Equal\", 'message: myTest(10)
should return \"Not Equal\"');",
+ "assert(myTest(12) === \"Equal\", 'message: myTest(12)
should return \"Equal\"');",
+ "assert(myTest(\"12\") === \"Equal\", 'message: myTest(\"12\")
should return \"Equal\"');",
+ "assert(code.match(/val\\s*==\\s*\\d+/g).length > 0, 'message: You should use the ==
operator');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -2229,12 +2255,6 @@
"Use strict equality operator in if
statement so the function will return \"Equal\" when val
is strictly equal to 7
"
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(myTest(10) === \"Not Equal\", 'message: myTest(10)
should return \"Not Equal\"');",
- "assert(myTest(7) === \"Equal\", 'message: myTest(7)
should return \"Equal\"');",
- "assert(myTest(\"7\") === \"Not Equal\", 'message: myTest(\"7\")
should return \"Not Equal\"');",
- "assert(code.match(/val\\s*===\\s*\\d+/g).length > 0, 'message: You should use the ===
operator');"
- ],
"challengeSeed": [
"// Setup",
"function myTest(val) {",
@@ -2250,6 +2270,12 @@
"solutions": [
"function myTest(val) {\n if (val === 7) {\n return \"Equal\";\n }\n return \"Not Equal\";\n}"
],
+ "tests": [
+ "assert(myTest(10) === \"Not Equal\", 'message: myTest(10)
should return \"Not Equal\"');",
+ "assert(myTest(7) === \"Equal\", 'message: myTest(7)
should return \"Equal\"');",
+ "assert(myTest(\"7\") === \"Not Equal\", 'message: myTest(\"7\")
should return \"Not Equal\"');",
+ "assert(code.match(/val\\s*===\\s*\\d+/g).length > 0, 'message: You should use the ===
operator');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -2269,14 +2295,6 @@
"Add the inequality operator !=
in the if
statement so that the function will return \"Not Equal\" when val
is not equivalent to 99
"
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(myTest(99) === \"Equal\", 'message: myTest(99)
should return \"Equal\"');",
- "assert(myTest(\"99\") === \"Equal\", 'message: myTest(\"99\")
should return \"Equal\"');",
- "assert(myTest(12) === \"Not Equal\", 'message: myTest(12)
should return \"Not Equal\"');",
- "assert(myTest(\"12\") === \"Not Equal\", 'message: myTest(\"12\")
should return \"Not Equal\"');",
- "assert(myTest(\"bob\") === \"Not Equal\", 'message: myTest(\"bob\")
should return \"Not Equal\"');",
- "assert(code.match(/val\\s*!=\\s*\\d+/g).length > 0, 'message: You should use the !=
operator');"
- ],
"challengeSeed": [
"// Setup",
"function myTest(val) {",
@@ -2292,6 +2310,14 @@
"solutions": [
"function myTest(val) {\n if (val != 99) {\n return \"Not Equal\";\n }\n return \"Equal\";\n}"
],
+ "tests": [
+ "assert(myTest(99) === \"Equal\", 'message: myTest(99)
should return \"Equal\"');",
+ "assert(myTest(\"99\") === \"Equal\", 'message: myTest(\"99\")
should return \"Equal\"');",
+ "assert(myTest(12) === \"Not Equal\", 'message: myTest(12)
should return \"Not Equal\"');",
+ "assert(myTest(\"12\") === \"Not Equal\", 'message: myTest(\"12\")
should return \"Not Equal\"');",
+ "assert(myTest(\"bob\") === \"Not Equal\", 'message: myTest(\"bob\")
should return \"Not Equal\"');",
+ "assert(code.match(/val\\s*!=\\s*\\d+/g).length > 0, 'message: You should use the !=
operator');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -2311,13 +2337,6 @@
"Add the strict inequality operator
to the if
statement so the function will return \"Not Equal\" when val
is not strictly equal to 17
"
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(myTest(17) === \"Equal\", 'message: myTest(17)
should return \"Equal\"');",
- "assert(myTest(\"17\") === \"Not Equal\", 'message: myTest(\"17\")
should return \"Not Equal\"');",
- "assert(myTest(12) === \"Not Equal\", 'message: myTest(12)
should return \"Not Equal\"');",
- "assert(myTest(\"bob\") === \"Not Equal\", 'message: myTest(\"bob\")
should return \"Not Equal\"');",
- "assert(code.match(/val\\s*!==\\s*\\d+/g).length > 0, 'message: You should use the !==
operator');"
- ],
"challengeSeed": [
"// Setup",
"function myTest(val) {",
@@ -2338,6 +2357,13 @@
"solutions": [
"function myTest(val) {\n if (val !== 17) {\n return \"Not Equal\";\n }\n return \"Equal\";\n}"
],
+ "tests": [
+ "assert(myTest(17) === \"Equal\", 'message: myTest(17)
should return \"Equal\"');",
+ "assert(myTest(\"17\") === \"Not Equal\", 'message: myTest(\"17\")
should return \"Not Equal\"');",
+ "assert(myTest(12) === \"Not Equal\", 'message: myTest(12)
should return \"Not Equal\"');",
+ "assert(myTest(\"bob\") === \"Not Equal\", 'message: myTest(\"bob\")
should return \"Not Equal\"');",
+ "assert(code.match(/val\\s*!==\\s*\\d+/g).length > 0, 'message: You should use the !==
operator');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -2357,16 +2383,6 @@
"Add the greater than
operator to the indicated lines so that the return statements make sense."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(myTest(0) === \"10 or Under\", 'message: myTest(0)
should return \"10 or Under\"');",
- "assert(myTest(10) === \"10 or Under\", 'message: myTest(10)
should return \"10 or Under\"');",
- "assert(myTest(11) === \"Over 10\", 'message: myTest(11)
should return \"Over 10\"');",
- "assert(myTest(99) === \"Over 10\", 'message: myTest(99)
should return \"Over 10\"');",
- "assert(myTest(100) === \"Over 10\", 'message: myTest(100)
should return \"Over 10\"');",
- "assert(myTest(101) === \"Over 100\", 'message: myTest(101)
should return \"Over 100\"');",
- "assert(myTest(150) === \"Over 100\", 'message: myTest(150)
should return \"Over 100\"');",
- "assert(code.match(/val\\s*>\\s*\\d+/g).length > 1, 'message: You should use the >
operator at least twice');"
- ],
"challengeSeed": [
"function myTest(val) {",
" if (val) { // Change this line",
@@ -2386,6 +2402,16 @@
"solutions": [
"function myTest(val) {\n if (val > 100) { // Change this line\n return \"Over 100\";\n }\n if (val > 10) { // Change this line\n return \"Over 10\";\n }\n return \"10 or Under\";\n}"
],
+ "tests": [
+ "assert(myTest(0) === \"10 or Under\", 'message: myTest(0)
should return \"10 or Under\"');",
+ "assert(myTest(10) === \"10 or Under\", 'message: myTest(10)
should return \"10 or Under\"');",
+ "assert(myTest(11) === \"Over 10\", 'message: myTest(11)
should return \"Over 10\"');",
+ "assert(myTest(99) === \"Over 10\", 'message: myTest(99)
should return \"Over 10\"');",
+ "assert(myTest(100) === \"Over 10\", 'message: myTest(100)
should return \"Over 10\"');",
+ "assert(myTest(101) === \"Over 100\", 'message: myTest(101)
should return \"Over 100\"');",
+ "assert(myTest(150) === \"Over 100\", 'message: myTest(150)
should return \"Over 100\"');",
+ "assert(code.match(/val\\s*>\\s*\\d+/g).length > 1, 'message: You should use the >
operator at least twice');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -2405,16 +2431,6 @@
"Add the greater than equal to
operator to the indicated lines so that the return statements make sense."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(myTest(0) === \"9 or Under\", 'message: myTest(0)
should return \"9 or Under\"');",
- "assert(myTest(9) === \"9 or Under\", 'message: myTest(9)
should return \"9 or Under\"');",
- "assert(myTest(10) === \"10 or Over\", 'message: myTest(10)
should return \"10 or Over\"');",
- "assert(myTest(11) === \"10 or Over\", 'message: myTest(10)
should return \"10 or Over\"');",
- "assert(myTest(19) === \"10 or Over\", 'message: myTest(19)
should return \"10 or Over\"');",
- "assert(myTest(20) === \"20 or Over\", 'message: myTest(100)
should return \"20 or Over\"');",
- "assert(myTest(21) === \"20 or Over\", 'message: myTest(101)
should return \"20 or Over\"');",
- "assert(code.match(/val\\s*>=\\s*\\d+/g).length > 1, 'message: You should use the >=
operator at least twice');"
- ],
"challengeSeed": [
"function myTest(val) {",
" if (val) { // Change this line",
@@ -2434,6 +2450,16 @@
"solutions": [
"function myTest(val) {\n if (val >= 20) { // Change this line\n return \"20 or Over\";\n }\n \n if (val >= 10) { // Change this line\n return \"10 or Over\";\n }\n\n return \"9 or Under\";\n}"
],
+ "tests": [
+ "assert(myTest(0) === \"9 or Under\", 'message: myTest(0)
should return \"9 or Under\"');",
+ "assert(myTest(9) === \"9 or Under\", 'message: myTest(9)
should return \"9 or Under\"');",
+ "assert(myTest(10) === \"10 or Over\", 'message: myTest(10)
should return \"10 or Over\"');",
+ "assert(myTest(11) === \"10 or Over\", 'message: myTest(10)
should return \"10 or Over\"');",
+ "assert(myTest(19) === \"10 or Over\", 'message: myTest(19)
should return \"10 or Over\"');",
+ "assert(myTest(20) === \"20 or Over\", 'message: myTest(100)
should return \"20 or Over\"');",
+ "assert(myTest(21) === \"20 or Over\", 'message: myTest(101)
should return \"20 or Over\"');",
+ "assert(code.match(/val\\s*>=\\s*\\d+/g).length > 1, 'message: You should use the >=
operator at least twice');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -2453,15 +2479,6 @@
"Add the less than
operator to the indicated lines so that the return statements make sense."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(myTest(0) === \"Under 25\", 'message: myTest(0)
should return \"Under 25\"');",
- "assert(myTest(24) === \"Under 25\", 'message: myTest(24)
should return \"Under 25\"');",
- "assert(myTest(25) === \"Under 55\", 'message: myTest(25)
should return \"Under 55\"');",
- "assert(myTest(54) === \"Under 55\", 'message: myTest(54)
should return \"Under 55\"');",
- "assert(myTest(55) === \"55 or Over\", 'message: myTest(55)
should return \"55 or Over\"');",
- "assert(myTest(99) === \"55 or Over\", 'message: myTest(99)
should return \"55 or Over\"');",
- "assert(code.match(/val\\s*<\\s*\\d+/g).length > 1, 'message: You should use the <
operator at least twice');"
- ],
"challengeSeed": [
"function myTest(val) {",
" if (val) { // Change this line",
@@ -2481,6 +2498,15 @@
"solutions": [
"function myTest(val) {\n if (val < 25) { // Change this line\n return \"Under 25\";\n }\n \n if (val < 55) { // Change this line\n return \"Under 55\";\n }\n\n return \"55 or Over\";\n}"
],
+ "tests": [
+ "assert(myTest(0) === \"Under 25\", 'message: myTest(0)
should return \"Under 25\"');",
+ "assert(myTest(24) === \"Under 25\", 'message: myTest(24)
should return \"Under 25\"');",
+ "assert(myTest(25) === \"Under 55\", 'message: myTest(25)
should return \"Under 55\"');",
+ "assert(myTest(54) === \"Under 55\", 'message: myTest(54)
should return \"Under 55\"');",
+ "assert(myTest(55) === \"55 or Over\", 'message: myTest(55)
should return \"55 or Over\"');",
+ "assert(myTest(99) === \"55 or Over\", 'message: myTest(99)
should return \"55 or Over\"');",
+ "assert(code.match(/val\\s*<\\s*\\d+/g).length > 1, 'message: You should use the <
operator at least twice');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -2500,16 +2526,6 @@
"Add the less than equal to
operator to the indicated lines so that the return statements make sense."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(myTest(0) === \"Smaller Than or Equal to 12\", 'message: myTest(0)
should return \"Smaller Than or Equal to 12\"');",
- "assert(myTest(11) === \"Smaller Than or Equal to 12\", 'message: myTest(11)
should return \"Smaller Than or Equal to 12\"');",
- "assert(myTest(12) === \"Smaller Than or Equal to 12\", 'message: myTest(12)
should return \"Smaller Than or Equal to 12\"');",
- "assert(myTest(23) === \"Smaller Than or Equal to 24\", 'message: myTest(23)
should return \"Smaller Than or Equal to 24\"');",
- "assert(myTest(24) === \"Smaller Than or Equal to 24\", 'message: myTest(24)
should return \"Smaller Than or Equal to 24\"');",
- "assert(myTest(25) === \"25 or More\", 'message: myTest(25)
should return \"25 or More\"');",
- "assert(myTest(55) === \"25 or More\", 'message: myTest(55)
should return \"25 or More\"');",
- "assert(code.match(/val\\s*<=\\s*\\d+/g).length > 1, 'message: You should use the <=
operator at least twice');"
- ],
"challengeSeed": [
"function myTest(val) {",
" if (val) { // Change this line",
@@ -2530,6 +2546,16 @@
"solutions": [
"function myTest(val) {\n if (val <= 12) { // Change this line\n return \"Smaller Than or Equal to 12\";\n }\n \n if (val <= 24) { // Change this line\n return \"Smaller Than or Equal to 24\";\n }\n\n return \"25 or More\";\n}"
],
+ "tests": [
+ "assert(myTest(0) === \"Smaller Than or Equal to 12\", 'message: myTest(0)
should return \"Smaller Than or Equal to 12\"');",
+ "assert(myTest(11) === \"Smaller Than or Equal to 12\", 'message: myTest(11)
should return \"Smaller Than or Equal to 12\"');",
+ "assert(myTest(12) === \"Smaller Than or Equal to 12\", 'message: myTest(12)
should return \"Smaller Than or Equal to 12\"');",
+ "assert(myTest(23) === \"Smaller Than or Equal to 24\", 'message: myTest(23)
should return \"Smaller Than or Equal to 24\"');",
+ "assert(myTest(24) === \"Smaller Than or Equal to 24\", 'message: myTest(24)
should return \"Smaller Than or Equal to 24\"');",
+ "assert(myTest(25) === \"25 or More\", 'message: myTest(25)
should return \"25 or More\"');",
+ "assert(myTest(55) === \"25 or More\", 'message: myTest(55)
should return \"25 or More\"');",
+ "assert(code.match(/val\\s*<=\\s*\\d+/g).length > 1, 'message: You should use the <=
operator at least twice');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -2551,18 +2577,6 @@
"Combine the two if statements into one statement which will return \"Yes\"
if val
is less than or equal to 50
and greater than or equal to 25
. Otherwise, will return \"No\"
."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(code.match(/&&/g).length === 1, 'message: You should use the &&
operator once');",
- "assert(code.match(/if/g).length === 1, 'message: You should only have one if
statement');",
- "assert(myTest(0) === \"No\", 'message: myTest(0)
should return \"No\"');",
- "assert(myTest(24) === \"No\", 'message: myTest(24)
should return \"No\"');",
- "assert(myTest(25) === \"Yes\", 'message: myTest(25)
should return \"Yes\"');",
- "assert(myTest(49) === \"Yes\", 'message: myTest(30)
should return \"Yes\"');",
- "assert(myTest(50) === \"Yes\", 'message: myTest(50)
should return \"Yes\"');",
- "assert(myTest(51) === \"No\", 'message: myTest(51)
should return \"No\"');",
- "assert(myTest(75) === \"No\", 'message: myTest(75)
should return \"No\"');",
- "assert(myTest(51) === \"No\", 'message: myTest(51)
should return \"No\"');"
- ],
"challengeSeed": [
"function myTest(val) {",
" // Only change code below this line",
@@ -2583,6 +2597,18 @@
"solutions": [
"function myTest(val) {\n if (val >= 25 && val <= 50) {\n return \"Yes\";\n }\n return \"No\";\n}"
],
+ "tests": [
+ "assert(code.match(/&&/g).length === 1, 'message: You should use the &&
operator once');",
+ "assert(code.match(/if/g).length === 1, 'message: You should only have one if
statement');",
+ "assert(myTest(0) === \"No\", 'message: myTest(0)
should return \"No\"');",
+ "assert(myTest(24) === \"No\", 'message: myTest(24)
should return \"No\"');",
+ "assert(myTest(25) === \"Yes\", 'message: myTest(25)
should return \"Yes\"');",
+ "assert(myTest(49) === \"Yes\", 'message: myTest(30)
should return \"Yes\"');",
+ "assert(myTest(50) === \"Yes\", 'message: myTest(50)
should return \"Yes\"');",
+ "assert(myTest(51) === \"No\", 'message: myTest(51)
should return \"No\"');",
+ "assert(myTest(75) === \"No\", 'message: myTest(75)
should return \"No\"');",
+ "assert(myTest(51) === \"No\", 'message: myTest(51)
should return \"No\"');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -2604,18 +2630,6 @@
"Combine the two if
statements into one statement which returns \"Inside\"
if val
is between 10
and 20
, inclusive. Otherwise, return \"Outside\"
."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(code.match(/\\|\\|/g).length === 1, 'message: You should use the ||
operator once');",
- "assert(code.match(/if/g).length === 1, 'message: You should only have one if
statement');",
- "assert(myTest(0) === \"Outside\", 'message: myTest(0)
should return \"Outside\"');",
- "assert(myTest(9) === \"Outside\", 'message: myTest(9)
should return \"Outside\"');",
- "assert(myTest(10) === \"Inside\", 'message: myTest(10)
should return \"Inside\"');",
- "assert(myTest(15) === \"Inside\", 'message: myTest(15)
should return \"Inside\"');",
- "assert(myTest(19) === \"Inside\", 'message: myTest(19)
should return \"Inside\"');",
- "assert(myTest(20) === \"Inside\", 'message: myTest(20)
should return \"Inside\"');",
- "assert(myTest(21) === \"Outside\", 'message: myTest(21)
should return \"Outside\"');",
- "assert(myTest(25) === \"Outside\", 'message: myTest(25)
should return \"Outside\"');"
- ],
"challengeSeed": [
"function myTest(val) {",
" // Only change code below this line",
@@ -2638,6 +2652,18 @@
"solutions": [
"function myTest(val) {\n if (val < 10 || val > 20) {\n return \"Outside\";\n }\n return \"Inside\";\n}"
],
+ "tests": [
+ "assert(code.match(/\\|\\|/g).length === 1, 'message: You should use the ||
operator once');",
+ "assert(code.match(/if/g).length === 1, 'message: You should only have one if
statement');",
+ "assert(myTest(0) === \"Outside\", 'message: myTest(0)
should return \"Outside\"');",
+ "assert(myTest(9) === \"Outside\", 'message: myTest(9)
should return \"Outside\"');",
+ "assert(myTest(10) === \"Inside\", 'message: myTest(10)
should return \"Inside\"');",
+ "assert(myTest(15) === \"Inside\", 'message: myTest(15)
should return \"Inside\"');",
+ "assert(myTest(19) === \"Inside\", 'message: myTest(19)
should return \"Inside\"');",
+ "assert(myTest(20) === \"Inside\", 'message: myTest(20)
should return \"Inside\"');",
+ "assert(myTest(21) === \"Outside\", 'message: myTest(21)
should return \"Outside\"');",
+ "assert(myTest(25) === \"Outside\", 'message: myTest(25)
should return \"Outside\"');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -2656,15 +2682,6 @@
"Combine the if
statements into a single statement."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(code.match(/if/g).length === 1, 'message: You should only have one if
statement');",
- "assert(/else/g.test(code), 'message: You should use an else
statement');",
- "assert(myTest(4) === \"5 or Smaller\", 'message: myTest(4)
should return \"5 or Smaller\"');",
- "assert(myTest(5) === \"5 or Smaller\", 'message: myTest(5)
should return \"5 or Smaller\"');",
- "assert(myTest(6) === \"Bigger than 5\", 'message: myTest(6)
should return \"Bigger than 5\"');",
- "assert(myTest(10) === \"Bigger than 5\", 'message: myTest(10)
should return \"Bigger than 5\"');",
- "assert(/var result = \"\";/.test(code) && /return result;/.test(code), 'message: Do not change the code above or below the lines.');"
- ],
"challengeSeed": [
"function myTest(val) {",
" var result = \"\";",
@@ -2689,6 +2706,15 @@
"solutions": [
"function myTest(val) {\n var result = \"\";\n if(val > 5) {\n result = \"Bigger than 5\";\n } else {\n result = \"5 or Smaller\";\n }\n return result;\n}"
],
+ "tests": [
+ "assert(code.match(/if/g).length === 1, 'message: You should only have one if
statement');",
+ "assert(/else/g.test(code), 'message: You should use an else
statement');",
+ "assert(myTest(4) === \"5 or Smaller\", 'message: myTest(4)
should return \"5 or Smaller\"');",
+ "assert(myTest(5) === \"5 or Smaller\", 'message: myTest(5)
should return \"5 or Smaller\"');",
+ "assert(myTest(6) === \"Bigger than 5\", 'message: myTest(6)
should return \"Bigger than 5\"');",
+ "assert(myTest(10) === \"Bigger than 5\", 'message: myTest(10)
should return \"Bigger than 5\"');",
+ "assert(/var result = \"\";/.test(code) && /return result;/.test(code), 'message: Do not change the code above or below the lines.');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -2707,15 +2733,6 @@
"Convert the logic to use else if
statements."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(code.match(/else/g).length > 1, 'message: You should have at least two else
statements');",
- "assert(code.match(/if/g).length > 1, 'message: You should have at least two if
statements');",
- "assert(myTest(0) === \"Smaller than 5\", 'message: myTest(4)
should return \"Smaller than 5\"');",
- "assert(myTest(5) === \"Between 5 and 10\", 'message: myTest(5)
should return \"Smaller than 5\"');",
- "assert(myTest(7) === \"Between 5 and 10\", 'message: myTest(7)
should return \"Between 5 and 10\"');",
- "assert(myTest(10) === \"Between 5 and 10\", 'message: myTest(10)
should return \"Between 5 and 10\"');",
- "assert(myTest(12) === \"10 or Bigger\", 'message: myTest(12)
should return \"10 or Bigger\"');"
- ],
"challengeSeed": [
"function myTest(val) {",
" if(val > 10) {",
@@ -2736,6 +2753,15 @@
"solutions": [
"function myTest(val) {\n if(val > 10) {\n return \"10 or Bigger\";\n } else if(val < 5) {\n return \"Smaller than 5\";\n } else {\n return \"Between 5 and 10\";\n }\n}"
],
+ "tests": [
+ "assert(code.match(/else/g).length > 1, 'message: You should have at least two else
statements');",
+ "assert(code.match(/if/g).length > 1, 'message: You should have at least two if
statements');",
+ "assert(myTest(0) === \"Smaller than 5\", 'message: myTest(4)
should return \"Smaller than 5\"');",
+ "assert(myTest(5) === \"Between 5 and 10\", 'message: myTest(5)
should return \"Smaller than 5\"');",
+ "assert(myTest(7) === \"Between 5 and 10\", 'message: myTest(7)
should return \"Between 5 and 10\"');",
+ "assert(myTest(10) === \"Between 5 and 10\", 'message: myTest(10)
should return \"Between 5 and 10\"');",
+ "assert(myTest(12) === \"10 or Bigger\", 'message: myTest(12)
should return \"10 or Bigger\"');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -2755,21 +2781,6 @@
"num < 5
- return \"Tiny\"
num < 10
- return \"Small\"
num < 15
- return \"Medium\"
num < 20
- return \"Large\"
num >= 20
- return \"Huge\""
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(code.match(/else/g).length > 3, 'message: You should have at least four else
statements');",
- "assert(code.match(/if/g).length > 3, 'message: You should have at least four if
statements');",
- "assert(code.match(/return/g).length === 5, 'message: You should have five return
statements');",
- "assert(myTest(0) === \"Tiny\", 'message: myTest(0)
should return \"Tiny\"');",
- "assert(myTest(4) === \"Tiny\", 'message: myTest(4)
should return \"Tiny\"');",
- "assert(myTest(5) === \"Small\", 'message: myTest(5)
should return \"Small\"');",
- "assert(myTest(8) === \"Small\", 'message: myTest(8)
should return \"Small\"');",
- "assert(myTest(10) === \"Medium\", 'message: myTest(10)
should return \"Medium\"');",
- "assert(myTest(14) === \"Medium\", 'message: myTest(14)
should return \"Medium\"');",
- "assert(myTest(15) === \"Large\", 'message: myTest(15)
should return \"Large\"');",
- "assert(myTest(17) === \"Large\", 'message: myTest(17)
should return \"Large\"');",
- "assert(myTest(20) === \"Huge\", 'message: myTest(20)
should return \"Huge\"');",
- "assert(myTest(25) === \"Huge\", 'message: myTest(25)
should return \"Huge\"');"
- ],
"challengeSeed": [
"function myTest(num) {",
" // Only change code below this line",
@@ -2785,6 +2796,21 @@
"solutions": [
"function myTest(num) {\n if (num < 5) {\n return \"Tiny\";\n } else if (num < 10) {\n return \"Small\";\n } else if (num < 15) {\n return \"Medium\";\n } else if (num < 20) {\n return \"Large\";\n } else {\n return \"Huge\";\n }\n}"
],
+ "tests": [
+ "assert(code.match(/else/g).length > 3, 'message: You should have at least four else
statements');",
+ "assert(code.match(/if/g).length > 3, 'message: You should have at least four if
statements');",
+ "assert(code.match(/return/g).length === 5, 'message: You should have five return
statements');",
+ "assert(myTest(0) === \"Tiny\", 'message: myTest(0)
should return \"Tiny\"');",
+ "assert(myTest(4) === \"Tiny\", 'message: myTest(4)
should return \"Tiny\"');",
+ "assert(myTest(5) === \"Small\", 'message: myTest(5)
should return \"Small\"');",
+ "assert(myTest(8) === \"Small\", 'message: myTest(8)
should return \"Small\"');",
+ "assert(myTest(10) === \"Medium\", 'message: myTest(10)
should return \"Medium\"');",
+ "assert(myTest(14) === \"Medium\", 'message: myTest(14)
should return \"Medium\"');",
+ "assert(myTest(15) === \"Large\", 'message: myTest(15)
should return \"Large\"');",
+ "assert(myTest(17) === \"Large\", 'message: myTest(17)
should return \"Large\"');",
+ "assert(myTest(20) === \"Huge\", 'message: myTest(20)
should return \"Huge\"');",
+ "assert(myTest(25) === \"Huge\", 'message: myTest(25)
should return \"Huge\"');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -2803,19 +2829,6 @@
"par
and strokes
will always be numeric and positive."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(golfScore(4, 1) === \"Hole-in-one!\", 'message: golfScore(4, 1)
should return \"Hole-in-one!\"');",
- "assert(golfScore(4, 2) === \"Eagle\", 'message: golfScore(4, 2)
should return \"Eagle\"');",
- "assert(golfScore(5, 2) === \"Eagle\", 'message: golfScore(5, 2)
should return \"Eagle\"');",
- "assert(golfScore(4, 3) === \"Birdie\", 'message: golfScore(4, 3)
should return \"Birdie\"');",
- "assert(golfScore(4, 4) === \"Par\", 'message: golfScore(4, 4)
should return \"Par\"');",
- "assert(golfScore(1, 1) === \"Hole-in-one!\", 'message: golfScore(1, 1)
should return \"Hole-in-one!\"');",
- "assert(golfScore(5, 5) === \"Par\", 'message: golfScore(5, 5)
should return \"Par\"');",
- "assert(golfScore(4, 5) === \"Bogey\", 'message: golfScore(4, 5)
should return \"Bogey\"');",
- "assert(golfScore(4, 6) === \"Double Bogey\", 'message: golfScore(4, 6)
should return \"Double Bogey\"');",
- "assert(golfScore(4, 7) === \"Go Home!\", 'message: golfScore(4, 7)
should return \"Go Home!\"');",
- "assert(golfScore(5, 9) === \"Go Home!\", 'message: golfScore(5, 9)
should return \"Go Home!\"');"
- ],
"challengeSeed": [
"function golfScore(par, strokes) {",
" // Only change code below this line",
@@ -2831,6 +2844,19 @@
"solutions": [
"function golfScore(par, strokes) {\n if (strokes === 1) {\n return \"Hole-in-one!\";\n }\n \n if (strokes <= par - 2) {\n return \"Eagle\";\n }\n \n if (strokes === par - 1) {\n return \"Birdie\";\n }\n \n if (strokes === par) {\n return \"Par\";\n }\n \n if (strokes === par + 1) {\n return \"Bogey\";\n }\n \n if(strokes === par + 2) {\n return \"Double Bogey\";\n }\n \n return \"Go Home!\";\n}"
],
+ "tests": [
+ "assert(golfScore(4, 1) === \"Hole-in-one!\", 'message: golfScore(4, 1)
should return \"Hole-in-one!\"');",
+ "assert(golfScore(4, 2) === \"Eagle\", 'message: golfScore(4, 2)
should return \"Eagle\"');",
+ "assert(golfScore(5, 2) === \"Eagle\", 'message: golfScore(5, 2)
should return \"Eagle\"');",
+ "assert(golfScore(4, 3) === \"Birdie\", 'message: golfScore(4, 3)
should return \"Birdie\"');",
+ "assert(golfScore(4, 4) === \"Par\", 'message: golfScore(4, 4)
should return \"Par\"');",
+ "assert(golfScore(1, 1) === \"Hole-in-one!\", 'message: golfScore(1, 1)
should return \"Hole-in-one!\"');",
+ "assert(golfScore(5, 5) === \"Par\", 'message: golfScore(5, 5)
should return \"Par\"');",
+ "assert(golfScore(4, 5) === \"Bogey\", 'message: golfScore(4, 5)
should return \"Bogey\"');",
+ "assert(golfScore(4, 6) === \"Double Bogey\", 'message: golfScore(4, 6)
should return \"Double Bogey\"');",
+ "assert(golfScore(4, 7) === \"Go Home!\", 'message: golfScore(4, 7)
should return \"Go Home!\"');",
+ "assert(golfScore(5, 9) === \"Go Home!\", 'message: golfScore(5, 9)
should return \"Go Home!\"');"
+ ],
"type": "bonfire",
"challengeType": "5",
"nameCn": "",
@@ -2851,14 +2877,6 @@
"Write a switch statement which tests val
and sets answer
for the following conditions:
1
- \"alpha\"
2
- \"beta\"
3
- \"gamma\"
4
- \"delta\""
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(myTest(1) === \"alpha\", 'message: myTest(1) should have a value of \"alpha\"');",
- "assert(myTest(2) === \"beta\", 'message: myTest(2) should have a value of \"beta\"');",
- "assert(myTest(3) === \"gamma\", 'message: myTest(3) should have a value of \"gamma\"');",
- "assert(myTest(4) === \"delta\", 'message: myTest(4) should have a value of \"delta\"');",
- "assert(!/else/g.test(code) || !/if/g.test(code), 'message: You should not use any if
or else
statements');",
- "assert(code.match(/break/g).length > 2, 'message: You should have at least 3 break
statements');"
- ],
"challengeSeed": [
"function myTest(val) {",
" var answer = \"\";",
@@ -2877,6 +2895,14 @@
"solutions": [
"function myTest(val) {\n var answer = \"\";\n\n switch (val) {\n case 1:\n answer = \"alpha\";\n break;\n case 2:\n answer = \"beta\";\n break;\n case 3:\n answer = \"gamma\";\n break;\n case 4:\n answer = \"delta\";\n }\n return answer; \n}"
],
+ "tests": [
+ "assert(myTest(1) === \"alpha\", 'message: myTest(1) should have a value of \"alpha\"');",
+ "assert(myTest(2) === \"beta\", 'message: myTest(2) should have a value of \"beta\"');",
+ "assert(myTest(3) === \"gamma\", 'message: myTest(3) should have a value of \"gamma\"');",
+ "assert(myTest(4) === \"delta\", 'message: myTest(4) should have a value of \"delta\"');",
+ "assert(!/else/g.test(code) || !/if/g.test(code), 'message: You should not use any if
or else
statements');",
+ "assert(code.match(/break/g).length > 2, 'message: You should have at least 3 break
statements');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -2896,15 +2922,6 @@
"Write a switch statement to set answer
for the following conditions:
\"a\"
- \"apple\"
\"b\"
- \"bird\"
\"c\"
- \"cat\"
default
- \"stuff\""
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(myTest(\"a\") === \"apple\", 'message: myTest(\"a\") should have a value of \"apple\"');",
- "assert(myTest(\"b\") === \"bird\", 'message: myTest(\"b\") should have a value of \"bird\"');",
- "assert(myTest(\"c\") === \"cat\", 'message: myTest(\"c\") should have a value of \"cat\"');",
- "assert(myTest(\"d\") === \"stuff\", 'message: myTest(\"d\") should have a value of \"stuff\"');",
- "assert(myTest(4) === \"stuff\", 'message: myTest(4) should have a value of \"stuff\"');",
- "assert(!/else/g.test(code) || !/if/g.test(code), 'message: You should not use any if
or else
statements');",
- "assert(code.match(/break/g).length > 2, 'message: You should have at least 3 break
statements');"
- ],
"challengeSeed": [
"function myTest(val) {",
" var answer = \"\";",
@@ -2923,6 +2940,15 @@
"solutions": [
"function myTest(val) {\n var answer = \"\";\n\n switch(val) {\n case \"a\":\n answer = \"apple\";\n break;\n case \"b\":\n answer = \"bird\";\n break;\n case \"c\":\n answer = \"cat\";\n break;\n default:\n answer = \"stuff\";\n }\n return answer; \n}"
],
+ "tests": [
+ "assert(myTest(\"a\") === \"apple\", 'message: myTest(\"a\") should have a value of \"apple\"');",
+ "assert(myTest(\"b\") === \"bird\", 'message: myTest(\"b\") should have a value of \"bird\"');",
+ "assert(myTest(\"c\") === \"cat\", 'message: myTest(\"c\") should have a value of \"cat\"');",
+ "assert(myTest(\"d\") === \"stuff\", 'message: myTest(\"d\") should have a value of \"stuff\"');",
+ "assert(myTest(4) === \"stuff\", 'message: myTest(4) should have a value of \"stuff\"');",
+ "assert(!/else/g.test(code) || !/if/g.test(code), 'message: You should not use any if
or else
statements');",
+ "assert(code.match(/break/g).length > 2, 'message: You should have at least 3 break
statements');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -2944,19 +2970,6 @@
"You will need to have a case
statement for each number in the range."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(myTest(1) === \"Low\", 'message: myTest(1)
should return \"Low\"');",
- "assert(myTest(2) === \"Low\", 'message: myTest(2)
should return \"Low\"');",
- "assert(myTest(3) === \"Low\", 'message: myTest(3)
should return \"Low\"');",
- "assert(myTest(4) === \"Mid\", 'message: myTest(4)
should return \"Mid\"');",
- "assert(myTest(5) === \"Mid\", 'message: myTest(5)
should return \"Mid\"');",
- "assert(myTest(6) === \"Mid\", 'message: myTest(6)
should return \"Mid\"');",
- "assert(myTest(7) === \"High\", 'message: myTest(7)
should return \"High\"');",
- "assert(myTest(8) === \"High\", 'message: myTest(8)
should return \"High\"');",
- "assert(myTest(9) === \"High\", 'message: myTest(9)
should return \"High\"');",
- "assert(!/else/g.test(code) || !/if/g.test(code), 'message: You should not use any if
or else
statements');",
- "assert(code.match(/case/g).length === 9, 'message: You should have nine case
statements');"
- ],
"challengeSeed": [
"function myTest(val) {",
" var answer = \"\";",
@@ -2975,6 +2988,19 @@
"solutions": [
"function myTest(val) {\n var answer = \"\";\n \n switch (val) {\n case 1:\n case 2:\n case 3:\n answer = \"Low\";\n break;\n case 4:\n case 5:\n case 6:\n answer = \"Mid\";\n break;\n case 7:\n case 8:\n case 9:\n answer = \"High\";\n }\n \n return answer; \n}"
],
+ "tests": [
+ "assert(myTest(1) === \"Low\", 'message: myTest(1)
should return \"Low\"');",
+ "assert(myTest(2) === \"Low\", 'message: myTest(2)
should return \"Low\"');",
+ "assert(myTest(3) === \"Low\", 'message: myTest(3)
should return \"Low\"');",
+ "assert(myTest(4) === \"Mid\", 'message: myTest(4)
should return \"Mid\"');",
+ "assert(myTest(5) === \"Mid\", 'message: myTest(5)
should return \"Mid\"');",
+ "assert(myTest(6) === \"Mid\", 'message: myTest(6)
should return \"Mid\"');",
+ "assert(myTest(7) === \"High\", 'message: myTest(7)
should return \"High\"');",
+ "assert(myTest(8) === \"High\", 'message: myTest(8)
should return \"High\"');",
+ "assert(myTest(9) === \"High\", 'message: myTest(9)
should return \"High\"');",
+ "assert(!/else/g.test(code) || !/if/g.test(code), 'message: You should not use any if
or else
statements');",
+ "assert(code.match(/case/g).length === 9, 'message: You should have nine case
statements');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -2995,18 +3021,6 @@
"Change the chained if
/if else
statements into a switch
statement."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(!/else/g.test(code), 'message: You should not use any else
statements');",
- "assert(!/if/g.test(code), 'message: You should not use any if
statements');",
- "assert(code.match(/break/g).length === 4, 'message: You should have four break
statements');",
- "assert(myTest(\"bob\") === \"Marley\", 'message: myTest(\"bob\")
should be \"Marley\"');",
- "assert(myTest(42) === \"The Answer\", 'message: myTest(42)
should be \"The Answer\"');",
- "assert(myTest(1) === \"There is no #1\", 'message: myTest(1)
should be \"There is no #1\"');",
- "assert(myTest(99) === \"Missed me by this much!\", 'message: myTest(99)
should be \"Missed me by this much!\"');",
- "assert(myTest(7) === \"Ate Nine\", 'message: myTest(7)
should be \"Ate Nine\"');",
- "assert(myTest(\"John\") === \"\", 'message: myTest(\"John\")
should be \"\" (empty string)');",
- "assert(myTest(156) === \"\", 'message: myTest(156)
should be \"\" (empty string)');"
- ],
"challengeSeed": [
"function myTest(val) {",
" var answer = \"\";",
@@ -3035,6 +3049,18 @@
"solutions": [
"function myTest(val) {\n var answer = \"\";\n\n switch (val) {\n case \"bob\":\n answer = \"Marley\";\n break;\n case 42:\n answer = \"The Answer\";\n break;\n case 1:\n answer = \"There is no #1\";\n break;\n case 99:\n answer = \"Missed me by this much!\";\n break;\n case 7:\n answer = \"Ate Nine\";\n }\n return answer; \n}"
],
+ "tests": [
+ "assert(!/else/g.test(code), 'message: You should not use any else
statements');",
+ "assert(!/if/g.test(code), 'message: You should not use any if
statements');",
+ "assert(code.match(/break/g).length === 4, 'message: You should have four break
statements');",
+ "assert(myTest(\"bob\") === \"Marley\", 'message: myTest(\"bob\")
should be \"Marley\"');",
+ "assert(myTest(42) === \"The Answer\", 'message: myTest(42)
should be \"The Answer\"');",
+ "assert(myTest(1) === \"There is no #1\", 'message: myTest(1)
should be \"There is no #1\"');",
+ "assert(myTest(99) === \"Missed me by this much!\", 'message: myTest(99)
should be \"Missed me by this much!\"');",
+ "assert(myTest(7) === \"Ate Nine\", 'message: myTest(7)
should be \"Ate Nine\"');",
+ "assert(myTest(\"John\") === \"\", 'message: myTest(\"John\")
should be \"\" (empty string)');",
+ "assert(myTest(156) === \"\", 'message: myTest(156)
should be \"\" (empty string)');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -3056,11 +3082,6 @@
"Fix the function isLess
to remove the if/else
statements."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(isLess(10,15) === true, 'message: isLess(10,15)
should return true
');",
- "assert(isLess(15, 10) === false, 'message: isLess(15,10)
should return true
');",
- "assert(!/if|else/g.test(code), 'message: You should not use any if
or else
statements');"
- ],
"challengeSeed": [
"function isLess(a, b) {",
" // Fix this code",
@@ -3080,6 +3101,11 @@
"solutions": [
"function isLess(a, b) {\n return a < b;\n}"
],
+ "tests": [
+ "assert(isLess(10,15) === true, 'message: isLess(10,15)
should return true
');",
+ "assert(isLess(15, 10) === false, 'message: isLess(15,10)
should return true
');",
+ "assert(!/if|else/g.test(code), 'message: You should not use any if
or else
statements');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -3100,14 +3126,6 @@
"Modify the function abTest
so that if a
or b
are less than 0
the function will immediately exit with a value of undefined
."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(typeof abTest(2,2) === 'number' , 'message: abTest(2,2)
should return a number');",
- "assert(abTest(2,2) === 8 , 'message: abTest(2,2)
should return 8
');",
- "assert(abTest(-2,2) === undefined , 'message: abTest(-2,2)
should return undefined
');",
- "assert(abTest(2,-2) === undefined , 'message: abTest(2,-2)
should return undefined
');",
- "assert(abTest(2,8) === 18 , 'message: abTest(2,8)
should return 18
');",
- "assert(abTest(3,3) === 12 , 'message: abTest(3,3)
should return 12
');"
- ],
"challengeSeed": [
"// Setup",
"function abTest(a, b) {",
@@ -3129,6 +3147,14 @@
"solutions": [
"function abTest(a, b) {\n if(a < 0 || b < 0) {\n return undefined;\n } \n return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2));\n}"
],
+ "tests": [
+ "assert(typeof abTest(2,2) === 'number' , 'message: abTest(2,2)
should return a number');",
+ "assert(abTest(2,2) === 8 , 'message: abTest(2,2)
should return 8
');",
+ "assert(abTest(-2,2) === undefined , 'message: abTest(-2,2)
should return undefined
');",
+ "assert(abTest(2,-2) === undefined , 'message: abTest(2,-2)
should return undefined
');",
+ "assert(abTest(2,8) === 18 , 'message: abTest(2,8)
should return 18
');",
+ "assert(abTest(3,3) === 12 , 'message: abTest(3,3)
should return 12
');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -3149,12 +3175,6 @@
"-3 Hold
5 Bet
"
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert((function(){ count = 0; cc(2);cc(3);cc(4);cc(5);var out = cc(6); if(out === \"5 Bet\") {return true;} return false; })(), 'message: Cards Sequence 2, 3, 4, 5, 6 should return \"5 Bet\"
');",
- "assert((function(){ count = 0; cc(7);cc(8);var out = cc(9); if(out === \"0 Hold\") {return true;} return false; })(), 'message: Cards Sequence 7, 8, 9 should return \"0 Hold\"
');",
- "assert((function(){ count = 0; cc(10);cc('J');cc('Q');cc('K');var out = cc('A'); if(out === \"-5 Hold\") {return true;} return false; })(), 'message: Cards Sequence 10, J, Q, K, A should return \"-5 Hold\"
');",
- "assert((function(){ count = 0; cc(3);cc(2);cc('A');cc(10);var out = cc('K'); if(out === \"-1 Hold\") {return true;} return false; })(), 'message: Cards Sequence 3, 2, A, 10, K should return \"-1 Hold\"
');"
- ],
"challengeSeed": [
"var count = 0;",
"",
@@ -3173,6 +3193,12 @@
"solutions": [
"var count = 0;\nfunction cc(card) {\n switch(card) {\n case 2:\n case 3:\n case 4:\n case 5:\n case 6:\n count++;\n break;\n case 10:\n case 'J':\n case 'Q':\n case 'K':\n case 'A':\n count--;\n }\n if(count > 0) {\n return count + \" Bet\";\n } else {\n return count + \" Hold\";\n }\n}"
],
+ "tests": [
+ "assert((function(){ count = 0; cc(2);cc(3);cc(4);cc(5);var out = cc(6); if(out === \"5 Bet\") {return true;} return false; })(), 'message: Cards Sequence 2, 3, 4, 5, 6 should return \"5 Bet\"
');",
+ "assert((function(){ count = 0; cc(7);cc(8);var out = cc(9); if(out === \"0 Hold\") {return true;} return false; })(), 'message: Cards Sequence 7, 8, 9 should return \"0 Hold\"
');",
+ "assert((function(){ count = 0; cc(10);cc('J');cc('Q');cc('K');var out = cc('A'); if(out === \"-5 Hold\") {return true;} return false; })(), 'message: Cards Sequence 10, J, Q, K, A should return \"-5 Hold\"
');",
+ "assert((function(){ count = 0; cc(3);cc(2);cc('A');cc(10);var out = cc('K'); if(out === \"-1 Hold\") {return true;} return false; })(), 'message: Cards Sequence 3, 2, A, 10, K should return \"-1 Hold\"
');"
+ ],
"type": "bonfire",
"challengeType": "5",
"nameCn": "",
@@ -3194,13 +3220,6 @@
"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 \"name\"
is a string, \"legs\"
and \"tails\"
are numbers, and \"friends\"
is an array."
],
- "tests": [
- "assert((function(z){if(z.hasOwnProperty(\"name\") && z.name !== undefined && typeof(z.name) === \"string\"){return true;}else{return false;}})(myDog), 'message: myDog
should contain the property name
and it should be a string
.');",
- "assert((function(z){if(z.hasOwnProperty(\"legs\") && z.legs !== undefined && typeof(z.legs) === \"number\"){return true;}else{return false;}})(myDog), 'message: myDog
should contain the property legs
and it should be a number
.');",
- "assert((function(z){if(z.hasOwnProperty(\"tails\") && z.tails !== undefined && typeof(z.tails) === \"number\"){return true;}else{return false;}})(myDog), 'message: myDog
should contain the property tails
and it should be a number
.');",
- "assert((function(z){if(z.hasOwnProperty(\"friends\") && z.friends !== undefined && Array.isArray(z.friends)){return true;}else{return false;}})(myDog), 'message: myDog
should contain the property friends
and it should be an array
.');",
- "assert((function(z){return Object.keys(z).length === 4;})(myDog), 'message: myDog
should only contain all the given properties.');"
- ],
"challengeSeed": [
"// Example",
"var ourDog = {",
@@ -3225,6 +3244,13 @@
"solutions": [
"var myDog = {\n \"name\": \"Camper\",\n \"legs\": 4,\n \"tails\": 1,\n \"friends\": [\"everything!\"] \n};"
],
+ "tests": [
+ "assert((function(z){if(z.hasOwnProperty(\"name\") && z.name !== undefined && typeof(z.name) === \"string\"){return true;}else{return false;}})(myDog), 'message: myDog
should contain the property name
and it should be a string
.');",
+ "assert((function(z){if(z.hasOwnProperty(\"legs\") && z.legs !== undefined && typeof(z.legs) === \"number\"){return true;}else{return false;}})(myDog), 'message: myDog
should contain the property legs
and it should be a number
.');",
+ "assert((function(z){if(z.hasOwnProperty(\"tails\") && z.tails !== undefined && typeof(z.tails) === \"number\"){return true;}else{return false;}})(myDog), 'message: myDog
should contain the property tails
and it should be a number
.');",
+ "assert((function(z){if(z.hasOwnProperty(\"friends\") && z.friends !== undefined && Array.isArray(z.friends)){return true;}else{return false;}})(myDog), 'message: myDog
should contain the property friends
and it should be an array
.');",
+ "assert((function(z){return Object.keys(z).length === 4;})(myDog), 'message: myDog
should only contain all the given properties.');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -3240,13 +3266,6 @@
"Read the values of the properties hat
and shirt
of testObj
using dot notation."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(typeof hatValue === 'string' , 'message: hatValue
should be a string');",
- "assert(hatValue === 'ballcap' , 'message: The value of hatValue
should be \"ballcap\"
');",
- "assert(typeof shirtValue === 'string' , 'message: shirtValue
should be a string');",
- "assert(shirtValue === 'jersey' , 'message: The value of shirtValue
should be \"jersey\"
');",
- "assert(code.match(/testObj\\.\\w+/g).length > 1, 'message: You should use dot notation twice');"
- ],
"challengeSeed": [
"// Setup",
"var testObj = {",
@@ -3266,6 +3285,13 @@
"solutions": [
"var testObj = {\n \"hat\": \"ballcap\",\n \"shirt\": \"jersey\",\n \"shoes\": \"cleats\"\n};\n\nvar hatValue = testObj.hat; \nvar shirtValue = testObj.shirt;"
],
+ "tests": [
+ "assert(typeof hatValue === 'string' , 'message: hatValue
should be a string');",
+ "assert(hatValue === 'ballcap' , 'message: The value of hatValue
should be \"ballcap\"
');",
+ "assert(typeof shirtValue === 'string' , 'message: shirtValue
should be a string');",
+ "assert(shirtValue === 'jersey' , 'message: The value of shirtValue
should be \"jersey\"
');",
+ "assert(code.match(/testObj\\.\\w+/g).length > 1, 'message: You should use dot notation twice');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -3286,13 +3312,6 @@
"Read the values of the properties \"an entree\"
and \"the drink\"
of testObj
using bracket notation."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(typeof entreeValue === 'string' , 'message: entreeValue
should be a string');",
- "assert(entreeValue === 'hamburger' , 'message: The value of entreeValue
should be \"hamburger\"
');",
- "assert(typeof drinkValue === 'string' , 'message: drinkValue
should be a string');",
- "assert(drinkValue === 'water' , 'message: The value of drinkValue
should be \"water\"
');",
- "assert(code.match(/testObj\\[('|\")[^'\"]+\\1\\]/g).length > 1, 'message: You should use bracket notation twice');"
- ],
"challengeSeed": [
"// Setup",
"var testObj = {",
@@ -3312,6 +3331,13 @@
"solutions": [
"var testObj = {\n \"an entree\": \"hamburger\",\n \"my side\": \"veggies\",\n \"the drink\": \"water\"\n};\nvar entreeValue = testObj[\"an entree\"];\nvar drinkValue = testObj['the drink'];"
],
+ "tests": [
+ "assert(typeof entreeValue === 'string' , 'message: entreeValue
should be a string');",
+ "assert(entreeValue === 'hamburger' , 'message: The value of entreeValue
should be \"hamburger\"
');",
+ "assert(typeof drinkValue === 'string' , 'message: drinkValue
should be a string');",
+ "assert(drinkValue === 'water' , 'message: The value of drinkValue
should be \"water\"
');",
+ "assert(code.match(/testObj\\[('|\")[^'\"]+\\1\\]/g).length > 1, 'message: You should use bracket notation twice');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -3332,12 +3358,6 @@
"Use the playerNumber
variable to lookup player 16
in testObj
using bracket notation."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(typeof playerNumber === 'number', 'message: playerNumber
should be a number');",
- "assert(typeof player === 'string', 'message: The variable player
should be a string');",
- "assert(player === 'Montana', 'message: The value of player
should be \"Montana\"');",
- "assert(/testObj\\[\\s*playerNumber\\s*\\]/.test(code),'message: You should use bracket notation to access testObj
');"
- ],
"challengeSeed": [
"// Setup",
"var testObj = {",
@@ -3357,6 +3377,12 @@
"solutions": [
"var testObj = {\n 12: \"Namath\",\n 16: \"Montana\",\n 19: \"Unitas\"\n};\nvar playerNumber = 16;\nvar player = testObj[playerNumber];"
],
+ "tests": [
+ "assert(typeof playerNumber === 'number', 'message: playerNumber
should be a number');",
+ "assert(typeof player === 'string', 'message: The variable player
should be a string');",
+ "assert(player === 'Montana', 'message: The value of player
should be \"Montana\"');",
+ "assert(/testObj\\[\\s*playerNumber\\s*\\]/.test(code),'message: You should use bracket notation to access testObj
');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -3379,10 +3405,6 @@
"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."
],
- "tests": [
- "assert(/happy coder/gi.test(myDog.name), 'message: Update myDog
's \"name\"
property to equal \"Happy Coder\".');",
- "assert(/\"name\": \"Coder\"/.test(code), 'message: Do not edit the myDog
definition');"
- ],
"challengeSeed": [
"// Example",
"var ourDog = {",
@@ -3409,6 +3431,13 @@
"tail": [
"(function(z){return z;})(myDog);"
],
+ "solutions": [
+ "var myDog = {\n \"name\": \"Coder\",\n \"legs\": 4,\n \"tails\": 1,\n \"friends\": [\"Free Code Camp Campers\"]\n};\nmyDog.name = \"Happy Coder\";"
+ ],
+ "tests": [
+ "assert(/happy coder/gi.test(myDog.name), 'message: Update myDog
's \"name\"
property to equal \"Happy Coder\".');",
+ "assert(/\"name\": \"Coder\"/.test(code), 'message: Do not edit the myDog
definition');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -3425,10 +3454,6 @@
"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."
],
- "tests": [
- "assert(myDog.bark !== undefined, 'message: Add the property \"bark\"
to myDog
.');",
- "assert(!/bark[^\\n]:/.test(code), 'message: Do not add \"bark\"
to the setup section');"
- ],
"challengeSeed": [
"// Example",
"var ourDog = {",
@@ -3457,6 +3482,10 @@
"solutions": [
"var myDog = {\n \"name\": \"Happy Coder\",\n \"legs\": 4,\n \"tails\": 1,\n \"friends\": [\"Free Code Camp Campers\"]\n};\nmyDog.bark = \"Woof Woof\";"
],
+ "tests": [
+ "assert(myDog.bark !== undefined, 'message: Add the property \"bark\"
to myDog
.');",
+ "assert(!/bark[^\\n]:/.test(code), 'message: Do not add \"bark\"
to the setup section');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -3469,10 +3498,6 @@
"Instructions
",
"Delete the \"tails\"
property from myDog
. You may use either dot or bracket notation."
],
- "tests": [
- "assert(myDog.tails === undefined, 'message: Delete the property \"tails\"
from myDog
.');",
- "assert(code.match(/\"tails\": 1/g).length > 1, 'message: Do not modify the myDog
setup');"
- ],
"challengeSeed": [
"// Example",
"var ourDog = {",
@@ -3504,6 +3529,10 @@
"solutions": [
"var ourDog = {\n \"name\": \"Camper\",\n \"legs\": 4,\n \"tails\": 1,\n \"friends\": [\"everything!\"],\n \"bark\": \"bow-wow\"\n};\n\nvar myDog = {\n \"name\": \"Happy Coder\",\n \"legs\": 4,\n \"tails\": 1,\n \"friends\": [\"Free Code Camp Campers\"],\n \"bark\": \"woof\"\n};\n\ndelete myDog.tails;"
],
+ "tests": [
+ "assert(myDog.tails === undefined, 'message: Delete the property \"tails\"
from myDog
.');",
+ "assert(code.match(/\"tails\": 1/g).length > 1, 'message: Do not modify the myDog
setup');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -3518,16 +3547,6 @@
"Convert the switch statement into a lookup table called lookup
. Use it to lookup val
and return the associated string."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(phoneticLookup(\"alpha\") === 'Adams', 'message: phoneticLookup(\"alpha\")
should equal \"Adams\"
');",
- "assert(phoneticLookup(\"bravo\") === 'Boston', 'message: phoneticLookup(\"bravo\")
should equal \"Boston\"
');",
- "assert(phoneticLookup(\"charlie\") === 'Chicago', 'message: phoneticLookup(\"charlie\")
should equal \"Chicago\"
');",
- "assert(phoneticLookup(\"delta\") === 'Denver', 'message: phoneticLookup(\"delta\")
should equal \"Denver\"
');",
- "assert(phoneticLookup(\"echo\") === 'Easy', 'message: phoneticLookup(\"echo\")
should equal \"Easy\"
');",
- "assert(phoneticLookup(\"foxtrot\") === 'Frank', 'message: phoneticLookup(\"foxtrot\")
should equal \"Frank\"
');",
- "assert(typeof phoneticLookup(\"\") === 'undefined', 'message: phoneticLookup(\"\")
should equal undefined
');",
- "assert(!/case|switch|if/g.test(code), 'message: You should not use case
, switch
, or if
statements'); "
- ],
"challengeSeed": [
"// Setup",
"function phoneticLookup(val) {",
@@ -3562,6 +3581,16 @@
"solutions": [
"function phoneticLookup(val) {\n var result = \"\";\n\n var lookup = {\n alpha: \"Adams\",\n bravo: \"Boston\",\n charlie: \"Chicago\",\n delta: \"Denver\",\n echo: \"Easy\",\n foxtrot: \"Frank\"\n };\n\n result = lookup[val];\n\n return result;\n}"
],
+ "tests": [
+ "assert(phoneticLookup(\"alpha\") === 'Adams', 'message: phoneticLookup(\"alpha\")
should equal \"Adams\"
');",
+ "assert(phoneticLookup(\"bravo\") === 'Boston', 'message: phoneticLookup(\"bravo\")
should equal \"Boston\"
');",
+ "assert(phoneticLookup(\"charlie\") === 'Chicago', 'message: phoneticLookup(\"charlie\")
should equal \"Chicago\"
');",
+ "assert(phoneticLookup(\"delta\") === 'Denver', 'message: phoneticLookup(\"delta\")
should equal \"Denver\"
');",
+ "assert(phoneticLookup(\"echo\") === 'Easy', 'message: phoneticLookup(\"echo\")
should equal \"Easy\"
');",
+ "assert(phoneticLookup(\"foxtrot\") === 'Frank', 'message: phoneticLookup(\"foxtrot\")
should equal \"Frank\"
');",
+ "assert(typeof phoneticLookup(\"\") === 'undefined', 'message: phoneticLookup(\"\")
should equal undefined
');",
+ "assert(!/case|switch|if/g.test(code), 'message: You should not use case
, switch
, or if
statements'); "
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -3581,11 +3610,6 @@
"Modify the function checkObj
to test myObj
for checkProp
. If the property is found, return that property's value. If not, return \"Not Found\"
."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(checkObj(\"gift\") === \"pony\", 'message: checkObj(\"gift\")
should return \"pony\"
.');",
- "assert(checkObj(\"pet\") === \"kitten\", 'message: checkObj(\"gift\")
should return \"kitten\"
.');",
- "assert(checkObj(\"house\") === \"Not Found\", 'message: checkObj(\"house\")
should return \"Not Found\"
.');"
- ],
"challengeSeed": [
"// Setup",
"var myObj = {",
@@ -3609,6 +3633,11 @@
"solutions": [
"var myObj = {\n gift: \"pony\",\n pet: \"kitten\",\n bed: \"sleigh\"\n};\nfunction checkObj(checkProp) {\n if(myObj.hasOwnProperty(checkProp)) {\n return myObj[checkProp];\n } else {\n return \"Not Found\";\n }\n}"
],
+ "tests": [
+ "assert(checkObj(\"gift\") === \"pony\", 'message: checkObj(\"gift\")
should return \"pony\"
.');",
+ "assert(checkObj(\"pet\") === \"kitten\", 'message: checkObj(\"gift\")
should return \"kitten\"
.');",
+ "assert(checkObj(\"house\") === \"Not Found\", 'message: checkObj(\"house\")
should return \"Not Found\"
.');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -3624,17 +3653,6 @@
"Add a new album to the myMusic
JSON object. Add artist
and title
strings, release_year
year, and a formats
array of strings."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(Array.isArray(myMusic), 'message: myMusic
should be an array');",
- "assert(myMusic.length > 1, 'message: myMusic
should have at least two elements');",
- "assert(typeof myMusic[1] === 'object', 'message: myMusic[1]
should be an object');",
- "assert(Object.keys(myMusic[1]).length > 3, 'message: myMusic[1]
should have at least 4 properties');",
- "assert(myMusic[1].hasOwnProperty('artist') && typeof myMusic[1].artist === 'string', 'message: myMusic[1]
should contain an artist
property which is a string');",
- "assert(myMusic[1].hasOwnProperty('title') && typeof myMusic[1].title === 'string', 'message: myMusic[1]
should contain a title
property which is a string');",
- "assert(myMusic[1].hasOwnProperty('release_year') && typeof myMusic[1].release_year === 'number', 'message: myMusic[1]
should contain a release_year
property which is a number');",
- "assert(myMusic[1].hasOwnProperty('formats') && Array.isArray(myMusic[1].formats), 'message: myMusic[1]
should contain a formats
property which is an array');",
- "assert(myMusic[1].formats.every(function(item) { return (typeof item === \"string\")}) && myMusic[1].formats.length > 1, 'message: formats
should be an array of strings with at least two elements');"
- ],
"challengeSeed": [
"var myMusic = [",
" {",
@@ -3657,6 +3675,17 @@
"solutions": [
"var myMusic = [\n {\n \"artist\": \"Billy Joel\",\n \"title\": \"Piano Man\",\n \"release_year\": 1993,\n \"formats\": [ \n \"CS\", \n \"8T\", \n \"LP\" ],\n \"gold\": true\n }, \n {\n \"artist\": \"ABBA\",\n \"title\": \"Ring Ring\",\n \"release_year\": 1973,\n \"formats\": [ \n \"CS\", \n \"8T\", \n \"LP\",\n \"CD\",\n ]\n }\n];"
],
+ "tests": [
+ "assert(Array.isArray(myMusic), 'message: myMusic
should be an array');",
+ "assert(myMusic.length > 1, 'message: myMusic
should have at least two elements');",
+ "assert(typeof myMusic[1] === 'object', 'message: myMusic[1]
should be an object');",
+ "assert(Object.keys(myMusic[1]).length > 3, 'message: myMusic[1]
should have at least 4 properties');",
+ "assert(myMusic[1].hasOwnProperty('artist') && typeof myMusic[1].artist === 'string', 'message: myMusic[1]
should contain an artist
property which is a string');",
+ "assert(myMusic[1].hasOwnProperty('title') && typeof myMusic[1].title === 'string', 'message: myMusic[1]
should contain a title
property which is a string');",
+ "assert(myMusic[1].hasOwnProperty('release_year') && typeof myMusic[1].release_year === 'number', 'message: myMusic[1]
should contain a release_year
property which is a number');",
+ "assert(myMusic[1].hasOwnProperty('formats') && Array.isArray(myMusic[1].formats), 'message: myMusic[1]
should contain a formats
property which is an array');",
+ "assert(myMusic[1].formats.every(function(item) { return (typeof item === \"string\")}) && myMusic[1].formats.length > 1, 'message: formats
should be an array of strings with at least two elements');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -3676,10 +3705,6 @@
"Access the myStorage
JSON object to retrieve the contents of the glove box
. Only use object notation for properties with a space in their name."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(gloveBoxContents === \"maps\", 'message: gloveBoxContents
should equal \"maps\"');",
- "assert(/=\\s*myStorage\\.car\\.inside\\[(\"|')glove box\\1\\]/g.test(code), 'message: Use dot and bracket notation to access myStorage
');"
- ],
"challengeSeed": [
"// Setup",
"var myStorage = {",
@@ -3710,6 +3735,10 @@
"solutions": [
"var myStorage = { \n \"car\":{ \n \"inside\":{ \n \"glove box\":\"maps\",\n \"passenger seat\":\"crumbs\"\n },\n \"outside\":{ \n \"trunk\":\"jack\"\n }\n }\n};\nvar gloveBoxContents = myStorage.car.inside[\"glove box\"];"
],
+ "tests": [
+ "assert(gloveBoxContents === \"maps\", 'message: gloveBoxContents
should equal \"maps\"');",
+ "assert(/=\\s*myStorage\\.car\\.inside\\[(\"|')glove box\\1\\]/g.test(code), 'message: Use dot and bracket notation to access myStorage
');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -3729,10 +3758,6 @@
"Retrieve the second tree from the variable myPlants
using object dot and array bracket notation."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(secondTree === \"pine\", 'message: secondTree
should equal \"pine\"');",
- "assert(/=\\s*myPlants\\[1\\].list\\[1\\]/.test(code), 'message: Use dot and bracket notation to access myPlants
');"
- ],
"challengeSeed": [
"// Setup",
"var myPlants = [",
@@ -3770,6 +3795,10 @@
"solutions": [
"var myPlants = [\n { \n type: \"flowers\",\n list: [\n \"rose\",\n \"tulip\",\n \"dandelion\"\n ]\n },\n {\n type: \"trees\",\n list: [\n \"fir\",\n \"pine\",\n \"birch\"\n ]\n } \n];\n\n// Only change code below this line\n\nvar secondTree = myPlants[1].list[1];"
],
+ "tests": [
+ "assert(secondTree === \"pine\", 'message: secondTree
should equal \"pine\"');",
+ "assert(/=\\s*myPlants\\[1\\].list\\[1\\]/.test(code), 'message: Use dot and bracket notation to access myPlants
');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -3791,12 +3820,6 @@
"Always return the entire collection object."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "collection = collectionCopy; assert(update(5439, \"artist\", \"ABBA\")[5439][\"artist\"] === \"ABBA\", 'message: After update(5439, \"artist\", \"ABBA\")
, artist
should be \"ABBA\"
');",
- "update(2548, \"artist\", \"\"); assert(!collection[2548].hasOwnProperty(\"artist\"), 'message: After update(2548, \"artist\", \"\")
, artist
should not be set');",
- "assert(update(1245, \"tracks\", \"Addicted to Love\")[1245][\"tracks\"].length === 1, 'message: After update(1245, \"tracks\", \"Addicted to Love\")
, tracks
should have a length of 1
');",
- "update(2548, \"tracks\", \"\"); assert(!collection[2548].hasOwnProperty(\"tracks\"), 'message: After update(2548, \"tracks\", \"\")
, tracks
should not be set');"
- ],
"challengeSeed": [
"// Setup",
"var collection = {",
@@ -3844,6 +3867,12 @@
"solutions": [
"var collection = {\n 2548: {\n album: \"Slippery When Wet\",\n artist: \"Bon Jovi\",\n tracks: [ \n \"Let It Rock\", \n \"You Give Love a Bad Name\" \n ]\n },\n 2468: {\n album: \"1999\",\n artist: \"Prince\",\n tracks: [ \n \"1999\", \n \"Little Red Corvette\" \n ]\n },\n 1245: {\n artist: \"Robert Palmer\",\n tracks: [ ]\n },\n 5439: {\n album: \"ABBA Gold\"\n }\n};\n// Keep a copy of the collection for tests\nvar collectionCopy = JSON.parse(JSON.stringify(collection));\n\n// Only change code below this line\nfunction update(id, prop, value) {\n if(value !== \"\") {\n if(prop === \"tracks\") {\n collection[id][prop].push(value);\n } else {\n collection[id][prop] = value;\n }\n } else {\n delete collection[id][prop];\n }\n\n return collection;\n}"
],
+ "tests": [
+ "collection = collectionCopy; assert(update(5439, \"artist\", \"ABBA\")[5439][\"artist\"] === \"ABBA\", 'message: After update(5439, \"artist\", \"ABBA\")
, artist
should be \"ABBA\"
');",
+ "update(2548, \"artist\", \"\"); assert(!collection[2548].hasOwnProperty(\"artist\"), 'message: After update(2548, \"artist\", \"\")
, artist
should not be set');",
+ "assert(update(1245, \"tracks\", \"Addicted to Love\")[1245][\"tracks\"].length === 1, 'message: After update(1245, \"tracks\", \"Addicted to Love\")
, tracks
should have a length of 1
');",
+ "update(2548, \"tracks\", \"\"); assert(!collection[2548].hasOwnProperty(\"tracks\"), 'message: After update(2548, \"tracks\", \"\")
, tracks
should not be set');"
+ ],
"type": "bonfire",
"challengeType": "5",
"nameCn": "",
@@ -3869,10 +3898,6 @@
"Instructions
",
"Use a for
loop to work to push the values 1 through 5 onto myArray
."
],
- "tests": [
- "assert(code.match(/for\\s*\\(/g).length > 1, 'message: You should be using a for
loop for this.');",
- "assert.deepEqual(myArray, [1,2,3,4,5], 'message: myArray
should equal [1,2,3,4,5]
.');"
- ],
"challengeSeed": [
"// Example",
"var ourArray = [];",
@@ -3891,6 +3916,13 @@
"tail": [
"if (typeof(myArray) !== \"undefined\"){(function(){return myArray;})();}"
],
+ "solutions": [
+ "var ourArray = [];\nfor (var i = 0; i < 5; i++) {\n ourArray.push(i);\n}\nvar myArray = [];\nfor (var i = 1; i < 6; i++) {\n myArray.push(i);\n}"
+ ],
+ "tests": [
+ "assert(code.match(/for\\s*\\(/g).length > 1, 'message: You should be using a for
loop for this.');",
+ "assert.deepEqual(myArray, [1,2,3,4,5], 'message: myArray
should equal [1,2,3,4,5]
.');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -3906,10 +3938,6 @@
"Instructions
",
"Push the odd numbers from 1 through 9 to myArray
using a for
loop."
],
- "tests": [
- "assert(code.match(/for\\s*\\(/g).length > 1, 'message: You should be using a for
loop for this.');",
- "assert.deepEqual(myArray, [1,3,5,7,9], 'message: myArray
should equal [1,3,5,7,9]
.');"
- ],
"challengeSeed": [
"// Example",
"var ourArray = [];",
@@ -3928,6 +3956,13 @@
"tail": [
"if(typeof(myArray) !== \"undefined\"){(function(){return myArray;})();}"
],
+ "solutions": [
+ "var ourArray = [];\nfor (var i = 0; i < 10; i += 2) {\n ourArray.push(i);\n}\nvar myArray = [];\nfor (var i = 1; i < 10; i += 2) {\n myArray.push(i);\n}"
+ ],
+ "tests": [
+ "assert(code.match(/for\\s*\\(/g).length > 1, 'message: You should be using a for
loop for this.');",
+ "assert.deepEqual(myArray, [1,3,5,7,9], 'message: myArray
should equal [1,3,5,7,9]
.');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -3944,10 +3979,6 @@
"Instructions
",
"Push the odd numbers from 9 through 1 to myArray
using a for
loop."
],
- "tests": [
- "assert(code.match(/for\\s*\\(/g).length > 1, 'message: You should be using a for
loop for this.');",
- "assert.deepEqual(myArray, [9,7,5,3,1], 'message: myArray
should equal [9,7,5,3,1]
.');"
- ],
"challengeSeed": [
"// Example",
"var ourArray = [];",
@@ -3965,6 +3996,13 @@
"tail": [
"if(typeof(myArray) !== \"undefined\"){(function(){return myArray;})();}"
],
+ "solutions": [
+ "var ourArray = [];\nfor (var i = 10; i > 0; i -= 2) {\n ourArray.push(i);\n}\nvar myArray = [];\nfor (var i = 9; i > 0; i -= 2) {\n myArray.push(i);\n}"
+ ],
+ "tests": [
+ "assert(code.match(/for\\s*\\(/g).length > 1, 'message: You should be using a for
loop for this.');",
+ "assert.deepEqual(myArray, [9,7,5,3,1], 'message: myArray
should equal [9,7,5,3,1]
.');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -3979,11 +4017,6 @@
"Create a variable total
. Use a for
loop to add each element of myArr
to total."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(total !== 'undefined', 'message: total
should be defined');",
- "assert(total === 20, 'message: total
should equal 20');",
- "assert(!/20/.test(code), 'message: Do not set total
to 20 directly');"
- ],
"challengeSeed": [
"// Example",
"var ourArr = [ 9, 10, 11, 12];",
@@ -4006,6 +4039,11 @@
"solutions": [
"var myArr = [ 2, 3, 4, 5, 6];\nvar total = 0;\n\nfor (var i = 0; i < myArr.length; i++) {\n total += myArr[i];\n}"
],
+ "tests": [
+ "assert(total !== 'undefined', 'message: total
should be defined');",
+ "assert(total === 20, 'message: total
should equal 20');",
+ "assert(!/20/.test(code), 'message: Do not set total
to 20 directly');"
+ ],
"type": "waypoint",
"challengeType": "1",
"nameCn": "",
@@ -4025,11 +4063,6 @@
"Modify function multiplyAll
so that it multiplies product
by each number in the subarrays of arr
"
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(multiplyAll([[1],[2],[3]]) === 6, 'message: multiplyAll([[1],[2],[3]]);
should return 6
');",
- "assert(multiplyAll([[1,2],[3,4],[5,6,7]]) === 5040, 'message: multiplyAll([[1,2],[3,4],[5,6,7]])
should return 5040
');",
- "assert(multiplyAll([[5,1],[0.2, 4, 0.5],[3, 9]]) === 54, 'message: multiplyAll([[5,1],[0.2, 4, 0.5],[3, 9]]);)
should return 54
');"
- ],
"challengeSeed": [
"function multiplyAll(arr) {",
" var product = 1;",
@@ -4047,7 +4080,12 @@
""
],
"solutions": [
- "function multiplyAll(arr) {\n var product = 1;\n for (var i = 0; i < arr.length; i++) {\n for (var j = 0; j < arr[i].length; j++) {\n product *= arr[i][j];\n }\n }\n return product;\n}\n\nmultiplyAll([[1,2],[3,4],[5,6,7]]);\n\n"
+ "function multiplyAll(arr) {\n var product = 1;\n for (var i = 0; i < arr.length; i++) {\n for (var j = 0; j < arr[i].length; j++) {\n product *= arr[i][j];\n }\n }\n return product;\n}\n\nmultiplyAll([[1,2],[3,4],[5,6,7]]);"
+ ],
+ "tests": [
+ "assert(multiplyAll([[1],[2],[3]]) === 6, 'message: multiplyAll([[1],[2],[3]]);
should return 6
');",
+ "assert(multiplyAll([[1,2],[3,4],[5,6,7]]) === 5040, 'message: multiplyAll([[1,2],[3,4],[5,6,7]])
should return 5040
');",
+ "assert(multiplyAll([[5,1],[0.2, 4, 0.5],[3, 9]]) === 54, 'message: multiplyAll([[5,1],[0.2, 4, 0.5],[3, 9]]);)
should return 54
');"
],
"type": "waypoint",
"challengeType": "1",
@@ -4068,10 +4106,6 @@
"Instructions
",
"Push the numbers 0 through 4 to myArray
using a while
loop."
],
- "tests": [
- "assert(code.match(/while/g), 'message: You should be using a while
loop for this.');",
- "assert.deepEqual(myArray, [0,1,2,3,4], 'message: myArray
should equal [0,1,2,3,4]
.');"
- ],
"challengeSeed": [
"// Setup",
"var myArray = [];",
@@ -4083,6 +4117,13 @@
"tail": [
"if(typeof(myArray) !== \"undefined\"){(function(){return myArray;})();}"
],
+ "solutions": [
+ "var myArray = [];\nvar i = 0;\nwhile(i < 5) {\n myArray.push(i);\n i++;\n}"
+ ],
+ "tests": [
+ "assert(code.match(/while/g), 'message: You should be using a while
loop for this.');",
+ "assert.deepEqual(myArray, [0,1,2,3,4], 'message: myArray
should equal [0,1,2,3,4]
.');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -4096,12 +4137,6 @@
"The provided code transforms the input into an array for you, codeArr
. Place the decoded values into the decodedArr
array where the provided code will transform it back into a string."
],
"releasedOn": "January 1, 2016",
- "tests": [
- "assert(rot13(\"SERR PBQR PNZC\") === \"FREE CODE CAMP\", 'message: rot13(\"SERR PBQR PNZC\")
should decode to \"FREE CODE CAMP\"
');",
- "assert(rot13(\"SERR CVMMN!\") === \"FREE PIZZA!\", 'message: rot13(\"SERR CVMMN!\")
should decode to \"FREE PIZZA!\"
');",
- "assert(rot13(\"SERR YBIR?\") === \"FREE LOVE?\", 'message: rot13(\"SERR YBIR?\")
should decode to \"FREE LOVE?\"
');",
- "assert(rot13(\"GUR DHVPX OEBJA QBT WHZCRQ BIRE GUR YNML SBK.\") === \"THE QUICK BROWN DOG JUMPED OVER THE LAZY FOX.\", 'message: rot13(\"GUR DHVPX OEBJA QBT WHZCRQ BIRE GUR YNML SBK.\")
should decode to \"THE QUICK BROWN DOG JUMPED OVER THE LAZY FOX.\"
');"
- ],
"challengeSeed": [
"function rot13(encodedStr) {",
" var codeArr = encodedStr.split(\"\"); // String to Array",
@@ -4123,6 +4158,12 @@
"solutions": [
"var lookup = {\n 'A': 'N','B': 'O','C': 'P','D': 'Q',\n 'E': 'R','F': 'S','G': 'T','H': 'U',\n 'I': 'V','J': 'W','K': 'X','L': 'Y',\n 'M': 'Z','N': 'A','O': 'B','P': 'C',\n 'Q': 'D','R': 'E','S': 'F','T': 'G',\n 'U': 'H','V': 'I','W': 'J','X': 'K',\n 'Y': 'L','Z': 'M' \n};\n\nfunction rot13(encodedStr) {\n var codeArr = encodedStr.split(\"\"); // String to Array\n var decodedArr = []; // Your Result goes here\n // Only change code below this line\n \n decodedArr = codeArr.map(function(letter) {\n if(lookup.hasOwnProperty(letter)) {\n letter = lookup[letter];\n }\n return letter;\n });\n\n // Only change code above this line\n return decodedArr.join(\"\"); // Array to String\n}"
],
+ "tests": [
+ "assert(rot13(\"SERR PBQR PNZC\") === \"FREE CODE CAMP\", 'message: rot13(\"SERR PBQR PNZC\")
should decode to \"FREE CODE CAMP\"
');",
+ "assert(rot13(\"SERR CVMMN!\") === \"FREE PIZZA!\", 'message: rot13(\"SERR CVMMN!\")
should decode to \"FREE PIZZA!\"
');",
+ "assert(rot13(\"SERR YBIR?\") === \"FREE LOVE?\", 'message: rot13(\"SERR YBIR?\")
should decode to \"FREE LOVE?\"
');",
+ "assert(rot13(\"GUR DHVPX OEBJA QBT WHZCRQ BIRE GUR YNML SBK.\") === \"THE QUICK BROWN DOG JUMPED OVER THE LAZY FOX.\", 'message: rot13(\"GUR DHVPX OEBJA QBT WHZCRQ BIRE GUR YNML SBK.\")
should decode to \"THE QUICK BROWN DOG JUMPED OVER THE LAZY FOX.\"
');"
+ ],
"type": "bonfire",
"challengeType": "5",
"nameCn": "",
@@ -4136,14 +4177,11 @@
"title": "Generate Random Fractions with JavaScript",
"description": [
"Random numbers are useful for creating random behavior.",
- "JavaScript has a Math.random()
function that generates a random decimal number.",
- "Change myFunction
to return a random number instead of returning 0
.",
- "Note that you can return a function, just like you would return a variable or value."
- ],
- "tests": [
- "assert(typeof(myFunction()) === \"number\", 'message: myFunction
should return a random number.');",
- "assert((myFunction()+''). match(/\\./g), 'message: The number returned by myFunction
should be a decimal.');",
- "assert(code.match(/Math\\.random/g).length >= 0, 'message: You should be using Math.random
to generate the random decimal number.');"
+ "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, all function calls will be resolved before the return
executes, so we can simply return
the value of the Math.random()
function.",
+ "Instructions
",
+ "Change myFunction
to return a random number instead of returning 0
."
],
"challengeSeed": [
"function myFunction() {",
@@ -4158,6 +4196,14 @@
"tail": [
"(function(){return myFunction();})();"
],
+ "solutions": [
+ "function myFunction() {\n return Math.random();\n}"
+ ],
+ "tests": [
+ "assert(typeof(myFunction()) === \"number\", 'message: myFunction
should return a random number.');",
+ "assert((myFunction()+''). match(/\\./g), 'message: The number returned by myFunction
should be a decimal.');",
+ "assert(code.match(/Math\\.random/g).length >= 0, 'message: You should be using Math.random
to generate the random decimal number.');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -4165,22 +4211,12 @@
"id": "cf1111c1c12feddfaeb1bdef",
"title": "Generate Random Whole Numbers with JavaScript",
"description": [
- "It's great that we can generate random decimal numbers, but it's even more useful if we use it to generate random whole numbers.",
- "First, let's use Math.random()
to generate a random decimal.",
- "Then let's multiply this random decimal by 20.",
- "Finally, let's use another function, Math.floor()
to round the number down to its nearest whole number.",
- "This technique will gives us a whole number between 0 and 19.",
- "Note that because we're rounding down, it's impossible to actually get 20.",
+ "It's great that we can generate random decimal numbers, but it's even more useful if we use it to generate random whole numbers.- Use
Math.random()
to generate a random decimal. - Multiply that random decimal by
20
. - Use another function,
Math.floor()
to round the number down to its nearest whole number.
Remember that Math.random()
can never quite return a 1
and, because we're rounding down, it's impossible to actually get 20
. This technique will gives us a whole number between 0
and 19
.",
"Putting everything together, this is what our code looks like:",
"Math.floor(Math.random() * 20);
",
"See how Math.floor
takes (Math.random() * 20)
as its argument? That's right - you can pass a function to another function as an argument.",
- "Let's use this technique to generate and return a random whole number between 0 and 9."
- ],
- "tests": [
- "assert(typeof(myFunction()) === \"number\" && (function(){var r = myFunction();return Math.floor(r) === r;})(), 'message: The result of myFunction
should be a whole number.');",
- "assert(code.match(/Math.random/g).length > 1, 'message: You should be using Math.random
to generate a random number.');",
- "assert(code.match(/\\(\\s*?Math.random\\s*?\\(\\s*?\\)\\s*?\\*\\s*?10\\s*?\\)/g) || code.match(/\\(\\s*?10\\s*?\\*\\s*?Math.random\\s*?\\(\\s*?\\)\\s*?\\)/g), 'message: You should have multiplied the result of Math.random
by 10 to make it a number that is between zero and nine.');",
- "assert(code.match(/Math.floor/g).length > 1, 'message: You should use Math.floor
to remove the decimal part of the number.');"
+ "Instructions
",
+ "Use this technique to generate and return a random whole number between 0
and 9
."
],
"challengeSeed": [
"var randomNumberBetween0and19 = Math.floor(Math.random() * 20);",
@@ -4195,6 +4231,15 @@
"tail": [
"(function(){return myFunction();})();"
],
+ "solutions": [
+ "var randomNumberBetween0and19 = Math.floor(Math.random() * 20);\n\nfunction myFunction() {\n return Math.floor(Math.random() * 10);\n}"
+ ],
+ "tests": [
+ "assert(typeof(myFunction()) === \"number\" && (function(){var r = myFunction();return Math.floor(r) === r;})(), 'message: The result of myFunction
should be a whole number.');",
+ "assert(code.match(/Math.random/g).length > 1, 'message: You should be using Math.random
to generate a random number.');",
+ "assert(code.match(/\\(\\s*?Math.random\\s*?\\(\\s*?\\)\\s*?\\*\\s*?10\\s*?\\)/g) || code.match(/\\(\\s*?10\\s*?\\*\\s*?Math.random\\s*?\\(\\s*?\\)\\s*?\\)/g), 'message: You should have multiplied the result of Math.random
by 10 to make it a number that is between zero and nine.');",
+ "assert(code.match(/Math.floor/g).length > 1, 'message: You should use Math.floor
to remove the decimal part of the number.');"
+ ],
"type": "waypoint",
"challengeType": "1"
},
@@ -4206,40 +4251,53 @@
"To do this, we'll define a minimum number min
and a maximum number max
.",
"Here's the formula we'll use. Take a moment to read it and try to understand what this code is doing:",
"Math.floor(Math.random() * (max - min + 1)) + min
",
- "Define two variables: myMin
and myMax
, and set them both equal to numbers.",
- "Then create a function called myFunction
that returns a random number that's greater than or equal to myMin
, and is less than or equal to myMax
."
- ],
- "tests": [
- "assert(myFunction() >= myMin, 'message: The random number generated by myFunction
should be greater than or equal to your minimum number, myMin
.');",
- "assert(myFunction() <= myMax, 'message: The random number generated by myFunction
should be less than or equal to your maximum number, myMax
.');",
- "assert(myFunction() % 1 === 0 , 'message: The random number generated by myFunction
should be an integer, not a decimal.');",
- "assert((function(){if(code.match(/myMax/g).length > 1 && code.match(/myMin/g).length > 2 && code.match(/Math.floor/g) && code.match(/Math.random/g)){return true;}else{return false;}})(), 'message: myFunction()
should use use both myMax
and myMin
, and return a random number in your range.');"
+ "Instructions
",
+ "Create a function called randomRange
that takes a range myMin
and myMax
and returns a random number that's greater than or equal to myMin
, and is less than or equal to myMax
, inclusive."
],
"challengeSeed": [
- "var ourMin = 1;",
- "",
- "var ourMax = 9;",
- "",
- "function ourFunction() {",
+ "// Example",
+ "function ourFunction(ourMin, ourMax) {",
"",
" return Math.floor(Math.random() * (ourMax - ourMin + 1)) + ourMin;",
- "",
"}",
"",
+ "ourFunction(1, 9);",
+ "",
"// Only change code below this line.",
"",
- "var myMin;",
+ "function randomRange(myMin, myMax) {",
"",
- "var myMax;",
+ " return 0; // Change this line",
"",
- "function myFunction() {",
+ "}",
"",
- " return;",
- "",
- "}"
+ "// Change these values to test your function",
+ "var myRandom = randomRange(5, 15);"
],
"tail": [
- "(function(){return myFunction();})();"
+ "var calcMin = 100;",
+ "var calcMax = -100;",
+ "for(var i = 0; i < 100; i++) {",
+ " var result = randomRange(5,15);",
+ " calcMin = Math.min(calcMin, result);",
+ " calcMax = Math.max(calcMax, result);",
+ "}",
+ "(function(){",
+ " if(typeof myRandom === 'number') {",
+ " return \"myRandom = \" + myRandom;",
+ " } else {",
+ " return \"myRandom undefined\";",
+ " }",
+ "})();"
+ ],
+ "solutions": [
+ "function randomRange(myMin, myMax) {\n return Math.floor(Math.random() * (myMax - myMin + 1)) + myMin;\n}"
+ ],
+ "tests": [
+ "assert(calcMin === 5, 'message: The random number generated by myFunction
should be greater than or equal to your minimum number, myMin
.');",
+ "assert(calcMax === 15, 'message: The random number generated by myFunction
should be less than or equal to your maximum number, myMax
.');",
+ "assert(randomRange(0,1) % 1 === 0 , 'message: The random number generated by myFunction
should be an integer, not a decimal.');",
+ "assert((function(){if(code.match(/myMax/g).length > 1 && code.match(/myMin/g).length > 2 && code.match(/Math.floor/g) && code.match(/Math.random/g)){return true;}else{return false;}})(), 'message: myFunction()
should use use both myMax
and myMin
, and return a random number in your range.');"
],
"type": "waypoint",
"challengeType": "1"
@@ -4251,37 +4309,46 @@
"Regular expressions
are used to find certain words or patterns inside of strings
.",
"For example, if we wanted to find the word the
in the string The dog chased the cat
, we could use the following regular expression
: /the/gi
",
"Let's break this down a bit:",
+ "/
is the start of the regular expression.",
"the
is the pattern we want to match.",
- "g
means that we want to search the entire string for this pattern instead of just the first match.",
+ "/
is the end of the regular expression.",
+ "g
means global
, which causes the pattern to return all matches in the string, not just the first one.",
"i
means that we want to ignore the case (uppercase or lowercase) when searching for the pattern.",
- "Regular expressions
are written by surrounding the pattern with /
symbols.",
- "Let's try selecting all the occurrences of the word and
in the string Ada Lovelace and Charles Babbage designed the first computer and the software that would have run on it
.",
- "We can do this by replacing the .
part of our regular expression with the word and
."
- ],
- "tests": [
- "assert(test==2, 'message: Your regular expression
should find two occurrences of the word and
.');",
- "assert(code.match(/\\/and\\/gi/), 'message: Use regular expressions
to find the word and
in testString
.');"
+ "Instructions
",
+ "Select all the occurrences of the word and
in testString
.",
+ "You can do this by replacing the .
part of the regular expression with the word and
."
],
"head": [
""
],
"challengeSeed": [
"// Setup",
- "var test = (function() {",
- " // Example",
- " var testString = \"Ada Lovelace and Charles Babbage designed the first computer and the software that would have run on it.\";",
- " var expressionToGetSoftware = /software/gi;",
+ "var testString = \"Ada Lovelace and Charles Babbage designed the first computer and the software that would have run on it.\";",
"",
- " // Only change code below this line.",
+ "// Example",
+ "var expressionToGetSoftware = /software/gi;",
+ "var softwareCount = testString.match(expressionToGetSoftware).length;",
+ " ",
"",
- " var expression = /./gi;",
+ "// Only change code below this line.",
"",
- " // Only change code above this line",
- " return testString.match(expression).length;",
- "})();(function(){return test;})();"
+ "var expression = /./gi; // Change this Line",
+ "",
+ "// Only change code above this line",
+ "",
+ "// This code counts the matches of expression in testString",
+ "var andCount = testString.match(expression).length;",
+ ""
],
"tail": [
- ""
+ "(function(){return andCount;})();"
+ ],
+ "solutions": [
+ "var testString = \"Ada Lovelace and Charles Babbage designed the first computer and the software that would have run on it.\";\nvar expression = /and/gi; // Change this Line\nvar andCount = testString.match(expression).length;"
+ ],
+ "tests": [
+ "assert(andCount==2, 'message: Your regular expression
should find two occurrences of the word and
.');",
+ "assert(code.match(/\\/and\\/gi/), 'message: Use regular expressions
to find the word and
in testString
.');"
],
"type": "waypoint",
"challengeType": "1"
@@ -4293,29 +4360,35 @@
"We can use special selectors in Regular Expressions
to select a particular type of value.",
"One such selector is the digit selector \\d
which is used to retrieve the numbers in a string.",
"It is used like this: /\\d/g
.",
- "For numbers this is often written as /\\d+/g
, where the +
following the digit selector allows this regular expression to match multi-digit numbers.",
- "Use the \\d
selector to select the number of numbers in the string, allowing for the possibility of multi-digit numbers."
- ],
- "tests": [
- "assert(code.match(/\\/\\\\d\\+\\//g), 'message: Use the /\\d+/g
regular expression to find the numbers in testString
.');",
- "assert(test === 2, 'message: Your regular expression should find two numbers in testString
.');"
+ "For numbers this is often written as /\\d+/g
, where the +
following the digit selector allows this regular expression to match one or more numbers.",
+ "Instructions
",
+ "Use the \\d
selector to select the number of numbers in the string, allowing for the possibility of one or more digit."
],
"head": [
- "var test = (function() {"
- ],
- "challengeSeed": [
- "var test = (function() {",
- "",
- " var testString = \"There are 3 cats but 4 dogs.\";",
- "",
- " // Only change code below this line.",
- "",
- " var expression = /.+/g;",
""
],
+ "challengeSeed": [
+ "// Setup",
+ "var testString = \"There are 3 cats but 4 dogs.\";",
+ "",
+ "// Only change code below this line.",
+ "",
+ "var expression = /.+/g; // Change this line",
+ "",
+ "// Only change code above this line",
+ "",
+ "// This code counts the matches of expression in testString",
+ "var digitCount = testString.match(expression).length;"
+ ],
"tail": [
- " return testString.match(expression).length;",
- "})();(function(){return test;})();"
+ "(function(){return digitCount;})();"
+ ],
+ "solutions": [
+ "var testString = \"There are 3 cats but 4 dogs.\";\nvar expression = /\\d+/g; // Change this line\nvar digitCount = testString.match(expression).length;"
+ ],
+ "tests": [
+ "assert(digitCount === 2, 'message: Your regular expression should find two numbers in testString
.');",
+ "assert(code.match(/\\/\\\\d\\+\\//g), 'message: Use the /\\d+/g
regular expression to find the numbers in testString
.');"
],
"type": "waypoint",
"challengeType": "1"
@@ -4328,27 +4401,34 @@
"The whitespace characters are \" \"
(space), \\r
(the carriage return), \\n
(newline), \\t
(tab), and \\f
(the form feed).",
"The whitespace regular expression looks like this:",
"/\\s+/g
",
- "Use it to select all the whitespace characters in the sentence string."
- ],
- "tests": [
- "assert(code.match(/\\/\\\\s\\+\\//g), 'message: Use the /\\s+/g
regular expression to find the spaces in testString
.');",
- "assert(test === 7, 'message: Your regular expression should find seven spaces in testString
.');"
+ "Instructions
",
+ "Use \\s
to select all the whitespace characters in the sentence string."
],
"head": [
- "var test = (function() {"
- ],
- "challengeSeed": [
- " var testString = \"How many spaces are there in this sentence?\";",
- "",
- " // Only change code below this line.",
- "",
- " var expression = /.+/g;",
""
],
- "tail": [
- " return testString.match(expression).length;",
+ "challengeSeed": [
+ "// Setup",
+ "var testString = \"How many spaces are there in this sentence?\";",
"",
- "})();(function(){return test;})();"
+ "// Only change code below this line.",
+ "",
+ "var expression = /.+/g; // Change this line",
+ "",
+ "// Only change code above this line",
+ "",
+ "// This code counts the matches of expression in testString",
+ "var spaceCount = testString.match(expression).length;"
+ ],
+ "tail": [
+ "(function(){return spaceCount;})();"
+ ],
+ "solutions": [
+ "var testString = \"How many spaces are there in this sentence?\";\nvar expression = /\\s+/g; // Change this line\nvar spaceCount = testString.match(expression).length;"
+ ],
+ "tests": [
+ "assert(spaceCount === 7, 'message: Your regular expression should find seven spaces in testString
.');",
+ "assert(code.match(/\\/\\\\s\\+\\//g), 'message: Use the /\\s+/g
regular expression to find the spaces in testString
.');"
],
"type": "waypoint",
"challengeType": "1"
@@ -4359,26 +4439,34 @@
"description": [
"You can invert any match by using the uppercase version of the regular expression selector.",
"For example, \\s
will match any whitespace, and \\S
will match anything that isn't whitespace.",
+ "Instructions
",
"Use /\\S/g
to count the number of non-whitespace characters in testString
."
],
- "tests": [
- "assert(code.match(/\\/\\\\S\\/g/g), 'message: Use the /\\S/g
regular expression to find non-space characters in testString
.');",
- "assert(test === 49, 'message: Your regular expression should find forty nine non-space characters in the testString
.');"
- ],
"head": [
- "var test = (function() {"
- ],
- "challengeSeed": [
- " var testString = \"How many non-space characters are there in this sentence?\";",
- "",
- " // Only change code below this line.",
- "",
- " var expression = /./g;",
""
],
+ "challengeSeed": [
+ "// Setup",
+ "var testString = \"How many non-space characters are there in this sentence?\";",
+ "",
+ "// Only change code below this line.",
+ "",
+ "var expression = /.+/g; // Change this line",
+ "",
+ "// Only change code above this line",
+ "",
+ "// This code counts the matches of expression in testString",
+ "var nonSpaceCount = testString.match(expression).length;"
+ ],
"tail": [
- " return testString.match(expression).length;",
- "})();(function(){return test;})();"
+ "(function(){return nonSpaceCount;})();"
+ ],
+ "solutions": [
+ "var testString = \"How many non-space characters are there in this sentence?\";\nvar expression = /\\S/g; \nvar nonSpaceCount = testString.match(expression).length;"
+ ],
+ "tests": [
+ "assert(nonSpaceCount === 49, 'message: Your regular expression should find forty nine non-space characters in the testString
.');",
+ "assert(code.match(/\\/\\\\S\\/g/g), 'message: Use the /\\S/g
regular expression to find non-space characters in testString
.');"
],
"type": "waypoint",
"challengeType": "1"
@@ -4386,7 +4474,6 @@
{
"id": "cf1111c1c12feddfaeb9bdef",
"title": "Create a JavaScript Slot Machine",
- "isBeta": "true",
"description": [
"We are now going to try and combine some of the stuff we've just learned and create the logic for a slot machine game.",
"For this we will need to generate three random numbers between 1
and 3
to represent the possible values of each individual slot.",
@@ -4394,12 +4481,6 @@
"Generate the random numbers by using the system we used earlier (an explanation of the formula can be found here):",
"Math.floor(Math.random() * (3 - 1 + 1)) + 1;
"
],
- "tests": [
- "assert(typeof(runSlots($(\".slot\"))[0]) === \"number\" && runSlots($(\".slot\"))[0] > 0 && runSlots($(\".slot\"))[0] < 4, 'slotOne
should be a random number.')",
- "assert(typeof(runSlots($(\".slot\"))[1]) === \"number\" && runSlots($(\".slot\"))[1] > 0 && runSlots($(\".slot\"))[1] < 4, 'slotTwo
should be a random number.')",
- "assert(typeof(runSlots($(\".slot\"))[2]) === \"number\" && runSlots($(\".slot\"))[2] > 0 && runSlots($(\".slot\"))[2] < 4, 'slotThree
should be a random number.')",
- "assert((function(){if(editor.match(/Math\\.floor\\(\\s?Math\\.random\\(\\)\\s?\\*\\s?\\(\\s?3\\s?\\-\\s?1\\s?\\+\\s?1\\s?\\)\\s?\\)\\s?\\+\\s?1/gi) !== null){return editor.match(/slot.*?=.*?\\(.*?\\).*?/gi).length >= 3;}else{return false;}})(), 'You should have used Math.floor(Math.random() * (3 - 1 + 1)) + 1;
three times to generate your random numbers.')"
- ],
"challengeSeed": [
"fccss",
" function runSlots() {",
@@ -4535,13 +4616,22 @@
" }",
""
],
+ "solutions": [
+ ""
+ ],
+ "tests": [
+ "assert(typeof(runSlots($(\".slot\"))[0]) === \"number\" && runSlots($(\".slot\"))[0] > 0 && runSlots($(\".slot\"))[0] < 4, 'slotOne
should be a random number.')",
+ "assert(typeof(runSlots($(\".slot\"))[1]) === \"number\" && runSlots($(\".slot\"))[1] > 0 && runSlots($(\".slot\"))[1] < 4, 'slotTwo
should be a random number.')",
+ "assert(typeof(runSlots($(\".slot\"))[2]) === \"number\" && runSlots($(\".slot\"))[2] > 0 && runSlots($(\".slot\"))[2] < 4, 'slotThree
should be a random number.')",
+ "assert((function(){if(editor.match(/Math\\.floor\\(\\s?Math\\.random\\(\\)\\s?\\*\\s?\\(\\s?3\\s?\\-\\s?1\\s?\\+\\s?1\\s?\\)\\s?\\)\\s?\\+\\s?1/gi) !== null){return editor.match(/slot.*?=.*?\\(.*?\\).*?/gi).length >= 3;}else{return false;}})(), 'You should have used Math.floor(Math.random() * (3 - 1 + 1)) + 1;
three times to generate your random numbers.')"
+ ],
"type": "waypoint",
- "challengeType": "0"
+ "challengeType": "0",
+ "isBeta": "true"
},
{
"id": "cf1111c1c13feddfaeb1bdef",
"title": "Add your JavaScript Slot Machine Slots",
- "isBeta": "true",
"description": [
"Now that our slots will each generate random numbers, we need to check whether they've all returned the same number.",
"If they have, we should notify our user that they've won and we should return null
.",
@@ -4553,9 +4643,6 @@
"Also, we need to show the user that he has won the game when he gets the same number in all the slots.",
"If all three numbers match, we should also set the text \"It's A Win\"
to the element with class logger
."
],
- "tests": [
- "assert((function(){var data = runSlots();return data === null || data.toString().length === 1;})(), 'If all three of our random numbers are the same we should return that number. Otherwise we should return null
.')"
- ],
"challengeSeed": [
"fccss",
" function runSlots() {",
@@ -4695,13 +4782,19 @@
" }",
""
],
+ "solutions": [
+ ""
+ ],
+ "tests": [
+ "assert((function(){var data = runSlots();return data === null || data.toString().length === 1;})(), 'If all three of our random numbers are the same we should return that number. Otherwise we should return null
.')"
+ ],
"type": "waypoint",
- "challengeType": "0"
+ "challengeType": "0",
+ "isBeta": "true"
},
{
"id": "cf1111c1c13feddfaeb2bdef",
"title": "Bring your JavaScript Slot Machine to Life",
- "isBeta": "true",
"description": [
"Now we can detect a win. Let's get this slot machine working.",
"Let's use the jQuery selector
$(\".slot\")
to select all of the slots.",
@@ -4710,10 +4803,6 @@
"This jQuery will select the first slot and update it's HTML to display the correct number.",
"Use the above selector to display each number in its corresponding slot."
],
- "tests": [
- "assert((function(){runSlots();if($($(\".slot\")[0]).html().replace(/\\s/gi, \"\") !== \"\" && $($(\".slot\")[1]).html().replace(/\\s/gi, \"\") !== \"\" && $($(\".slot\")[2]).html().replace(/\\s/gi, \"\") !== \"\"){return true;}else{return false;}})(), 'You should be displaying the result of the slot numbers in the corresponding slots.')",
- "assert((editor.match( /\\$\\s*?\\(\\s*?\\$\\s*?\\(\\s*?(?:'|\")\\s*?\\.slot\\s*?(?:'|\")\\s*?\\)\\[\\d\\]\\s*?\\)/gi) && editor.match( /\\$\\s*?\\(\\s*?\\$\\s*?\\(\\s*?(?:'|\")\\s*?\\.slot\\s*?(?:'|\")\\s*?\\)\\[\\d\\]\\s*?\\)/gi ).length >= 3 && editor.match( /\\.html\\(slotOne\\)/gi ) && editor.match( /\\.html\\(slotTwo\\)/gi ) && editor.match( /\\.html\\(slotThree\\)/gi )), 'You should have used the the selector given in the description to select each slot and assign it the value of slotOne
, slotTwo
and slotThree
respectively.')"
- ],
"challengeSeed": [
"fccss",
" function runSlots() {",
@@ -4861,13 +4950,20 @@
" }",
""
],
+ "solutions": [
+ ""
+ ],
+ "tests": [
+ "assert((function(){runSlots();if($($(\".slot\")[0]).html().replace(/\\s/gi, \"\") !== \"\" && $($(\".slot\")[1]).html().replace(/\\s/gi, \"\") !== \"\" && $($(\".slot\")[2]).html().replace(/\\s/gi, \"\") !== \"\"){return true;}else{return false;}})(), 'You should be displaying the result of the slot numbers in the corresponding slots.')",
+ "assert((editor.match( /\\$\\s*?\\(\\s*?\\$\\s*?\\(\\s*?(?:'|\")\\s*?\\.slot\\s*?(?:'|\")\\s*?\\)\\[\\d\\]\\s*?\\)/gi) && editor.match( /\\$\\s*?\\(\\s*?\\$\\s*?\\(\\s*?(?:'|\")\\s*?\\.slot\\s*?(?:'|\")\\s*?\\)\\[\\d\\]\\s*?\\)/gi ).length >= 3 && editor.match( /\\.html\\(slotOne\\)/gi ) && editor.match( /\\.html\\(slotTwo\\)/gi ) && editor.match( /\\.html\\(slotThree\\)/gi )), 'You should have used the the selector given in the description to select each slot and assign it the value of slotOne
, slotTwo
and slotThree
respectively.')"
+ ],
"type": "waypoint",
- "challengeType": "0"
+ "challengeType": "0",
+ "isBeta": "true"
},
{
"id": "cf1111c1c11feddfaeb1bdff",
"title": "Give your JavaScript Slot Machine some Stylish Images",
- "isBeta": "true",
"description": [
"Now let's add some images to our slots.",
"We've already set up the images for you in an array called images
. We can use different indexes to grab each of these.",
@@ -4875,15 +4971,6 @@
"$($('.slot')[0]).html('<img src = \"' + images[slotOne-1] + '\">');
",
"Set up all three slots like this, then click the \"Go\" button to play the slot machine."
],
- "tests": [
- "assert((editor.match(/\\$\\s*?\\(\\s*?\\$\\s*?\\(\\s*?(?:'|\")\\s*?\\.slot\\s*?(?:'|\")\\s*?\\)\\[\\d\\]\\s*?\\)\\.html\\(\\s*?\\'\\
\\'\\s*?\\);/gi) && editor.match(/\\$\\s*?\\(\\s*?\\$\\s*?\\(\\s*?(?:'|\")\\s*?\\.slot\\s*?(?:'|\")\\s*?\\)\\[\\d\\]\\s*?\\)\\.html\\(\\s*?\\'\\
\\'\\s*?\\);/gi).length >= 3), 'Use the provided code three times. One for each slot.')",
- "assert(editor.match(/\\$\\s*?\\(\\s*?\\$\\s*?\\(\\s*?(?:'|\")\\s*?\\.slot\\s*?(?:'|\")\\s*?\\)\\[0\\]\\s*?\\)/gi), 'You should have used $('.slot')[0]
at least once.')",
- "assert(editor.match(/\\$\\s*?\\(\\s*?\\$\\s*?\\(\\s*?(?:'|\")\\s*?\\.slot\\s*?(?:'|\")\\s*?\\)\\[1\\]\\s*?\\)/gi), 'You should have used $('.slot')[1]
at least once.')",
- "assert(editor.match(/\\$\\s*?\\(\\s*?\\$\\s*?\\(\\s*?(?:'|\")\\s*?\\.slot\\s*?(?:'|\")\\s*?\\)\\[2\\]\\s*?\\)/gi), 'You should have used $('.slot')[2]
at least once.')",
- "assert(editor.match(/slotOne/gi) && editor.match(/slotOne/gi).length >= 7, 'You should have used the slotOne
value at least once.')",
- "assert(editor.match(/slotTwo/gi) && editor.match(/slotTwo/gi).length >= 8, 'You should have used the slotTwo
value at least once.')",
- "assert(editor.match(/slotThree/gi) && editor.match(/slotThree/gi).length >= 7, 'You should have used the slotThree
value at least once.')"
- ],
"challengeSeed": [
"fccss",
" function runSlots() {",
@@ -5035,8 +5122,21 @@
" }",
""
],
+ "solutions": [
+ ""
+ ],
+ "tests": [
+ "assert((editor.match(/\\$\\s*?\\(\\s*?\\$\\s*?\\(\\s*?(?:'|\")\\s*?\\.slot\\s*?(?:'|\")\\s*?\\)\\[\\d\\]\\s*?\\)\\.html\\(\\s*?\\'\\
\\'\\s*?\\);/gi) && editor.match(/\\$\\s*?\\(\\s*?\\$\\s*?\\(\\s*?(?:'|\")\\s*?\\.slot\\s*?(?:'|\")\\s*?\\)\\[\\d\\]\\s*?\\)\\.html\\(\\s*?\\'\\
\\'\\s*?\\);/gi).length >= 3), 'Use the provided code three times. One for each slot.')",
+ "assert(editor.match(/\\$\\s*?\\(\\s*?\\$\\s*?\\(\\s*?(?:'|\")\\s*?\\.slot\\s*?(?:'|\")\\s*?\\)\\[0\\]\\s*?\\)/gi), 'You should have used $('.slot')[0]
at least once.')",
+ "assert(editor.match(/\\$\\s*?\\(\\s*?\\$\\s*?\\(\\s*?(?:'|\")\\s*?\\.slot\\s*?(?:'|\")\\s*?\\)\\[1\\]\\s*?\\)/gi), 'You should have used $('.slot')[1]
at least once.')",
+ "assert(editor.match(/\\$\\s*?\\(\\s*?\\$\\s*?\\(\\s*?(?:'|\")\\s*?\\.slot\\s*?(?:'|\")\\s*?\\)\\[2\\]\\s*?\\)/gi), 'You should have used $('.slot')[2]
at least once.')",
+ "assert(editor.match(/slotOne/gi) && editor.match(/slotOne/gi).length >= 7, 'You should have used the slotOne
value at least once.')",
+ "assert(editor.match(/slotTwo/gi) && editor.match(/slotTwo/gi).length >= 8, 'You should have used the slotTwo
value at least once.')",
+ "assert(editor.match(/slotThree/gi) && editor.match(/slotThree/gi).length >= 7, 'You should have used the slotThree
value at least once.')"
+ ],
"type": "waypoint",
- "challengeType": "0"
+ "challengeType": "0",
+ "isBeta": "true"
}
]
-}
+}
\ No newline at end of file