From 44c77d65b1fed82321228c766d5799e90340f862 Mon Sep 17 00:00:00 2001 From: Quincy Larson Date: Wed, 28 Oct 2015 02:39:51 -0700 Subject: [PATCH] fix some mis-mergings for basic-javascript.json --- seed/challenges/basic-javascript.json | 106 +++++++++++++++++++++++--- 1 file changed, 94 insertions(+), 12 deletions(-) diff --git a/seed/challenges/basic-javascript.json b/seed/challenges/basic-javascript.json index 5c9da5407a..a0f9635795 100644 --- a/seed/challenges/basic-javascript.json +++ b/seed/challenges/basic-javascript.json @@ -30,7 +30,7 @@ "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.", - "Let's modify our welcomeToBooleansfunction so that it will return trueinstead of falsewhen the run button is clicked." + "Let's modify our welcomeToBooleans function so that it will return true instead of falsewhen the run button is clicked." ], "tests": [ "assert(typeof(welcomeToBooleans()) === 'boolean', 'message: The welcomeToBooleans() function should return a boolean (true/false) value.');", @@ -80,7 +80,7 @@ "title": "Declare String Variables", "description": [ "In the previous challenge, we 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.", - "Now let's create two new string variables: myFirstNameand myLastName and assign them the values of your first and last name, respectively." + "Now let's create two new 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.');", @@ -528,6 +528,7 @@ "tests": [ "assert((function(d){if(d[0] == 'John' && d[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;}})(removed), 'message: removedFromMyArray should only contain [\"cat\", 2].');" + ], "challengeSeed": [ "var ourArray = [1,2,3];", @@ -871,6 +872,12 @@ "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:", + "for([initialization]; [condition]; [final-expression])", + "The initialization statement is executed one time only before the loop starts. It is typically used to define and setup your loop varaible.", + "The condition statement is evaluated at the beginning of every loop and will continue as long as it evalutes true. When condition is false at the start of the loop, the loop will stop executing. This means if condition starts as false, your loop will never execute.", + "The final-expression is executed at the end of each loop iteration, prior to the next condition check and is usually used to increment or decrement your loop counter.", + "We'll initialize with i = 0 and loop while our condition i < 5 is true. We'll increment i by 1 each loop with i++ as our final-expression.", "var ourArray = [];", "for(var i = 0; i < 5; i++) {", "  ourArray.push(i);", @@ -879,7 +886,7 @@ "Let's try getting a for loop to work by pushing values to an array." ], "tests": [ - "assert(editor.getValue().match(/for/g), 'message: You should be using a for loop for this.');", + "assert(editor.getValue().match(/for\\s*\\(/g).length > 1, 'message: You should be using a for loop for this.');", "assert.deepEqual(myArray, [0,1,2,3,4], 'message: myArray should equal [0,1,2,3,4].');" ], "challengeSeed": [ @@ -900,6 +907,81 @@ "type": "waypoint", "challengeType": 1 }, + { + "id":"56104e9e514f539506016a5c", + "title": "Iterate Odd Numbers With a For Loop", + "description":[ + "For loops don't have to iterate one at a time. By changing our final-expression, we can count by even numbers.", + "We'll start at i = 0 and loop while i < 10. We'll increment i by 2 each loop with i += 2.", + "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 and final-expression so we can count by odd numbers." + ], + "tests":[ + "assert(editor.getValue().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":[ + "var ourArray = [];", + "for(var i = 1; i < 10; i += 2){", + " ourArray.push(i);", + "}", + "var myArray = [];", + "", + "// Only change code below this line.", + "", + "// Push the odd numbers from one through nine to myArray using a \"for loop\" like above.", + "", + "// 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;})();}", + "" + ], + "type": "waypoint", + "challengeType": 1 + }, + { + "id":"56105e7b514f539506016a5e", + "title": "Count Backwards With a For Loop", + "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 initialization, condition, and final-expression.", + "We'll start at i = 10 and loop while i > 0. We'll decrement i by 2 each loop with i -= 2.", + "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 for numbers." + ], + "tests":[ + "assert(editor.getValue().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":[ + "ourArray = [];", + "for(var i = 9; i > 0; i -= 2){", + " ourArray.push(i);", + "}", + "var myArray = [];", + "", + "// Only change code below this line.", + "", + "// Push the odd numbers from nine through one to myArray using a \"for loop\" like above.", + "", + "// 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;})();}", + "" + ], + "type": "waypoint", + "challengeType": 1 + }, { "id": "cf1111c1c11feddfaeb1bdef", "title": "Iterate with JavaScript While Loops", @@ -1219,10 +1301,10 @@ "Math.floor(Math.random() * (3 - 1 + 1)) + 1;" ], "tests": [ - "assert(typeof(runSlots($(\".slot\"))[0]) === \"number\", 'slotOne should be a random number.')", - "assert(typeof(runSlots($(\".slot\"))[1]) === \"number\", 'slotTwo should be a random number.')", - "assert(typeof(runSlots($(\".slot\"))[2]) === \"number\", '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(/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 Math.floor(Math.random() * (3 - 1 + 1)) + 1; three times to generate your random numbers.')" + "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", @@ -1375,7 +1457,7 @@ "}" ], "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 null.')" + "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", @@ -1557,8 +1639,8 @@ " ", " // Only change code above this line.", " ", - " if(slotOne !== slotTwo || slotTwo !== slotThree){", - " return null;", + " if (slotOne === slotTwo && slotTwo === slotThree) {", + " return slotOne;", " }", " ", " if(slotOne !== undefined && slotTwo !== undefined && slotThree !== undefined){", @@ -1726,8 +1808,8 @@ " ", " // Only change code above this line.", " ", - " if(slotOne !== slotTwo || slotTwo !== slotThree){", - " return null;", + " if (slotOne === slotTwo && slotTwo === slotThree) {", + " return slotOne;", " }", " ", " if(slotOne !== undefined && slotTwo !== undefined && slotThree !== undefined){",