diff --git a/challenges/01-front-end-development-certification/basic-javascript.json b/challenges/01-front-end-development-certification/basic-javascript.json
index 2763f16f4e..305ea24fd4 100644
--- a/challenges/01-front-end-development-certification/basic-javascript.json
+++ b/challenges/01-front-end-development-certification/basic-javascript.json
@@ -13,7 +13,8 @@
"// This is a comment.
",
"The slash-star-star-slash comment will comment out everything between the /*
and the */
characters:",
"/* This is also a comment */
",
- "
//
style comment that contains at least five letters.');",
@@ -29,7 +30,8 @@
"description": [
"In computer science, data structures
are things that hold data. JavaScript has seven of these. For example, the Number
data structure holds numbers.",
"Let's learn about the most basic data structure of all: the Boolean
. Booleans can only hold the value of either true or false. They are basically little on-off switches.",
- "welcomeToBooleans
function so that it will return true
instead of false
when the run button is clicked."
+ "welcomeToBooleans
function so that it will return 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.');",
@@ -58,7 +60,8 @@
"When we store data in a data structure
, we call it a variable
. These variables are no different from the x and y variables you use in math.",
"Let's create our first variable and call it \"myName\".",
"You'll notice that in myName
, we didn't use a space, and that the \"N\" is capitalized. JavaScript variables are written in camel case
. An example of camel case is: camelCase.",
- "var
keyword to create a variable called myName
. Set its value to your name, in double quotes.",
+ "var
keyword to create a variable called myName
. Set its value to your name, in double quotes.",
"Hint",
"Look at the ourName
example if you get stuck."
],
@@ -89,7 +92,8 @@
"myVar = 5;
",
"myNum = myVar;
",
"Assigns 5
to myVar
and then resolves myVar
to 5
again and assigns it to myNum
.",
- "a
",
+ "a
",
"Assign the contents of a
to variable b
."
],
"releasedOn": "11/27/2015",
@@ -133,7 +137,8 @@
"var myVar = 0;
",
"Creates a new variable called myVar
and assigns it an inital value of 0
.",
"",
- "a
with var
and initialize it to a value of 9
."
+ "a
with var
and initialize it to a value of 9
."
],
"releasedOn": "11/27/2015",
"tests": [
@@ -165,7 +170,8 @@
"title": "Understanding Uninitialized Variables",
"description": [
"When Javascript variables are declared, they have an inital value of undefined. If you do a mathematical operation on an undefined
variable your result will be NaN which means \"Not a Number\". If you concatanate a string with an undefined
variable, you will get a literal string of \"undefined\".",
- "a
, b
, and c
with 5
, 10
, and \"I am a\"
respectively so that they will not be undefined
."
+ "a
, b
, and c
with 5
, 10
, and \"I am a\"
respectively so that they will not be undefined
."
],
"releasedOn": "11/27/2015",
"tests": [
@@ -214,7 +220,8 @@
"MYVAR
is not the same as MyVar
nor myvar
. It is possible to have mulitpe distinct variables with the same name but different capitalization. It is strongly reccomended that for sake of clarity you do not use this language feature.",
"var someVariable;var anotherVariableName;var thisVariableNameIsTooLong;", - "
+
symbol for addition.",
- "0
so that sum will equal 20
."
+ "0
so that sum will equal 20
."
],
"tests": [
"assert(sum === 20, 'message: sum
should equal 20
');",
@@ -280,7 +288,8 @@
"description": [
"We can also subtract one number from another.",
"JavaScript uses the -
symbol for subtraction.",
- "0
so that difference will equal 12
."
+ "0
so that difference will equal 12
."
],
"tests": [
"assert(difference === 12, 'message: Make the variable difference
equal 12.');",
@@ -306,7 +315,8 @@
"description": [
"We can also multiply one number by another.",
"JavaScript uses the *
symbol for multiplication.",
- "0
so that product will equal 80
."
+ "0
so that product will equal 80
."
],
"tests": [
"assert(product === 80,'message: Make the variable product
equal 80');",
@@ -332,7 +342,8 @@
"description": [
"We can also divide one number by another.",
"JavaScript uses the /
symbol for division.",
- "0
so that quotient will equal 2
."
+ "0
so that quotient will equal 2
."
],
"tests": [
"assert(quotient === 2, 'message: Make the variable quotient
equal 2.');",
@@ -357,7 +368,8 @@
"i++;
",
"is the equivilent of",
"i = i + 1;
",
- "++
operator on myVar
"
+ "++
operator on myVar
"
],
"releasedOn": "11/27/2015",
"tests": [
@@ -395,7 +407,8 @@
"i--;
",
"is the equivilent of",
"i = i - 1;
",
- "--
operator on myVar
"
+ "--
operator on myVar
"
],
"releasedOn": "11/27/2015",
"tests": [
@@ -506,7 +519,8 @@
"Math.floor(5 / 2) === 2
2 * 2 === 4
5 - 4 === 1
",
"Usage",
"Modulus can be helpful in creating alternating or cycling values. For example, in a loop an increasing variable myVar % 2
will alternate between 0 and 1 as myVar goes between even and odd numbers respectively.",
- "remainder
equal to the remainder of 11 divided by 3 using the modulus operator."
+ "remainder
equal to the remainder of 11 divided by 3 using the modulus operator."
],
"releasedOn": "11/27/2015",
"tests": [
@@ -545,7 +559,8 @@
"to add 5
to myVar
. Since this is such a common pattern, there are operators which do both a mathematical operation and assignement in one step.",
"One such operator is the +=
operator.",
"myVar += 5;
will add 5
to myVar
.",
- "a
, b
, and c
to use the +=
operator."
+ "a
, b
, and c
to use the +=
operator."
],
"releasedOn": "11/27/2015",
"tests": [
@@ -595,7 +610,8 @@
"myVar = myVar - 5;
",
"Will subtract 5
from myVar
. This can be rewritten as: ",
"myVar -= 5;
",
- "a
, b
, and c
to use the -=
operator."
+ "a
, b
, and c
to use the -=
operator."
],
"releasedOn": "11/27/2015",
"tests": [
@@ -648,7 +664,8 @@
"myVar = myVar * 5;
",
"Will multiply myVar
by 5
. This can be rewritten as: ",
"myVar *= 5;
",
- "a
, b
, and c
to use the *=
operator."
+ "a
, b
, and c
to use the *=
operator."
],
"releasedOn": "11/27/2015",
"tests": [
@@ -699,7 +716,8 @@
"myVar = myVar / 5;
",
"Will divide myVar
by 5
. This can be rewritten as: ",
"myVar /= 5;
",
- "a
, b
, and c
to use the /=
operator."
+ "a
, b
, and c
to use the /=
operator."
],
"releasedOn": "11/27/2015",
"tests": [
@@ -797,7 +815,8 @@
"title": "Declare String Variables",
"description": [
"Previously we have used the code var myName = \"your name\"
. This is what we call a String
variable. It is nothing more than a \"string\" of characters. JavaScript strings are always wrapped in quotes.",
- "myFirstName
and myLastName
and assign them the values of your first and last name, respectively."
+ "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.');",
@@ -829,7 +848,8 @@
"description": [
"When you are defining a string you must start and end with a double or single quote. What happens when you need a literal quote inside of your string?",
"In Javascript you can escape a quote inside a string by placing a backslash (\\
) in front of the quote. This signals Javascript that the following quote is not the end of the string, but should instead should appear inside the string.",
- "myStr
:\"I am a \"double quoted\" string inside \"double quotes\"\"
"
+ "myStr
:\"I am a \"double quoted\" string inside \"double quotes\"\"
"
],
"releasedOn": "11/27/2015",
"tests": [
@@ -859,7 +879,8 @@
"\"This string has \\\"double quotes\\\" in it\"
",
"The value in using one or the other has to do with the need to escape quotes of the same type. If you have a string with many double quotes, this can be difficult to write and to read. Instead, use single quotes:",
"'This string has \"double quotes\" in it'
",
- "Code | Output |
---|---|
\\' | single quote |
\\\" | double quote |
\\\\ | backslash |
\\n | new line |
\\r | carriage return |
\\t | tab |
\\b | backspace |
\\f | form feed |
backslash tab tab carriage return new line
and assign it to myStr
"
+ "backslash tab tab carriage return new line
and assign it to myStr
"
],
"releasedOn": "11/27/2015",
"tests": [
@@ -916,7 +938,8 @@
"title": "Concatanting Strings with the Plus Operator",
"description": [
"In Javascript the +
operator for strings is called the concatanation operator. You can build strings out of other strings by concatanating them together.",
- "myStr
from the strings \"This is the start. \"
and \"This is the end.\"
using the +
operator.",
+ "myStr
from the strings \"This is the start. \"
and \"This is the end.\"
using the +
operator.",
""
],
"releasedOn": "11/27/2015",
@@ -986,7 +1009,8 @@
"title": "Constructing Strings with Variables",
"description": [
"Sometimes you will need to build a string, Mad Libs style. By using the concatanation operator (+
) you can insert one or more varaibles into a string you're building.",
- "myName
and build myStr
with myName
between the strings \"My name is \"
and \" and I am swell!\"
"
+ "myName
and build myStr
with myName
between the strings \"My name is \"
and \" and I am swell!\"
"
],
"releasedOn": "11/27/2015",
"tests": [
@@ -1021,7 +1045,8 @@
"title": "Appending Variables to Strings",
"description": [
"Just as we can build a string over multiple lines out of string literals, we can also append variables to a string using the plus equals (+=
) operator.",
- "someAdjective
and append it to myStr
using the +=
operator."
+ "someAdjective
and append it to myStr
using the +=
operator."
],
"releasedOn": "11/27/2015",
"tests": [
@@ -1063,7 +1088,8 @@
"description": [
"Data structures
have properties
. For example, strings
have a property called .length
that will tell you how many characters are in the string.",
"For example, if we created a variable var firstName = \"Charles\"
, we could find out how long the string \"Charles\" is by using the firstName.length
property.",
- ".length
property to count the number of characters in the lastName
variable and assign it to lastNameLength
."
+ ".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.');",
@@ -1100,7 +1126,8 @@
"Bracket notation
is a way to get a character at a specific index
within a string.",
"Computers don't start counting at 1 like humans do. They start at 0. This is refered to as Zero-based indexing.",
"For example, the character at index 0 in the word \"Charles\" is \"C\". So if var firstName = \"Charles\"
, you can get the value of the first letter of the string by using firstName[0]
.",
- "bracket notation
to find the first character in the lastName
variable and assign it to firstLetterOfLastName
.",
+ "bracket notation
to find the first character in the lastName
variable and assign it to firstLetterOfLastName
.",
"HintfirstLetterOfFirstName
variable declaration if you get stuck."
],
"tests": [
@@ -1142,7 +1169,8 @@
"var myStr = \"Bob\";
myStr[0] = \"J\";
",
"will not change the contents of myStr
to \"Job\", because the contents of myStr cannot be altered. Note that this does not mean that myStr
cannot be change, just that individual characters cannot be changes. The only way to change myStr
would be to overwrite the contents with a new string, like this:",
"var myStr = \"Bob\";
myStr = \"Job\";
",
- "myStr
to achieve the desired effect."
+ "myStr
to achieve the desired effect."
],
"releasedOn": "11/27/2015",
"tests": [
@@ -1180,7 +1208,8 @@
"description": [
"You can also use bracket notation
to get the character at other positions within a string.",
"Remember that computers start counting at 0, so the first character is actually the zeroth character.",
- "thirdLetterOfLastName
to equal the third letter
of the lastName
variable.",
+ "thirdLetterOfLastName
to equal the third letter
of the lastName
variable.",
"HintsecondLetterOfFirstName
variable declaration if you get stuck."
],
"tests": [
@@ -1215,7 +1244,8 @@
"description": [
"In order to get the last letter of a string, you can subtract one from the string's length.",
"For example, if var firstName = \"Charles\"
, you can get the value of the last letter of the string by using firstName[firstName.length - 1]
.",
- "bracket notation
to find the last character in the lastName
variable.",
+ "bracket notation
to find the last character in the lastName
variable.",
"HintlastLetterOfFirstName
variable declaration if you get stuck."
],
"tests": [
@@ -1251,7 +1281,8 @@
"description": [
"You can use the same principle we just used to retrieve the last character in a string to retrieve the Nth-to-last character.",
"For example, you can get the value of the third-to-last letter of the var firstName = \"Charles\"
string by using firstName[firstName.length - 3]
",
- "bracket notation
to find the second-to-last character in the lastName
string.",
+ "bracket notation
to find the second-to-last character in the lastName
string.",
" HintthirdToLastLetterOfFirstName
variable declaration if you get stuck."
],
"tests": [
@@ -1336,7 +1367,8 @@
"description": [
"With JavaScript array
variables, we can store several pieces of data in one place.",
"You start an array declaration with an opening square bracket, end it with a closing square bracket, and put a comma between each entry, like this:var sandwich = [\"peanut butter\", \"jelly\", \"bread\"]
.",
- "myArray
that contains both a string
and a number
(in that order).",
+ "myArray
that contains both a string
and a number
(in that order).",
"Hint[[\"Bulls\", 23]]
. This is also called a Multi-dimensional Array.",
- "myArray
."
+ "myArray
."
],
"tests": [
"assert(Array.isArray(myArray) && myArray.some(Array.isArray), 'message: myArray
should have at least one array nested within another array.');"
@@ -1398,7 +1431,8 @@
"var array = [1,2,3];
",
"array[0]; //equals 1
",
"var data = array[1];
",
- "myData
and set it to equal the first value of myArray
."
+ "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
.');"
@@ -1432,7 +1466,8 @@
"For example:",
"var ourArray = [3,2,1];
",
"ourArray[0] = 1; // equals [1,2,1]
",
- "0
of myArray
to a value of 3
."
+ "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].');",
@@ -1470,7 +1505,8 @@
"arr[0]; // equals [1,2,3]
",
"arr[1][2]; // equals 6
",
"arr[3][0][1]; // equals 11
",
- "myArray
using bracket notation so that myData is equal to 8
"
+ "myArray
using bracket notation so that myData is equal to 8
"
],
"tests": [
"assert(myData === 8, 'message: myData
should be equal to 8
.');",
@@ -1502,7 +1538,8 @@
"var arr = [1,2,3];
",
"arr.push(4);
",
"// arr is now [1,2,3,4]
",
- "[\"dog\", 3]
onto the end of the myArray
variable."
+ "[\"dog\", 3]
onto the end of the myArray
variable."
],
"tests": [
"\nassert((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]]
.');"
@@ -1537,7 +1574,8 @@
"Another way to change the data in an array is with the .pop()
function. ",
".pop()
is used to \"pop\" a value off of the end of an array. We can store this \"popped off\" variable by performing pop()
within a variable declaration.",
"Any type of data structure can be \"popped\" off of an array - numbers, strings, even nested arrays.",
- ".pop()
function to remove the last item from myArray
, assigning the \"popped off\" value to removedFromMyArray
."
+ ".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]]
.');",
@@ -1572,7 +1610,8 @@
"description": [
"pop()
always removes the last element of an array. What if you want to remove the first?",
"That's where .shift()
comes in. It works just like .pop()
, except it removes the first element instead of the last.",
- ".shift()
function to remove the first item from myArray
, assigning the \"shifted off\" value to removedFromMyArray
."
+ ".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]]
.');",
@@ -1610,7 +1649,8 @@
"description": [
"Not only can you shift
elements off of the beginning of an array, you can also unshift
elements onto the beginning of an array.",
"unshift()
works exactly like push()
, but instead of adding the element at the end of the array, unshift()
adds the element at the beginning of the array.",
- "[\"Paul\",35]
onto the beginning of the myArray
variable using unshift()
."
+ "[\"Paul\",35]
onto 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]]).');"
@@ -1713,7 +1753,8 @@
"You can call or invoke this function by using its name followed by parentheses, like this:",
"functionName();
",
"Each time the function is called it will print out the message \"Hello World\" on the dev console. All of the code between the curly braces will be executed every time the function is called.",
- "myFunction
which prints \"Hi World\" to the dev console. Call that function."
+ "myFunction
which prints \"Hi World\" to the dev console. Call that function."
],
"tests": [
"assert(typeof myFunction === 'function', 'message: myFunction
should be a function');",
@@ -1773,7 +1814,8 @@
"Then we can call testFun
:",
"testFun(\"Hello\", \"World\");
",
"We have passed two arguments, \"Hello\" and \"World\". Inside the function, param1
will equal \"Hello\" and param2
will equal \"World\". Note that you could call testFun
again with different arguments and the parameters would take on the value of the new arguments.",
- "myFunction
that accepts two arguments and outputs their sum to the dev console. Call your function."
+ "myFunction
that accepts two arguments and outputs their sum to the dev console. Call your function."
],
"releasedOn": "11/27/2015",
"tests": [
@@ -1835,7 +1877,8 @@
"description": [
"In Javascript, scope refers to the visibility of variables. Variables which are defined outside of a function block have Global scope. This means the can be seen everywhere in your Javascript code. ",
"Variables which are used without the var
keyword are automatically created in the global
scope. This can create unintended concequences elsewhere in your code or when running a function again. You should always declare your variables with var
.",
- "global
variable myGlobal
outside of any function. Initialize it to have a value of 10
",
+ "global
variable myGlobal
outside of any function. Initialize it to have a value of 10
",
"Inside function fun1
, assign 5
to oopsGlobal
without using the var
keyword."
],
"releasedOn": "11/27/2015",
@@ -1907,7 +1950,8 @@
"Here is a function myTest
with a local variable called loc
.",
"function myTest() {", "
var local1 = \"foo\";
console.log(local1);
}
myTest(); // \"foo\"
console.log(local1); // \"undefined\"
local1
is not defined outside of the function.",
- "myVar
inside myFunction
"
+ "myVar
inside myFunction
"
],
"releasedOn": "11/27/2015",
"tests": [
@@ -1940,7 +1984,12 @@
"id": "56533eb9ac21ba0edf2244c0",
"title": "Global vs. Local Scope in Functions",
"description": [
- "Show how global and local scopes interact"
+ "It is possible to have both a local and global variables with the same name. When you do this, the local
variable takes precedence over the global
variable.",
+ "In this example:",
+ "var someVar = \"Hat\";", + "The function
function myFun() {
var someVar = \"Head\";
return someVar;
}
myFun
will return \"Head\"
because the local
version of the variable is present.",
+ "myFunction
to override the value of "
],
"releasedOn": "11/27/2015",
"tests": [
@@ -1999,7 +2048,8 @@
"For Example:",
"function plusThree(num) {
return num + 3;
}
var answer = plusThree(5); // 8
",
"plusThree
takes an argument for num
and returns a value equal to num + 3
.",
- "Instructions
Create a function timesFive
that accepts one argument, multiplies it by 5
, and returns the new value."
+ "Instructions
",
+ "Create a function timesFive
that accepts one argument, multiplies it by 5
, and returns the new value."
],
"releasedOn": "11/27/2015",
"tests": [
@@ -2168,7 +2218,8 @@
"For example:",
"function test(myVal) {
if (myVal > 10) {
return \"Greater Than\";
}
return \"Not Greater Than\";
}
",
"If myVal
is greater than 10
, the function will return \"Greater Than\". If it is not, the function will return \"Not Greater Than\".",
- "Instructions
Create an if
statement inside the function to return \"Yes\"
if testMe
is greater than 5
. Return \"No\"
if it is less than 5
."
+ "Instructions
",
+ "Create an if
statement inside the function to return \"Yes\"
if testMe
is greater than 5
. Return \"No\"
if it is less than 5
."
],
"tests": [
"assert(typeof myFunction === \"function\", 'message: myFunction
should be a function');",
@@ -2222,7 +2273,8 @@
"If myVal
is equal to 10
, the function will return \"Equal\". If it is not, the function will return \"Not Equal\".",
"The equality operator will do it's best to convert values for comparison, for example:",
" 1 == 1 // true
\"1\" == 1 // true
1 == '1' // true
0 == false // true
0 == null // false
0 == undefined // false
null == undefined // true
",
- "Instructions
Add the equality operator
to the indicated line so the function will return \"Equal\" when val
is equivilent to 12
"
+ "Instructions
",
+ "Add the equality operator
to the indicated line so the function will return \"Equal\" when val
is equivilent to 12
"
],
"releasedOn": "11/27/2015",
"tests": [
@@ -2265,7 +2317,8 @@
"description": [
"Strict equality (===
) is the counterpart to the equality operator (==
). Unlike the equality operator, strict equality tests both the type and value of the compared elements.",
"Examples3 === 3 // true
3 === '3' // false
",
- "Instructions
Change the equality operator to a strict equality on the if
statement so the function will return \"Equal\" when val
is strictltly equal to 7
"
+ "Instructions
",
+ "Change the equality operator to a strict equality on the if
statement so the function will return \"Equal\" when val
is strictltly equal to 7
"
],
"releasedOn": "11/27/2015",
"tests": [
@@ -2308,7 +2361,8 @@
"description": [
"The inequality operator (!=
) is the opposite of the equality operator. It means \"Not Equal\" and returns false
where equality would return true
and vice versa. Like the equality operator, the inequality operator will convert types.",
"Examples1 != 2 // true
1 != \"1\" // false
1 != '1' // false
1 != true // false
0 != false // false
",
- "Instructions
Add the inequality operator !=
to the if
statement so the function will return \"Not Equal\" when val
is not equivilent to 99
"
+ "Instructions
",
+ "Add the inequality operator !=
to the if
statement so the function will return \"Not Equal\" when val
is not equivilent to 99
"
],
"releasedOn": "11/27/2015",
"tests": [
@@ -2353,7 +2407,8 @@
"description": [
"The inequality operator (!==
) is the opposite of the strict equality operator. It means \"Strictly Not Equal\" and returns false
where strict equality would return true
and vice versa. Strict inequality will not convert types.",
"Examples3 !== 3 // false
3 !== '3' // true
4 !== 3 // true
",
- "Instructions
Add the strict inequality operator
to the if
statement so the function will return \"Not Equal\" when val
is not strictly equal to 17
"
+ "Instructions
",
+ "Add the strict inequality operator
to the if
statement so the function will return \"Not Equal\" when val
is not strictly equal to 17
"
],
"releasedOn": "11/27/2015",
"tests": [
@@ -2402,7 +2457,8 @@
"description": [
"The greater than operator (>
) compares the values of two numbers. If the number to the left is greater than the number to the right, it returns true
. If the number on the left is less than or equal to the number on the right, it returns false
. Like the equality operator, greater than converts data types.",
"Examples 5 > 3 // true
7 > '3' // true
2 > 3 // false
'1' > 9 // false
",
- "Instructions
Add the greater than
operator to the indicated lines so that the return statements make sense."
+ "Instructions
",
+ "Add the greater than
operator to the indicated lines so that the return statements make sense."
],
"releasedOn": "11/27/2015",
"tests": [
@@ -2455,7 +2511,8 @@
"description": [
"The greater than equal to operator (>=
) compares the values of two numbers. If the number to the left is greater than or equal the number to the right, it returns true
. If the number on the left is less than the number on the right, it returns false
. Like the equality operator, greater than equal to converts data types.",
"Examples 6 >= 6 // true
7 >= '3' // true
2 >= 3 // false
'7' >= 9 // false
",
- "Instructions
Add the greater than equal to
operator to the indicated lines so that the return statements make sense."
+ "Instructions
",
+ "Add the greater than equal to
operator to the indicated lines so that the return statements make sense."
],
"releasedOn": "11/27/2015",
"tests": [
@@ -2501,7 +2558,8 @@
"description": [
"The less than
operator (<
) compares the values of two numbers. If the number to the left is less than the number to the right, it returns true
. If the number on the left is greater than or equal to the number on the right, it returns false
. Like the equality operator, less than
converts data types.",
"Examples 2 < 5 // true
'3' < 7 // true
5 < 5 // false
3 < 2 // false
'8' < 4 // false
",
- "Instructions
Add the less than
operator to the indicated lines so that the return statements make sense."
+ "Instructions
",
+ "Add the less than
operator to the indicated lines so that the return statements make sense."
],
"releasedOn": "11/27/2015",
"tests": [
@@ -2546,7 +2604,8 @@
"description": [
"The less than equal to
operator (<=
) compares the values of two numbers. If the number to the left is less than or equl the number to the right, it returns true
. If the number on the left is greater than the number on the right, it returns false
. Like the equality operator, less than equal to
converts data types.",
"Examples 4 <= 5 // true
'7' <= 7 // true
5 <= 5 // true
3 <= 2 // false
'8' <= 4 // false
",
- "Instructions
Add the less than equal to
operator to the indicated lines so that the return statements make sense."
+ "Instructions
",
+ "Add the less than equal to
operator to the indicated lines so that the return statements make sense."
],
"releasedOn": "11/27/2015",
"tests": [
@@ -2593,7 +2652,8 @@
"Sometimes you will need to test more than one thing at a time. The logical and operator (&&
) returns true
if and only if the operands to the left and right of it are true.",
"The same effect could be achieved by nesting an if statement inside another if:",
"if (num < 10) {
if (num > 5) {
return \"Yes\";
}
}
return \"No\";
Will only return \"Yes\" if num
is between 6
and 9
. The same logic can be written as:if (num < 10 && num > 5) {
return \"Yes\";
}return \"No\";
",
- "Instructions
Combine the two if statements into one statement which returns \"Yes\"
if val
is less than or equal to 50
and greater than or equal to 25
. Otherwise, return \"No\"
."
+ "Instructions
",
+ "Combine the two if statements into one statement which returns \"Yes\"
if val
is less than or equal to 50
and greater than or equal to 25
. Otherwise, return \"No\"
."
],
"releasedOn": "11/27/2015",
"tests": [
@@ -2648,7 +2708,8 @@
"The logical or operator (||
) returns true
if either ofoperands is true, or false if neither is true.",
"The pattern below should look familiar from prior waypoints:",
"if (num > 10) {
return \"No\";
}
if (num < 5) {
return \"No\";
}
return \"Yes\";
Will only return \"Yes\" if num
is between 5
and 10
. The same logic can be written as:if (num > 10 || num < 5) {
return \"No\";
}return \"Yes\";
",
- "Instructions
Combine the two if statements into one statement which returns \"Inside\"
if val
is between 10
and 20
, inclusive. Otherwise, return \"Outside\"
."
+ "Instructions
",
+ "Combine the two if statements into one statement which returns \"Inside\"
if val
is between 10
and 20
, inclusive. Otherwise, return \"Outside\"
."
],
"releasedOn": "11/27/2015",
"tests": [
@@ -2775,7 +2836,8 @@
"description": [
"When a condition for an if
statement is true, the block of code following it is executed. What about when that condition is false? Normally nothing would happen. With an else
statement, an alternate block of code can be executed.",
"if (num > 10) {
return \"Bigger than 10\";
} else {
return \"10 or Less\";
}
",
- "Instructions
Combine the if
statements into a single statement."
+ "Instructions
",
+ "Combine the if
statements into a single statement."
],
"releasedOn": "11/27/2015",
"tests": [
@@ -2887,7 +2949,8 @@
"description": [
"if...else if
statements can be chained together for complex logic. Here is pseudocode of multiple chained if
/else if
statements:",
"if(condition1) {
statement1
} else if (condition1) {
statement1
} else if (condition3) {
statement3
. . .
} else {
statementN
}
",
- "Instructions
Write chained if
/else if
statements to fulfill the following conditions:",
+ "Instructions
",
+ "Write chained if
/else if
statements to fulfill the following conditions:",
"num < 5
- return \"Tiny\"
num < 10
- return \"Small\"
num < 15
- return \"Medium\"
num < 20
- return \"Large\"
num >= 20
- return \"Huge\""
],
"releasedOn": "11/27/2015",
@@ -2948,7 +3011,8 @@
"If you have many options to choose from use a switch
statement A switch
statement tests a value and has many case
statements which define that value can be, shown here in pseudocode:",
"switch (num) {
case value1:
statement1
break;
value2:
statement2;
break;
...
valueN:
statementN;
}
",
"case
values are tested with strict equality (===
). The break
tells Javascript to stop executing statements. If the break
is omitted, the next statement will be executed.",
- "Instructions
Write a switch statement to set answer
for the following conditions:
1
- \"alpha\"
2
- \"beta\"
3
- \"gamma\"
4
- \"delta\""
+ "Instructions
",
+ "Write a switch statement to set answer
for the following conditions:
1
- \"alpha\"
2
- \"beta\"
3
- \"gamma\"
4
- \"delta\""
],
"releasedOn": "11/27/2015",
"tests": [
@@ -3009,7 +3073,8 @@
"In a switch
statement you may not be able to specify all possible values as case
statements. Instead, you can use the default
statement where a case
would go. Think of it like an else
statement for switch
.",
"A default
statement should be the last \"case
\" in the list.",
"switch (num) {
case value1:
statement1
break;
value2:
statement2;
break;
...
default:
defaultStatement;
}
",
- "Instructions
Write a switch statement to set answer
for the following conditions:
\"a\"
- \"apple\"
\"b\"
- \"bird\"
\"c\"
- \"cat\"
default
- \"stuff\""
+ "Instructions
",
+ "Write a switch statement to set answer
for the following conditions:
\"a\"
- \"apple\"
\"b\"
- \"bird\"
\"c\"
- \"cat\"
default
- \"stuff\""
],
"releasedOn": "11/27/2015",
"tests": [
@@ -3071,7 +3136,8 @@
"If the break
statement is ommitted from a switch
statement case
, the following case
statement(s). If you have mutiple inputs with the same output, you can represent them in a switch
statement like this:",
"switch(val) {
case 1:
case 2:
case 3:
result = \"1, 2, or 3\";
break;
case 4:
result = \"4 alone\";
}
",
"Cases for 1, 2, and 3 will all produce the same result.",
- "Instructions
Write a switch statement to set answer
for the following ranges:
1-3
- \"Low\"
4-6
- \"Mid\"
7-9
- \"High\"",
+ "Instructions
",
+ "Write a switch statement to set answer
for the following ranges:
1-3
- \"Low\"
4-6
- \"Mid\"
7-9
- \"High\"",
"Note
You will need to have a case
statement for each number in the range."
],
"releasedOn": "11/27/2015",
@@ -3143,7 +3209,8 @@
"if(val === 1) {
answer = \"a\";
} else if(val === 2) {
answer = \"b\";
} else {
answer = \"c\";
}
",
"can be replaced with:",
"switch (val) {
case 1:
answer = \"a\";
break;
case 2:
answer = \"b\";
break;
default:
answer = \"c\";
}
",
- "Instructions
Change the chained if
/if else
statements into a switch
statement."
+ "Instructions
",
+ "Change the chained if
/if else
statements into a switch
statement."
],
"releasedOn": "11/27/2015",
"tests": [
@@ -3287,7 +3354,8 @@
"Here's a sample object:",
"var cat = {
\"name\": \"Whiskers\",
\"legs\": 4,
\"tails\": 1,
\"enemies\": [\"Water\", \"Dogs\"]
};
",
"Objects are useful for storing data in a structured way, and can represent real world objects, like a cat.",
- "Instructions
Make an object that represents a dog called myDog
which contains the properties \"name\"
(a string), \"legs\"
, \"tails\"
and \"friends\"
.",
+ "Instructions
",
+ "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": [
@@ -3331,7 +3399,8 @@
"The dot operator is what you use when you know the name of the property you're trying to access ahead of time.",
"Here is a sample of using the .
to read an object property:",
"var myObj = {
prop1: \"val1\",
prop2: \"val2\"
};
myObj.prop1; // val1
myObj.prop2; // val2
",
- "Instructions
Read the values of the properties hat
and shirt
of testObj
using dot notation."
+ "Instructions
",
+ "Read the values of the properties hat
and shirt
of testObj
using dot notation."
],
"releasedOn": "11/27/2015",
"tests": [
@@ -3382,7 +3451,8 @@
"Here is a sample of using bracket notation to read an object property:",
"var myObj = {
\"Space Name\": \"Kirk\",
\"More Space\": \"Spock\"
};
myObj[\"Space Name\"]; // Kirk
myObj['More Space']; // Spock
",
"Note that property names with spaces in them must be in quotes (single or double).",
- "Instructions
Read the values of the properties \"an entree\"
and \"the drink\"
of testObj
using bracket notation."
+ "Instructions
",
+ "Read the values of the properties \"an entree\"
and \"the drink\"
of testObj
using bracket notation."
],
"releasedOn": "11/27/2015",
"tests": [
@@ -3433,7 +3503,8 @@
"Here is an example of using a variable to access a property:",
"var someProp = \"propName\";
var myObj = {
propName: \"Some Value\"
}
myObj[someProp]; // \"Some Value\"
",
"Note that we do not use quotes around the variable name when using it to access the property because we are using the value of the variable, not the name",
- "Instructions
Use the playerNumber
variable to lookup player 16
in testObj
using bracket notation."
+ "Instructions
",
+ "Use the playerNumber
variable to lookup player 16
in testObj
using bracket notation."
],
"releasedOn": "11/27/2015",
"tests": [
@@ -3480,7 +3551,8 @@
"ourDog.name = \"Happy Camper\";
or",
"outDog[\"name\"] = \"Happy Camper\";
",
"Now when we evaluate ourDog.name
, instead of getting \"Camper\", we'll get his new name, \"Happy Camper\".",
- "Instructions
Update the myDog
object's name property. Let's change her name from \"Coder\" to \"Happy Coder\". You can use either dot or bracket notation."
+ "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\".');",
@@ -3525,7 +3597,8 @@
"or",
"ourDog[\"bark\"] = \"bow-wow\";
",
"Now when we evaluate ourDog.bark
, we'll get his bark, \"bow-wow\".",
- "Instructions
Add a \"bark\"
property to myDog
and set it to a dog sound, such as \"woof\". You may use either dot or bracket notation."
+ "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
.');",
@@ -3574,7 +3647,8 @@
"description": [
"We can also delete properties from objects like this:",
"delete ourDog.bark;
",
- "Instructions
Delete the \"tails\"
property from myDog
. You may use either dot or bracket notation."
+ "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
.');",
@@ -3629,7 +3703,8 @@
"Objects can be thought of as a key/value storage, like a dictonary. If you have tabular data, you can use an object to \"lookup\" values rather than a switch
statement or an if...else
chain. This is most useful when you know that your input data is limited to a certain range.",
"Here is an example of a simple reverse alphabet lookup:",
"var alpha = {
1:\"Z\"
2:\"Y\"
3:\"X\"
...
4:\"W\"
24:\"C\"
25:\"B\"
26:\"A\"
};
alpha[2]; // \"Y\"
alpha[24]; // \"C\"
",
- "Instructions
Convert the switch statement into a lookup table called lookup
. Use it to lookup val
and return the associated string."
+ "Instructions
",
+ "Convert the switch statement into a lookup table called lookup
. Use it to lookup val
and return the associated string."
],
"releasedOn": "11/27/2015",
"tests": [
@@ -3727,7 +3802,8 @@
"Here is an example of a JSON object:",
"var ourMusic = [
{
\"artist\": \"Daft Punk\",
\"title\": \"Homework\",
\"release_year\": 1997,
\"formats\": [
\"CD\",
\"Cassette\",
\"LP\" ],
\"gold\": true
}
];
",
"This is an array of objects and the object has various peices of metadata about an album. It also has a nested array of formats. Additional album records could be added to the top level array.",
- "Instructions
Add a new album to the myMusic
JSON object. Add artist
and title
strings, release_year
year, and a formats
array of strings."
+ "Instructions
",
+ "Add a new album to the myMusic
JSON object. Add artist
and title
strings, release_year
year, and a formats
array of strings."
],
"releasedOn": "11/27/2015",
"tests": [
@@ -3802,7 +3878,8 @@
"The properties and sub-properties of JSON objects can be accessed by chaining together the dot or bracket notation.",
"Here is a nested JSON Object:",
"var ourStorage = {
\"desk\": {
\"drawer\": \"stapler\"
},
\"cabinet\": {
\"top drawer\": {
\"folder1\": \"a file\",
\"folder2\": \"secrets\"
},
\"bottom drawer\": \"soda\"
}
}
ourStorage.cabinet[\"top drawer\"].folder2; // \"secrets\"
ourStoage.desk.drawer; // \"stapler\"
",
- "Instructions
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."
+ "Instructions
",
+ "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": "11/27/2015",
"tests": [
@@ -3860,7 +3937,8 @@
"As we have seen in earlier examples, JSON objects can contain both nested objects and nested arrays. Similar to accessing nested objects, Array bracket notation can be chained to access nested arrays.",
"Here is an example of how to access a nested array:",
"var ourPets = {
\"cats\": [
\"Meowzer\",
\"Fluffy\",
\"Kit-Cat\"
],
\"dogs:\" [
\"Spot\",
\"Bowser\",
\"Frankie\"
]
};
ourPets.cats[1]; // \"Fluffy\"
ourPets.dogs[0]; // \"Spot\"
",
- "Instructions
Retrieve the second tree using object dot and array bracket notation."
+ "Instructions
",
+ "Retrieve the second tree using object dot and array bracket notation."
],
"releasedOn": "11/27/2015",
"tests": [
@@ -3976,7 +4054,8 @@
"In the following example we initialize with i = 0
and iterate while our condition i < 5
is true. We'll increment i
by 1
in each loop iteration with i++
as our final-expression
.",
"var ourArray = [];
for (var i = 0; i < 5; i++) {
ourArray.push(i);
}
",
"ourArray
will now contain [0,1,2,3,4]
.",
- "Instructions
Use a for
loop to work to push the values 1 through 5 onto myArray
."
+ "Instructions
",
+ "Use a for
loop to work to push the values 1 through 5 onto myArray
."
],
"tests": [
"assert(editor.getValue().match(/for\\s*\\(/g).length > 1, 'message: You should be using a for
loop for this.');",
@@ -4012,7 +4091,8 @@
"var ourArray = [];
for (var i = 0; i < 10; i += 2) {
ourArray.push(i);
}
",
"ourArray
will now contain [0,2,4,6,8]
.",
"Let's change our initialization
so we can count by odd numbers.",
- "Instructions
Push the odd numbers from 1 through 9 to myArray
using a for
loop."
+ "Instructions
",
+"Push the odd numbers from 1 through 9 to myArray
using a for
loop."
],
"tests": [
"assert(editor.getValue().match(/for\\s*\\(/g).length > 1, 'message: You should be using a for
loop for this.');",
@@ -4049,7 +4129,8 @@
"var ourArray = [];
for (var i=10; i > 0; i-=2) {
ourArray.push(i);
}
",
"ourArray
will now contain [10,8,6,4,2]
.",
"Let's change our initialization
and final-expression
so we can count backward by twos by odd numbers.",
- "Instructions
Push the odd numbers from 9 through 1 to myArray
using a for
loop."
+ "Instructions
",
+"Push the odd numbers from 9 through 1 to myArray
using a for
loop."
],
"tests": [
"assert(editor.getValue().match(/for\\s*\\(/g).length > 1, 'message: You should be using a for
loop for this.');",
@@ -4082,7 +4163,8 @@
"A common task in Javascript is to iterate through the contents of an array. One way to do that is with a for
loop. This code will output each element of the array arr
to the console:",
"var arr = [10,9,8,7,6];
for (var i=0; i < arr.length; i++) {
console.log(arr[i]);
}
",
"Remember that Arrays have zero-based numbering, which means the last index of the array is length - 1. Our condition for this loop is i < arr.length
, which stops when i
is at length - 1.",
- "Instructions
Create a variable total
. Use a for
loop to add each element of myArr
to total."
+ "Instructions
",
+ "Create a variable total
. Use a for
loop to add each element of myArr
to total."
],
"releasedOn": "11/27/2015",
"tests": [
@@ -4132,7 +4214,8 @@
"If you have a multi-dimensional array, you can use the same logic as the prior waypoint to loop through both the array and any sub-arrays. Here is an example:",
"var arr = [
[1,2], [3,4], [5,6]
];
for (var i=0; i < arr.length; i++) {
for (var j=0; k < arr[i].length; j++) {
console.log(arr[i][j]);
}
}
",
"This outputs each sub-element in arr
one at a time. Note that for the inner loop we are checking the .length
of arr[i]
, since arr[i]
is itself an array.",
- "Instructions
The function multiplyAll
will be passed a multi-dimensional array, arr
. Loop through both levels of arr
and multiply product
by each one."
+ "Instructions
",
+ "Modify function multiplyAll
so that it multiplies product
by each number in the subarrays of arr
"
],
"releasedOn": "11/27/2015",
"tests": [
@@ -4187,7 +4270,8 @@
"Another type of JavaScript loop is called a \"while loop\", because it runs \"while\" something is true and stops once that something is no longer true.",
"var ourArray = [];
var i = 0;
while(i < 5) {
ourArray.push(i);
i++;
}
",
"Let's try getting a while loop to work by pushing values to an array.",
- "Instructions
Push the numbers 0 through 4 to myArray
using a while
loop."
+ "Instructions
",
+ "Push the numbers 0 through 4 to myArray
using a while
loop."
],
"tests": [
"assert(editor.getValue().match(/while/g), 'message: You should be using a while
loop for this.');",
@@ -5131,4 +5215,4 @@
"challengeType": "0"
}
]
-}
\ No newline at end of file
+}