merge staging and make my own minor improvements
This commit is contained in:
@ -4,10 +4,10 @@
|
||||
"time": "3h",
|
||||
"challenges": [
|
||||
{
|
||||
"id":"bd7123c9c441eddfaeb4bdef",
|
||||
"id": "bd7123c9c441eddfaeb4bdef",
|
||||
"title": "Comment your JavaScript Code",
|
||||
"difficulty":"9.98",
|
||||
"description":[
|
||||
"difficulty": "9.98",
|
||||
"description": [
|
||||
"Comments are lines of code that your computer will intentionally ignore. Comments are a great way to leave notes to yourself and to other people who will later need to figure out what it does.",
|
||||
"Let's take a look at the two ways you can write comments in JavaScript.",
|
||||
"The double-slash comment will comment out the remainder of the text on the current line:",
|
||||
@ -17,13 +17,12 @@
|
||||
"Try creating one of each.",
|
||||
"And one more thing you need to notice. Starting at this waypoint in JavaScript related challenges (except AngularJS, all Ziplines, Git, Node.js and Express.js, MongoDB and Full Stack JavaScript Projects) you can see contents of <code>assert()</code> functions (in some challenges <code>except()</code>, <code>assert.equal()</code> and so on) which are used to test your code. It's part of these challenges that you are able to see the tests that are running against your code."
|
||||
],
|
||||
"tests":[
|
||||
"tests": [
|
||||
"assert(editor.getValue().match(/(\\/\\/)...../g), 'message: Create a <code>//</code> style comment that contains at least five letters');",
|
||||
"assert(editor.getValue().match(/(\\/\\*)[\\w\\W]{5,}(?=\\*\\/)/gm), 'message: Create a <code>/* */</code> style comment that contains at least five letters.');",
|
||||
"assert(editor.getValue().match(/(\\*\\/)/g), 'message: Make sure that you close the comment with a <code>*/</code>');"
|
||||
],
|
||||
"challengeSeed":[
|
||||
],
|
||||
"challengeSeed": [],
|
||||
"type": "waypoint",
|
||||
"challengeType": 1
|
||||
},
|
||||
@ -432,17 +431,17 @@
|
||||
"challengeType": 1
|
||||
},
|
||||
{
|
||||
"id":"cf1111c1c11feddfaeb7bdef",
|
||||
"id": "cf1111c1c11feddfaeb7bdef",
|
||||
"title": "Nest one Array within Another Array",
|
||||
"difficulty":"9.98161",
|
||||
"description":[
|
||||
"difficulty": "9.98161",
|
||||
"description": [
|
||||
"You can also nest arrays within other arrays, like this: <code>[[\"Bulls\", 23]]</code>.",
|
||||
"Let's now go create a nested array called <code>myArray</code>."
|
||||
],
|
||||
"tests":[
|
||||
"tests": [
|
||||
"assert(Array.isArray(myArray) && myArray.some(Array.isArray), 'message: <code>myArray</code> should have at least one array nested within another array.');"
|
||||
],
|
||||
"challengeSeed":[
|
||||
"challengeSeed": [
|
||||
"var ourArray = [[\"the universe\", \"everything\", 42]];",
|
||||
"// Only change code below this line.",
|
||||
"",
|
||||
@ -457,10 +456,10 @@
|
||||
"challengeType": 1
|
||||
},
|
||||
{
|
||||
"id":"bg9997c9c79feddfaeb9bdef",
|
||||
"id": "bg9997c9c79feddfaeb9bdef",
|
||||
"title": "Access Array Data with Indexes",
|
||||
"difficulty":"9.9817",
|
||||
"description":[
|
||||
"difficulty": "9.9817",
|
||||
"description": [
|
||||
"We can access the data inside arrays using <code>indexes</code>.",
|
||||
"Array indexes are written in the same bracket notation that strings use, except that instead of specifying a character, they are specifying an entry in the array.",
|
||||
"For example:",
|
||||
@ -469,10 +468,10 @@
|
||||
"<code>var data = array[1];</code>",
|
||||
"Create a variable called <code>myData</code> and set it to equal the first value of <code>myArray</code>."
|
||||
],
|
||||
"tests":[
|
||||
"tests": [
|
||||
"assert((function(){if(typeof(myArray) != 'undefined' && typeof(myData) != 'undefined' && myArray[0] == myData){return true;}else{return false;}})(), 'message: The variable <code>myData</code> should equal the first value of <code>myArray</code>.');"
|
||||
],
|
||||
"challengeSeed":[
|
||||
"challengeSeed": [
|
||||
"// var ourArray = [1,2,3];",
|
||||
"// var ourData = ourArray[0]; // equals 1",
|
||||
"",
|
||||
@ -489,21 +488,21 @@
|
||||
"challengeType": 1
|
||||
},
|
||||
{
|
||||
"id":"cf1111c1c11feddfaeb8bdef",
|
||||
"id": "cf1111c1c11feddfaeb8bdef",
|
||||
"title": "Modify Array Data With Indexes",
|
||||
"difficulty":"9.98171",
|
||||
"description":[
|
||||
"difficulty": "9.98171",
|
||||
"description": [
|
||||
"We can also modify the data stored in arrays by using indexes.",
|
||||
"For example:",
|
||||
"<code>var ourArray = [3,2,1];</code>",
|
||||
"<code>ourArray[0] = 1; // equals [1,2,1]</code>",
|
||||
"Now modify the data stored at index 0 of <code>myArray</code> to the value of 3."
|
||||
],
|
||||
"tests":[
|
||||
"tests": [
|
||||
"assert((function(){if(typeof(myArray) != 'undefined' && myArray[0] == 3 && myArray[1] == 2 && myArray[2] == 3){return true;}else{return false;}})(), 'message: <code>myArray</code> should now be [3,2,3].');",
|
||||
"assert((function(){if(editor.getValue().match(/myArray\\[0\\]\\s?=\\s?/g)){return true;}else{return false;}})(), 'message: You should be using correct index to modify the value in <code>myArray</code>.');"
|
||||
],
|
||||
"challengeSeed":[
|
||||
"challengeSeed": [
|
||||
"var ourArray = [1,2,3];",
|
||||
"ourArray[1] = 3;",
|
||||
"// ourArray now equals [1,3,3].",
|
||||
@ -645,10 +644,10 @@
|
||||
"challengeType": 1
|
||||
},
|
||||
{
|
||||
"id":"bg9997c9c89feddfaeb9bdef",
|
||||
"id": "bg9997c9c89feddfaeb9bdef",
|
||||
"title": "Write Reusable JavaScript with Functions",
|
||||
"difficulty":"9.9819",
|
||||
"description":[
|
||||
"difficulty": "9.9819",
|
||||
"description": [
|
||||
"In JavaScript, we can divide up our code into reusable parts called functions.",
|
||||
"Here's an example of a function:",
|
||||
"<code>function functionName(a, b) {</code>",
|
||||
@ -659,10 +658,10 @@
|
||||
"In this example, the function will return the number <code>6</code> as this is the result of <code>4 + 2</code>.",
|
||||
"Create and call a function called <code>myFunction</code> that returns the sum of <code>a</code> and <code>b</code>."
|
||||
],
|
||||
"tests":[
|
||||
"tests": [
|
||||
"assert((function(){if(typeof(f) !== \"undefined\" && f === a + b){return true;}else{return false;}})(), 'message: Your function should return the value of a + b');"
|
||||
],
|
||||
"challengeSeed":[
|
||||
"challengeSeed": [
|
||||
"var a = 4;",
|
||||
"var b = 5;",
|
||||
"",
|
||||
@ -688,10 +687,10 @@
|
||||
"challengeType": 1
|
||||
},
|
||||
{
|
||||
"id":"bg9998c9c99feddfaeb9bdef",
|
||||
"id": "bg9998c9c99feddfaeb9bdef",
|
||||
"title": "Build JavaScript Objects",
|
||||
"difficulty":"9.9822",
|
||||
"description":[
|
||||
"difficulty": "9.9822",
|
||||
"description": [
|
||||
"You may have heard the term <code>object</code> before.",
|
||||
"Objects are similar to <code>arrays</code>, except that instead of using indexes to access and modify their data, you access the data in objects through what are called <code>properties</code>.",
|
||||
"Here's a sample object:",
|
||||
@ -705,13 +704,13 @@
|
||||
"Objects are useful for storing data in a structured way, and can represent real world objects, like a cat.",
|
||||
"Let's try to make an object that represents a dog called <code>myDog</code> which contains the properties <code>'name'</code> (String), <code>'legs'</code> (Number), <code>'tails'</code> (Number) and <code>'friends'</code> (Array)!"
|
||||
],
|
||||
"tests":[
|
||||
"tests": [
|
||||
"assert((function(z){if(z.hasOwnProperty(\"name\") && z.name !== undefined && typeof(z.name) === \"string\"){return true;}else{return false;}})(myDog), 'message: <code>myDog</code> should contain the property <code>name</code> and it should be a <code>string</code>.');",
|
||||
"assert((function(z){if(z.hasOwnProperty(\"legs\") && z.legs !== undefined && typeof(z.legs) === \"number\"){return true;}else{return false;}})(myDog), 'message: <code>myDog</code> should contain the property <code>legs</code> and it should be a <code>number</code>.');",
|
||||
"assert((function(z){if(z.hasOwnProperty(\"tails\") && z.tails !== undefined && typeof(z.tails) === \"number\"){return true;}else{return false;}})(myDog), 'message: <code>myDog</code> should contain the property <code>tails</code> and it should be a <code>number</code>.');",
|
||||
"assert((function(z){if(z.hasOwnProperty(\"friends\") && z.friends !== undefined && Array.isArray(z.friends)){return true;}else{return false;}})(myDog), 'message: <code>myDog</code> should contain the property <code>friends</code> and it should be an <code>array</code>.');"
|
||||
],
|
||||
"challengeSeed":[
|
||||
"challengeSeed": [
|
||||
"// var ourDog = {",
|
||||
"// \"name\": \"Camper\",",
|
||||
"// \"legs\": 4,",
|
||||
@ -736,10 +735,10 @@
|
||||
"challengeType": 1
|
||||
},
|
||||
{
|
||||
"id":"bg9999c9c99feddfaeb9bdef",
|
||||
"id": "bg9999c9c99feddfaeb9bdef",
|
||||
"title": "Manipulate JavaScript Objects",
|
||||
"difficulty":"9.9823",
|
||||
"description":[
|
||||
"difficulty": "9.9823",
|
||||
"description": [
|
||||
"There are many ways to add and remove properties from objects.",
|
||||
"For example, we can add properties to objects like this:",
|
||||
"<code>myObject.myProperty = \"myValue\";</code>",
|
||||
@ -747,11 +746,11 @@
|
||||
"<code>delete myObject.myProperty;</code>",
|
||||
"Let's add the property <code>\"bark\"</code>, and delete the property <code>\"tails\"</code>."
|
||||
],
|
||||
"tests":[
|
||||
"tests": [
|
||||
"assert(myDog.bark !== undefined, 'message: Add the property <code>\"bark\"</code> to <code>myDog</code>.');",
|
||||
"assert(myDog.tails === undefined, 'message: Delete the property <code>\"tails\"</code> from <code>myDog</code>.');"
|
||||
],
|
||||
"challengeSeed":[
|
||||
"challengeSeed": [
|
||||
"// var ourDog = {",
|
||||
"// \"name\": \"Camper\",",
|
||||
"// \"legs\": 4,",
|
||||
@ -785,19 +784,17 @@
|
||||
"challengeType": 1
|
||||
},
|
||||
{
|
||||
"id":"cf1111c1c11feddfaeb5bdef",
|
||||
"id": "cf1111c1c11feddfaeb5bdef",
|
||||
"title": "Iterate with JavaScript For Loops",
|
||||
"difficulty":"9.9824",
|
||||
"description":[
|
||||
"difficulty": "9.9824",
|
||||
"description": [
|
||||
"You can run the same code multiple times by using a loop.",
|
||||
"The most common type of JavaScript loop is called a \"for loop\" because it runs \"for\" a specific number of times.",
|
||||
"",
|
||||
"For loops are declared with three optional expressions seperated by semicolons:",
|
||||
"<code>for([initialization]; [condition]; [final-expression])</code>",
|
||||
"The <code>initialization</code> statement is executed one time only before the loop starts. It is typically used to define and setup your loop varaible.",
|
||||
"The <code>condition</code> statement is evaluated at the beginning of every loop and will continue as long as it evalutes <code>true</code>. When <code>condition</code> is <code>false</code> at the start of the loop, the loop will stop executing. This means if <code>condition</code> starts as <code>false</code>, your loop will never execute.",
|
||||
"The <code>final-expression</code> is executed at the end of each loop iteration, prior to the next <code>condition</code> check and is usually used to increment or decrement your loop counter.",
|
||||
"",
|
||||
"We'll initialize with <code>i = 0</code> and loop while our condition <code>i < 5</code> is true. We'll increment <code>i</code> by 1 each loop with <code>i++</code> as our <code>final-expression</code>.",
|
||||
"<code>var ourArray = [];</code>",
|
||||
"<code>for(var i = 0; i < 5; i++) {</code>",
|
||||
@ -806,12 +803,13 @@
|
||||
"<code>ourArray</code> will now contain [0,1,2,3,4] ",
|
||||
"Let's try getting a for loop to work by pushing values to an array."
|
||||
],
|
||||
"tests":[
|
||||
"tests": [
|
||||
"assert(editor.getValue().match(/for\\s*\\(/g).length > 1, 'message: You should be using a <code>for</code> loop for this.');",
|
||||
"assert.deepEqual(myArray, [0,1,2,3,4], 'message: <code>myArray</code> should equal [0,1,2,3,4].');"
|
||||
],
|
||||
"challengeSeed":[
|
||||
"challengeSeed": [
|
||||
"var ourArray = [];",
|
||||
"",
|
||||
"for(var i = 0; i < 5; i++){",
|
||||
" ourArray.push(i);",
|
||||
"}",
|
||||
@ -824,17 +822,16 @@
|
||||
"// Only change code above this line.",
|
||||
"// We use this function to show you the value of your variable in your output box.",
|
||||
"// You'll learn about functions soon.",
|
||||
"if(typeof(myArray) !== \"undefined\"){(function(){return myArray;})();}",
|
||||
""
|
||||
"if(typeof(myArray) !== \"undefined\"){(function(){return myArray;})();}"
|
||||
],
|
||||
"type": "waypoint",
|
||||
"challengeType": 1
|
||||
},
|
||||
{
|
||||
"id":"56104e9e514f539506016a5c",
|
||||
"id": "56104e9e514f539506016a5c",
|
||||
"title": "Iterate Odd Numbers With a For Loop",
|
||||
"difficulty":"9.9824",
|
||||
"description":[
|
||||
"difficulty": "9.9824",
|
||||
"description": [
|
||||
"For loops don't have to iterate one at a time. By changing our <code>final-expression</code>, we can count by even numbers.",
|
||||
"We'll start at <code>i = 0</code> and loop while <code>i < 10</code>. We'll increment <code>i</code> by 2 each loop with <code>i += 2</code>.",
|
||||
"<code>var ourArray = [];</code>",
|
||||
@ -844,15 +841,17 @@
|
||||
"<code>ourArray</code> will now contain [0,2,4,6,8] ",
|
||||
"Let's change our <code>initialization</code> and <code>final-expression</code> so we can count by odd numbers."
|
||||
],
|
||||
"tests":[
|
||||
"tests": [
|
||||
"assert(editor.getValue().match(/for\\s*\\(/g).length > 1, 'message: You should be using a <code>for</code> loop for this.');",
|
||||
"assert.deepEqual(myArray, [1,3,5,7,9], 'message: <code>myArray</code> should equal [1,3,5,7,9].');"
|
||||
],
|
||||
"challengeSeed":[
|
||||
"ourArray = [];",
|
||||
"challengeSeed": [
|
||||
"var ourArray = [];",
|
||||
"",
|
||||
"for(var i = 1; i < 10; i += 2){",
|
||||
" ourArray.push(i);",
|
||||
"}",
|
||||
"",
|
||||
"var myArray = [];",
|
||||
"",
|
||||
"// Only change code below this line.",
|
||||
@ -869,10 +868,10 @@
|
||||
"challengeType": 1
|
||||
},
|
||||
{
|
||||
"id":"56105e7b514f539506016a5e",
|
||||
"id": "56105e7b514f539506016a5e",
|
||||
"title": "Count Backwards With a For Loop",
|
||||
"difficulty":"9.9824",
|
||||
"description":[
|
||||
"difficulty": "9.9824",
|
||||
"description": [
|
||||
"A for loop can also count backwards, so long as we can define the right conditions.",
|
||||
"",
|
||||
"In order to count backwards by twos, we'll need to change our <code>initialization</code>, <code>condition</code>, and <code>final-expression</code>.",
|
||||
@ -884,15 +883,17 @@
|
||||
"<code>ourArray</code> will now contain [10,8,6,4,2] ",
|
||||
"Let's change our <code>initialization</code> and <code>final-expression</code> so we can count backward by twos for numbers."
|
||||
],
|
||||
"tests":[
|
||||
"tests": [
|
||||
"assert(editor.getValue().match(/for\\s*\\(/g).length > 1, 'message: You should be using a <code>for</code> loop for this.');",
|
||||
"assert.deepEqual(myArray, [9,7,5,3,1], 'message: <code>myArray</code> should equal [9,7,5,3,1].');"
|
||||
],
|
||||
"challengeSeed":[
|
||||
"ourArray = [];",
|
||||
"challengeSeed": [
|
||||
"var ourArray = [];",
|
||||
"",
|
||||
"for(var i = 9; i > 0; i -= 2){",
|
||||
" ourArray.push(i);",
|
||||
"}",
|
||||
"",
|
||||
"var myArray = [];",
|
||||
"",
|
||||
"// Only change code below this line.",
|
||||
@ -909,10 +910,10 @@
|
||||
"challengeType": 1
|
||||
},
|
||||
{
|
||||
"id":"cf1111c1c11feddfaeb1bdef",
|
||||
"id": "cf1111c1c11feddfaeb1bdef",
|
||||
"title": "Iterate with JavaScript While Loops",
|
||||
"difficulty":"9.9825",
|
||||
"description":[
|
||||
"difficulty": "9.9825",
|
||||
"description": [
|
||||
"You can run the same code multiple times by using a loop.",
|
||||
"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.",
|
||||
"<code>var ourArray = [];</code>",
|
||||
@ -923,11 +924,11 @@
|
||||
"<code>}</code>",
|
||||
"Let's try getting a while loop to work by pushing values to an array."
|
||||
],
|
||||
"tests":[
|
||||
"tests": [
|
||||
"assert(editor.getValue().match(/while/g), 'message: You should be using a <code>while</code> loop for this.');",
|
||||
"assert.deepEqual(myArray, [0,1,2,3,4], 'message: <code>myArray</code> should equal [0,1,2,3,4].');"
|
||||
],
|
||||
"challengeSeed":[
|
||||
"challengeSeed": [
|
||||
"var myArray = [];",
|
||||
"// Only change code below this line.",
|
||||
"",
|
||||
@ -943,20 +944,20 @@
|
||||
"challengeType": 1
|
||||
},
|
||||
{
|
||||
"id":"cf1111c1c11feddfaeb9bdef",
|
||||
"id": "cf1111c1c11feddfaeb9bdef",
|
||||
"title": "Generate Random Fractions with JavaScript",
|
||||
"difficulty":"9.9827",
|
||||
"description":[
|
||||
"difficulty": "9.9827",
|
||||
"description": [
|
||||
"Random numbers are useful for creating random behavior.",
|
||||
"JavaScript has a <code>Math.random()</code> function that generates a random decimal number.",
|
||||
"Use <code>Math.random()</code> to get <code>myFunction</code> to return a random number."
|
||||
],
|
||||
"tests":[
|
||||
"tests": [
|
||||
"assert(typeof(myFunction()) === \"number\", 'message: <code>myFunction</code> should return a random number.');",
|
||||
"assert((myFunction()+''). match(/\\./g), 'message: The number returned by <code>myFunction</code> should be a decimal.');",
|
||||
"assert(editor.getValue().match(/Math\\.random/g).length >= 2, 'message: You should be using <code>Math.random</code> to generate the random decimal number.');"
|
||||
],
|
||||
"challengeSeed":[
|
||||
"challengeSeed": [
|
||||
"function myFunction() {",
|
||||
" // Change the 0 to Math.random().",
|
||||
" // Only change code below this line.",
|
||||
@ -973,10 +974,10 @@
|
||||
"challengeType": 1
|
||||
},
|
||||
{
|
||||
"id":"cf1111c1c12feddfaeb1bdef",
|
||||
"id": "cf1111c1c12feddfaeb1bdef",
|
||||
"title": "Generate Random Whole Numbers with JavaScript",
|
||||
"difficulty":"9.9828",
|
||||
"description":[
|
||||
"difficulty": "9.9828",
|
||||
"description": [
|
||||
"It's great that we can create random decimal numbers, but it's even more useful if we use it to generate a random whole number.",
|
||||
"To achieve this we can multiply the random number by ten and use the <code>Math.floor()</code> to convert the decimal number to the nearest less than or equal whole number.",
|
||||
"This technique gives us a whole number between zero and nine.",
|
||||
@ -984,13 +985,13 @@
|
||||
"<code>Math.floor(Math.random()*10);</code>",
|
||||
"Let's give this technique a go now."
|
||||
],
|
||||
"tests":[
|
||||
"tests": [
|
||||
"assert(typeof(myFunction()) === \"number\", 'message: The result of <code>myFunction</code> should be a number.');",
|
||||
"assert(editor.getValue().match(/Math.random/g), 'message: You should be using Math.random to create a random number.');",
|
||||
"assert(editor.getValue().match(/\\(\\s*?Math.random\\s*?\\(\\s*?\\)\\s*?\\*\\s*?10\\s*?\\)/g) || editor.getValue().match(/\\(\\s*?10\\s*?\\*\\s*?Math.random\\s*?\\(\\s*?\\)\\s*?\\)/g), 'message: You should have multiplied the result of <code>Math.random</code> by 10 to make it a number that is between zero and nine.');",
|
||||
"assert(editor.getValue().match(/Math.floor/g), 'message: You should use <code>Math.floor</code> to remove the decimal part of the number.');"
|
||||
],
|
||||
"challengeSeed":[
|
||||
"challengeSeed": [
|
||||
"function myFunction(){",
|
||||
" // Make myFunction return a random number between zero and nine instead of a decimal.",
|
||||
"",
|
||||
@ -1008,21 +1009,21 @@
|
||||
"challengeType": 1
|
||||
},
|
||||
{
|
||||
"id":"cf1111c1c12feddfaeb2bdef",
|
||||
"id": "cf1111c1c12feddfaeb2bdef",
|
||||
"title": "Generate Random Whole Numbers within a Range",
|
||||
"difficulty":"9.9829",
|
||||
"description":[
|
||||
"difficulty": "9.9829",
|
||||
"description": [
|
||||
"We can use a certain mathematical expression to get a random number between two numbers.",
|
||||
"<code>Math.floor(Math.random() * (max - min + 1)) + min</code>",
|
||||
"By using this, we can control the output of a random number."
|
||||
],
|
||||
"tests":[
|
||||
"tests": [
|
||||
"assert(myFunction() >= min, 'message: The random number generated by <code>myFunction</code> should be greater than or equal to the minimum number.');",
|
||||
"assert(myFunction() <= max, 'message: The random number generated by <code>myFunction</code> should be less than or equal to the maximum number.');",
|
||||
"assert(myFunction() % 1 === 0 , 'message: The random number generated by <code>myFunction</code> should be an integer, not a decimal.');",
|
||||
"assert((function(){if(editor.getValue().match(/max/g).length >= 3 && editor.getValue().match(/min/g).length >= 4 && editor.getValue().match(/Math.floor/g) && editor.getValue().match(/Math.random/g)){return true;}else{return false;}})(), 'message: You should be using the function given in the description to calculate the random in number in a range.');"
|
||||
],
|
||||
"challengeSeed":[
|
||||
"challengeSeed": [
|
||||
"var min = 1;",
|
||||
"var max = 9;",
|
||||
"function myFunction() {",
|
||||
@ -1040,10 +1041,10 @@
|
||||
"challengeType": 1
|
||||
},
|
||||
{
|
||||
"id":"cf1111c1c12feddfaeb3bdef",
|
||||
"id": "cf1111c1c12feddfaeb3bdef",
|
||||
"title": "Use Conditional Logic with If and Else Statements",
|
||||
"difficulty":"9.983",
|
||||
"description":[
|
||||
"difficulty": "9.983",
|
||||
"description": [
|
||||
"We can use <code>if</code> statements in JavaScript to only execute code if a certain condition is met.",
|
||||
"<code>if</code> statements require some sort of boolean condition to evaluate.",
|
||||
"For example:",
|
||||
@ -1055,13 +1056,13 @@
|
||||
"Let's use <code>if</code> and <code>else</code> statements to make a coin-flip game.",
|
||||
"Create <code>if</code> and <code>else</code> statements to return the string <code>\"heads\"</code> if the flip variable is zero, or else return the string <code>\"tails\"</code> if the flip variable is not zero."
|
||||
],
|
||||
"tests":[
|
||||
"tests": [
|
||||
"assert((function(){var result = myFunction();if(result === 'heads' || result === 'tails'){return true;} else {return false;}})(), 'message: <code>myFunction</code> should either return <code>heads</code> or <code>tails</code>.');",
|
||||
"assert((function(){var result = myFunction();if(result === 'heads' && flip === 0 || result === 'tails' && flip !== 0){return true;} else {return false;}})(), 'message: <code>myFunction</code> should return <code>heads</code> when flip equals 0 and <code>tails</code> when flip equals 1.');",
|
||||
"assert(editor.getValue().match(/if/g).length >= 4, 'message: You should have created a new if statement.');",
|
||||
"assert(editor.getValue().match(/else/g).length >= 2, 'message: You should have created a new else statement.');"
|
||||
],
|
||||
"challengeSeed":[
|
||||
"challengeSeed": [
|
||||
"var flip = Math.floor(Math.random() * (1 - 0 + 1)) + 0;",
|
||||
"function myFunction(){",
|
||||
" // Create an if-else statement here to return \"heads\" if flip is 0. Otherwise return \"tails\".",
|
||||
@ -1080,12 +1081,12 @@
|
||||
"challengeType": 1
|
||||
},
|
||||
{
|
||||
"id":"cf1111c1c12feddfaeb6bdef",
|
||||
"id": "cf1111c1c12feddfaeb6bdef",
|
||||
"title": "Sift through Text with Regular Expressions",
|
||||
"difficulty":"9.984",
|
||||
"description":[
|
||||
"difficulty": "9.984",
|
||||
"description": [
|
||||
"<code>Regular expressions</code> are used to find certain words or patterns inside of <code>strings</code>.",
|
||||
"For example, if we wanted to find the word <code>the</code> in the string <code>The dog chased the cat</code>, we could use the following <code>regular expression</code>: <code>\/the\/gi</code>",
|
||||
"For example, if we wanted to find the word <code>the</code> in the string <code>The dog chased the cat</code>, we could use the following <code>regular expression</code>: <code>/the/gi</code>",
|
||||
"Let's break this down a bit:",
|
||||
"<code>the</code> is the pattern we want to match.",
|
||||
"<code>g</code> means that we want to search the entire string for this pattern instead of just the first match.",
|
||||
@ -1093,11 +1094,11 @@
|
||||
"<code>Regular expressions</code> are written by surrounding the pattern with <code>/</code> symbols.",
|
||||
"Let's try selecting all the occurrences of the word <code>and</code> in the string <code>Ada Lovelace and Charles Babbage designed the first computer and the software that would have run on it</code>. We can do this by replacing the <code>.</code> part of our regular expression with the current <code>regular expression</code> with the word <code>and</code>."
|
||||
],
|
||||
"tests":[
|
||||
"tests": [
|
||||
"assert(test==2, 'message: Your <code>regular expression</code> should find two occurrences of the word <code>and</code>.');",
|
||||
"assert(editor.getValue().match(/\\/and\\/gi/), 'message: You should have used <code>regular expressions</code> to find the word <code>and</code>.');"
|
||||
],
|
||||
"challengeSeed":[
|
||||
"challengeSeed": [
|
||||
"var test = (function() {",
|
||||
" var testString = \"Ada Lovelace and Charles Babbage designed the first computer and the software that would have run on it.\";",
|
||||
" var expressionToGetSoftware = /software/gi;",
|
||||
@ -1114,21 +1115,21 @@
|
||||
"challengeType": 1
|
||||
},
|
||||
{
|
||||
"id":"cf1111c1c12feddfaeb7bdef",
|
||||
"id": "cf1111c1c12feddfaeb7bdef",
|
||||
"title": "Find Numbers with Regular Expressions",
|
||||
"difficulty":"9.985",
|
||||
"description":[
|
||||
"difficulty": "9.985",
|
||||
"description": [
|
||||
"We can use special selectors in <code>Regular Expressions</code> to select a particular type of value.",
|
||||
"One such selector is the digit selector <code>\\d</code> which is used to grab the numbers in a string.",
|
||||
"It is used like this: <code>/\\d/g</code>.",
|
||||
"For numbers this is often written as <code>/\\d+/g</code>, where the <code>+</code> following the digit selector allows this regular expression to match multi-digit numbers.",
|
||||
"Use the <code>\\d</code> selector to select the number of numbers in the string, allowing for the possibility of multi-digit numbers."
|
||||
],
|
||||
"tests":[
|
||||
"tests": [
|
||||
"assert(test === 2, 'message: Your RegEx should have found two numbers in the <code>testString</code>.');",
|
||||
"assert(editor.getValue().match(/\\/\\\\d\\+\\//g), 'message: You should be using the following expression <code>/\\d+/g</code> to find the numbers in the <code>testString</code>.');"
|
||||
],
|
||||
"challengeSeed":[
|
||||
"challengeSeed": [
|
||||
"var test = (function() {",
|
||||
" var testString = \"There are 3 cats but 4 dogs.\";",
|
||||
"",
|
||||
@ -1145,21 +1146,21 @@
|
||||
"challengeType": 1
|
||||
},
|
||||
{
|
||||
"id":"cf1111c1c12feddfaeb8bdef",
|
||||
"id": "cf1111c1c12feddfaeb8bdef",
|
||||
"title": "Find Whitespace with Regular Expressions",
|
||||
"difficulty":"9.986",
|
||||
"description":[
|
||||
"difficulty": "9.986",
|
||||
"description": [
|
||||
"We can also use selectors like <code>\\s</code> to find whitespace in a string.",
|
||||
"The whitespace characters are <code>\" \"</code> (space), <code>\\r</code> (carriage return), <code>\\n</code> (newline), <code>\\t</code> (tab), and <code>\\f</code> (form feed).",
|
||||
"It is used like this:",
|
||||
"<code>/\\s+/g</code>",
|
||||
"Select all the whitespace characters in the sentence string."
|
||||
],
|
||||
"tests":[
|
||||
"tests": [
|
||||
"assert(test === 7, 'message: Your RegEx should have found seven spaces in the <code>testString</code>.');",
|
||||
"assert(editor.getValue().match(/\\/\\\\s\\+\\//g), 'message: You should be using the following expression <code>/\\s+/g</code> to find the spaces in the <code>testString</code>.');"
|
||||
],
|
||||
"challengeSeed":[
|
||||
"challengeSeed": [
|
||||
"var test = (function(){",
|
||||
" var testString = \"How many spaces are there in this sentence?\";",
|
||||
"",
|
||||
@ -1176,18 +1177,18 @@
|
||||
"challengeType": 1
|
||||
},
|
||||
{
|
||||
"id":"cf1111c1c13feddfaeb3bdef",
|
||||
"id": "cf1111c1c13feddfaeb3bdef",
|
||||
"title": "Invert Regular Expression Matches with JavaScript",
|
||||
"difficulty":"9.987",
|
||||
"description":[
|
||||
"difficulty": "9.987",
|
||||
"description": [
|
||||
"Use <code>/\\S/g</code> to match everything that isn't a space in the string.",
|
||||
"You can invert any match by using the uppercase version of the selector <code>\\s</code> versus <code>\\S</code> for example."
|
||||
],
|
||||
"tests":[
|
||||
"tests": [
|
||||
"assert(test === 49, 'message: Your RegEx should have found forty nine non-space characters in the <code>testString</code>.');",
|
||||
"assert(editor.getValue().match(/\\/\\\\S\\/g/g), 'message: You should be using the following expression <code>/\\S/g</code> to find non-space characters in the <code>testString</code>.');"
|
||||
],
|
||||
"challengeSeed":[
|
||||
"challengeSeed": [
|
||||
"var test = (function(){",
|
||||
" var testString = \"How many non-space characters are there in this sentence?\";",
|
||||
"",
|
||||
@ -1201,26 +1202,26 @@
|
||||
"})();(function(){return test;})();"
|
||||
],
|
||||
"type": "waypoint",
|
||||
"challengeType":1
|
||||
"challengeType": 1
|
||||
},
|
||||
{
|
||||
"id":"cf1111c1c12feddfaeb9bdef",
|
||||
"id": "cf1111c1c12feddfaeb9bdef",
|
||||
"title": "Create a JavaScript Slot Machine",
|
||||
"difficulty":"9.988",
|
||||
"description":[
|
||||
"difficulty": "9.988",
|
||||
"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 <code>1</code> and <code>3</code> to represent the possible values of each individual slot.",
|
||||
"Store the three random numbers in <code>slotOne</code>, <code>slotTwo</code> and <code>slotThree</code>.",
|
||||
"Generate the random numbers by using the system we used earlier (an explanation of the formula can be found <a href=\"https://github.com/FreeCodeCamp/FreeCodeCamp/wiki/Waypoint-Generate-Random-Whole-Numbers-within-a-Range#explanation\">here</a>):",
|
||||
"<code>Math.floor(Math.random() * (3 - 1 + 1)) + 1;</code>"
|
||||
],
|
||||
"tests":[
|
||||
"tests": [
|
||||
"assert(typeof(runSlots($(\".slot\"))[0]) === \"number\", '<code>slotOne</code> should be a random number.')",
|
||||
"assert(typeof(runSlots($(\".slot\"))[1]) === \"number\", '<code>slotTwo</code> should be a random number.')",
|
||||
"assert(typeof(runSlots($(\".slot\"))[2]) === \"number\", '<code>slotThree</code> 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(/Math\\.floor\\(\\s?Math\\.random\\(\\)\\s?\\*\\s?\\(\\s?3\\s?\\-\\s?1\\s?\\+\\s?1\\s?\\)\\s?\\)\\s?\\+\\s?1;/gi).length >= 3;}else{return false;}})(), 'You should have used <code>Math.floor(Math.random() * (3 - 1 + 1)) + 1;</code> three times to generate your random numbers.')"
|
||||
],
|
||||
"challengeSeed":[
|
||||
"challengeSeed": [
|
||||
"fccss",
|
||||
" function runSlots(){",
|
||||
" var slotOne;",
|
||||
@ -1358,10 +1359,10 @@
|
||||
"challengeType": 0
|
||||
},
|
||||
{
|
||||
"id":"cf1111c1c13feddfaeb1bdef",
|
||||
"id": "cf1111c1c13feddfaeb1bdef",
|
||||
"title": "Add your JavaScript Slot Machine Slots",
|
||||
"difficulty":"9.989",
|
||||
"description":[
|
||||
"difficulty": "9.989",
|
||||
"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.",
|
||||
"Otherwise, we should return <code>null</code>, which is a JavaScript data structure that means nothing.",
|
||||
@ -1371,10 +1372,10 @@
|
||||
"<code>  return null;</code>",
|
||||
"<code>}</code>"
|
||||
],
|
||||
"tests":[
|
||||
"tests": [
|
||||
"assert((function(){var data = runSlots();if(data === null){return true}else{if(data[0] === data[1] && data[1] === data[2]){return true;}else{return false;}}})(), 'If all three of our random numbers are the same we should return that number. Otherwise we should return <code>null</code>.')"
|
||||
],
|
||||
"challengeSeed":[
|
||||
"challengeSeed": [
|
||||
"fccss",
|
||||
" function runSlots(){",
|
||||
" var slotOne;",
|
||||
@ -1518,10 +1519,10 @@
|
||||
"challengeType": 0
|
||||
},
|
||||
{
|
||||
"id":"cf1111c1c13feddfaeb2bdef",
|
||||
"id": "cf1111c1c13feddfaeb2bdef",
|
||||
"title": "Bring your JavaScript Slot Machine to Life",
|
||||
"difficulty":"9.990",
|
||||
"description":[
|
||||
"difficulty": "9.990",
|
||||
"description": [
|
||||
"Now we can detect a win. Let's get this slot machine working.",
|
||||
"Let's use the jQuery <code>selector</code> <code>$(\".slot\")</code> to select all of the slots.",
|
||||
"Once they are all selected, we can use <code>bracket notation</code> to access each individual slot:",
|
||||
@ -1529,11 +1530,11 @@
|
||||
"This jQuery will select the first and update the slot's HTML to display the correct number.",
|
||||
"Use the above selector to display each number in its corresponding slot."
|
||||
],
|
||||
"tests":[
|
||||
"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 <code>slotOne</code>, <code>slotTwo</code> and <code>slotThree</code> respectively.')"
|
||||
],
|
||||
"challengeSeed":[
|
||||
"challengeSeed": [
|
||||
"fccss",
|
||||
" function runSlots(){",
|
||||
" var slotOne;",
|
||||
@ -1684,17 +1685,17 @@
|
||||
"challengeType": 0
|
||||
},
|
||||
{
|
||||
"id":"cf1111c1c11feddfaeb1bdff",
|
||||
"id": "cf1111c1c11feddfaeb1bdff",
|
||||
"title": "Give your JavaScript Slot Machine some Stylish Images",
|
||||
"difficulty":"9.9901",
|
||||
"description":[
|
||||
"difficulty": "9.9901",
|
||||
"description": [
|
||||
"Now let's add some images to our slots.",
|
||||
"We've already set up the images for you in an array called <code>images</code>. We can use different indexes to grab each of these.",
|
||||
"Here's how we would set the first slot to show a different image depending on which number its random number generates:",
|
||||
"<code>$($('.slot')[0]).html('<img src = \"' + images[slotOne-1] + '\">');</code>",
|
||||
"Set up all three slots like this, then click the \"Go\" button to play the slot machine."
|
||||
],
|
||||
"tests":[
|
||||
"tests": [
|
||||
"assert((editor.match(/\\$\\s*?\\(\\s*?\\$\\s*?\\(\\s*?(?:'|\")\\s*?\\.slot\\s*?(?:'|\")\\s*?\\)\\[\\d\\]\\s*?\\)\\.html\\(\\s*?\\'\\<img\\s?src\\s?=\\s?\"\\'\\s?\\+\\s?images\\[\\w+\\-1\\]\\s?\\+\\s?\\'\"\\>\\'\\s*?\\);/gi) && editor.match(/\\$\\s*?\\(\\s*?\\$\\s*?\\(\\s*?(?:'|\")\\s*?\\.slot\\s*?(?:'|\")\\s*?\\)\\[\\d\\]\\s*?\\)\\.html\\(\\s*?\\'\\<img\\s?src\\s?=\\s?\"\\'\\s?\\+\\s?images\\[\\w+\\-1\\]\\s?\\+\\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 <code>$('.slot')[0]</code> at least once.')",
|
||||
"assert(editor.match(/\\$\\s*?\\(\\s*?\\$\\s*?\\(\\s*?(?:'|\")\\s*?\\.slot\\s*?(?:'|\")\\s*?\\)\\[1\\]\\s*?\\)/gi), 'You should have used <code>$('.slot')[1]</code> at least once.')",
|
||||
@ -1703,7 +1704,7 @@
|
||||
"assert(editor.match(/slotTwo/gi) && editor.match(/slotTwo/gi).length >= 8, 'You should have used the <code>slotTwo</code> value at least once.')",
|
||||
"assert(editor.match(/slotThree/gi) && editor.match(/slotThree/gi).length >= 7, 'You should have used the <code>slotThree</code> value at least once.')"
|
||||
],
|
||||
"challengeSeed":[
|
||||
"challengeSeed": [
|
||||
"fccss",
|
||||
" function runSlots(){",
|
||||
" var slotOne;",
|
||||
@ -1859,4 +1860,4 @@
|
||||
"challengeType": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user