From ef9e2f498e2096572a112c5e0361fc11bf920219 Mon Sep 17 00:00:00 2001 From: Ethan Arrowood Date: Thu, 21 Dec 2017 15:38:28 -0500 Subject: [PATCH] test(challenges): Test ES6 challenge (#16201) * test(challenges): Test ES6 challenge Added tests to 3rd ES6 challenge * test(challenges): ES6 challenges * test(challenges): ES6 chall c11-c15 * test(challenges): ES6 chall c16-c20 * test(challenges): ES6 chall c21-c27 * test(challenges): Refactor ES6 challenges Update tests to use getUserInput. Remove test for arrow function use Closes #16207 * test(challenges): Fix falsey case Add proper getUserInput syntax for !code.match tests Closes #16207 * test(challenges): QA ES6 Challenges QA and edit for ES6 challenges 1 - 18 Closes #16207 --- .../es6.json | 274 +++++++++--------- 1 file changed, 144 insertions(+), 130 deletions(-) diff --git a/challenges/02-javascript-algorithms-and-data-structures/es6.json b/challenges/02-javascript-algorithms-and-data-structures/es6.json index 1288c48591..d12880a8d9 100644 --- a/challenges/02-javascript-algorithms-and-data-structures/es6.json +++ b/challenges/02-javascript-algorithms-and-data-structures/es6.json @@ -38,17 +38,17 @@ "A new keyword called let was introduced in ES6 to solve the problems with the var keyword. With the let keyword, all the examples we just saw will cause an error to appear. We can no longer overwrite variables or use a variable before we declare it. Some modern browsers require you to add \"use strict\"; to the top of your code before you can use the new features of ES6.", "Let's try using the let keyword.", "
", - "Fix the code so that it only uses the let keyword and makes the errors go away.", - "Note
Remember to add \"use strict\"; to the top of your code." + "Fix the code so that it only uses the let keyword and makes the errors go away." ], - "challengeSeed": [ + "challengeSeed": [ + "\"use strict\";", "var favorite = redNosedReindeer + \" is Santa's favorite reindeer.\";", "var redNosedReindeer = \"Rudolph\";", "var redNosedReindeer = \"Comet\";" ], "tests": [ "assert(redNosedReindeer === \"Rudolph\", 'message: redNosedReindeer should be Rudolph.');", - "assert(favorite === \"Rudolph is Santa's favorite reindeer.\", \"message: favorite should return Santa's favorite reindeer.\");" + "assert(favorite === \"Rudolph is Santa's favorite reindeer.\", 'message: favorite should return Santa's favorite reindeer.');" ], "type": "waypoint", "releasedOn": "Feb 17, 2017", @@ -72,10 +72,10 @@ "i is not defined because it was not declared in the global scope. It is only declared within the for loop statement. printNumTwo() returned the correct value because three different i variables with unique values (0, 1, and 2) were created by the let keyword within the loop statement.", "
", "Fix the code so that i declared in the if statement is a separate variable than i declared in the first line of the function. Be certain not to use the var keyword anywhere in your code.", - "Note
Remember to add \"use strict\"; to the top of your code.", "This exercise is designed to illustrate the difference between how var and let keywords assign scope to the declared variable. When programming a function similar to the one used in this exercise, it is often better to use different variable names to avoid confusion." ], - "challengeSeed": [ + "challengeSeed": [ + "\"use strict\";", "function checkScope() {", " var i = \"function scope\";", " if (true) {", @@ -90,7 +90,7 @@ ], "tests": [ "// TEMPORARILY COMMENTED OUT: assert(!/var/g.test(code) && /let/g.test(code), 'message: The var keyword should be replaced with let. (This test is temporarily disabled)');", - "assert(code.match(/(i\\s*=\\s*).*\\s*.*\\s*.*\\1('|\")block\\s*scope\\2/g), 'message: The variable i declared in the if statement should equal \"block scope\".');", + "getUserInput => assert(getUserInput('index').match(/(i\\s*=\\s*).*\\s*.*\\s*.*\\1('|\")block\\s*scope\\2/g), 'message: The variable i declared in the if statement should equal \"block scope\".');", "assert(checkScope() === \"function scope\", 'message: checkScope() should return \"function scope\"');" ], "type": "waypoint", @@ -107,12 +107,10 @@ "
\"use strict\"
const FAV_PET = \"Cats\";
FAV_PET = \"Dogs\"; // returns error
", "As you can see, trying to reassign a variable declared with const will throw an error. You should always name variables you don't want to reassign using the const keyword. This helps when you accidentally attempt to reassign a variable that is meant to stay constant. A common practice is to name your constants in all upper-cases and with an underscore to separate words (e.g. EXAMPLE_VARIABLE).", "
", - "Change the code so that all variables are declared using let or const. Use let when you want the variable to change, and const when you want the variable to remain constant. Also, rename variables declared with const to conform to common practices.", - "Note
Don't forget to add \"use strict\"; to the top of your code." + "Change the code so that all variables are declared using let or const. Use let when you want the variable to change, and const when you want the variable to remain constant. Also, rename variables declared with const to conform to common practices." ], - "challengeSeed": [ - "// change 'var' to 'let' or 'const'", - "// rename constant variables", + "challengeSeed": [ + "\"use strict\";", "var pi = 3.14;", "var radius = 10;", "var calculateCircumference = function(r) {", @@ -121,13 +119,15 @@ " return result;", "};", "// Test your code", + "console.log(calculateCircumference(radius));", + "radius = 5;", "console.log(calculateCircumference(radius));" ], "tests": [ - "// Test user replaced all var keyword", - "// Test PI is const", - "// Test calculateCircumference is const", - "// Test pi and calculateCircumference has been renamed" + "assert(!/var/g.test(code),'message: var does not exist in code.');", + "getUserInput => assert(getUserInput('index').match(/(const pi)/g), 'message: PI is const.');", + "getUserInput => assert(getUserInput('index').match(/(const calculateCircumference)/g), 'message: calculateCircumference is const.');", + "getUserInput => assert(getUserInput('index').match(/(let radius)/g), 'message: radius is let.');" ], "type": "waypoint", "releasedOn": "Feb 17, 2017", @@ -144,10 +144,10 @@ "
\"use strict\";
const s = [5, 6, 7];
s = [1, 2, 3]; // throws error, trying to assign a const
s[2] = 45; // works just as it would with an array declared with var or let
console.log(s); // returns [5, 6, 45]
", "As you can see, you can mutate the object [5, 6, 7] itself and the variable s will still point to the altered array [5, 6, 45]. Like all arrays, the array elements in s are mutable, but because const was used, you cannot use the variable identifier s to point to a different array using the assignment operator.", "
", - "An array is declared as const s = [5, 7, 2]. Change the array to [2, 5, 7] using various element assignment.", - "Note
Don't forget to add \"use strict\"; to the top of your code." + "An array is declared as const s = [5, 7, 2]. Change the array to [2, 5, 7] using various element assignment." ], - "challengeSeed": [ + "challengeSeed": [ + "\"use strict\";", "const s = [5, 7, 2];", "// change code below this line", "", @@ -158,9 +158,9 @@ "console.log(s);" ], "tests": [ - "assert(code.match(/const/g), 'message: Do not replace const keyword.');", - "assert(code.match(/const\\s+s/g), 'message: s is declared with const.');", - "assert(code.match(/const\\s+s\\s*?=\\s*?\\[\\s*?2\\s*?,\\s*?5\\s*?,\\s*?7\\s*?\\]\\s*?;/g), 'message: Do not change the original array declaration.');", + "getUserInput => assert(getUserInput('index').match(/const/g), 'message: Do not replace const keyword.');", + "getUserInput => assert(getUserInput('index').match(/const\\s+s/g), 'message: s is declared with const.');", + "getUserInput => assert(getUserInput('index').match(/const\\s+s\\s*=\\s*\\[\\s*5\\s*,\\s*7\\s*,\\s*2\\s*\\]\\s*;?/g), 'message: Do not change the original array declaration.');", "assert.deepEqual(s, [2, 5, 7], 'message: s should be equal to [2, 5, 7].');" ], "type": "waypoint", @@ -178,7 +178,8 @@ "
", "In this challenge you are going to use Object.freeze to prevent mathematical constants from changing. You need to freeze MATH_CONSTANTS object so that noone is able alter the value of PI or add any more properties to it." ], - "challengeSeed": [ + "challengeSeed": [ + "\"use strict\";", "const MATH_CONSTANTS = {", " PI: 3.14", "};", @@ -191,9 +192,9 @@ "console.log(MATH_CONSTANTS.PI);// should show 3.14" ], "tests": [ - "// Do not replace const keyword.", - "// MATH_CONSTANTS is declared with const.", - "// Do not change original MATH_CONSTANTS", + "getUserInput => assert(getUserInput('index').match(/const/g), 'message: Do not replace const keyword.');", + "getUserInput => assert(getUserInput('index').match(/const\\s+MATH_CONSTANTS/g), 'message: MATH_CONSTANTS is declared with const.');", + "getUserInput => assert(getUserInput('index').match(/const\\s+MATH_CONSTANTS\\s+=\\s+{\\s+PI:\\s+3.14\\s+};/g), 'message: Do not change original MATH_CONSTANTS.');", "assert.deepEqual(MATH_CONSTANTS, {PI: 3.14}, 'message: MATH_CONSTANTS.PI should be equal to 3.14.');" ], "type": "waypoint", @@ -214,11 +215,10 @@ "
const myFunc= () => \"value\"
", "This code will still return value by default.", "
", - "Rewrite the function assigned to the variable magic which returns a new Date() to use arrow function syntax. Also make sure nothing is defined using the keyword var.", - "Note", - "Don't forget to use strict mode." + "Rewrite the function assigned to the variable magic which returns a new Date() to use arrow function syntax. Also make sure nothing is defined using the keyword var." ], - "challengeSeed": [ + "challengeSeed": [ + "\"use strict\";", "// change code below this line", "var magic = function() {", " return new Date();", @@ -228,12 +228,11 @@ "console.log(magic());" ], "tests": [ - "// Test user did replace var keyword", - "// Test magic is const", - "// Test magic is a function", - "// Test magic() returns the correct date", - "// Test function keyword was not used", - "// Test arrow => was used" + "getUserInput => assert(!getUserInput('index').match(/var/g), 'message: User did replace var keyword.');", + "getUserInput => assert(getUserInput('index').match(/const\\s+magic/g), 'message: magic is const.');", + "assert(typeof magic === 'function', 'message: magic is a function.');", + "assert(magic().getDate() == new Date().getDate(), 'message: magic() returns correct date.');", + "getUserInput => assert(!getUserInput('index').match(/function/g), 'message: function keyword was not used.');" ], "type": "waypoint", "releasedOn": "Feb 17, 2017", @@ -248,11 +247,10 @@ "
// doubles input value and returns it
const doubler = (item) => item * 2;
", "You can pass more than one argument into arrow functions as well.", "
", - "Rewrite the myConcat function which appends contents of arr2 to arr1 so that the function uses arrow function syntax.", - "Note", - "Don't forget to use strict mode." + "Rewrite the myConcat function which appends contents of arr2 to arr1 so that the function uses arrow function syntax." ], - "challengeSeed": [ + "challengeSeed": [ + "\"use strict\";", "// change code below this line", "var myConcat = function(arr1, arr2) {", " return arr1.concat(arr2);", @@ -262,12 +260,11 @@ "console.log(myConcat([1, 2], [3, 4, 5]));" ], "tests": [ - "// Test user did replace var keyword", - "// Test myConcat is const", - "assert(typeof myConcat === \"function\", 'message: myConcat should be a function');", - "// Test myConcat() returns the correct array", - "// Test function keyword was not used", - "// Test arrow => was used" + "getUserInput => assert(!getUserInput('index').match(/var/g), 'message: User did replace var keyword.');", + "getUserInput => assert(getUserInput('index').match(/const\\s+myConcat/g), 'message: myConcat is const.');", + "assert(typeof myConcat === 'function', 'message: myConcat should be a function');", + "assert(() => { const a = myConcat([1], [2]); return a[0] == 1 && a[1] == 2; }, 'message: myConcat() returns the correct array');", + "getUserInput => assert(!getUserInput('index').match(/function/g), 'message: function keyword was not used.');" ], "type": "waypoint", "releasedOn": "Feb 17, 2017", @@ -286,11 +283,10 @@ "
FBPosts.filter((post) => post.thumbnail !== null && post.shares > 100 && post.likes > 500)
", "This code is more succinct and accomplishes the same task with fewer lines of code.", "
", - "Use arrow function syntax to compute the square of only the positive integers (fractions are not integers) in the array realNumberArray and store the new array in the variable squaredIntegers.", - "Note", - "Don't forget to use strict mode." + "Use arrow function syntax to compute the square of only the positive integers (fractions are not integers) in the array realNumberArray and store the new array in the variable squaredIntegers." ], - "challengeSeed": [ + "challengeSeed": [ + "\"use strict\";", "const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34];", "// change code below this line", "var squaredIntegers = realNumberArray;", @@ -299,14 +295,13 @@ "console.log(squaredIntegers);" ], "tests": [ - "// Test user did replace var keyword", - "// Test squaredIntegers is const", + "getUserInput => assert(!getUserInput('index').match(/var/g), 'message: User did replace var keyword.');", + "getUserInput => assert(getUserInput('index').match(/const\\s+squaredIntegers/g), 'message: squaredIntegers is const.');", "assert(Array.isArray(squaredIntegers), 'message: squaredIntegers should be an array');", "assert(squaredIntegers[0] === 16 && squaredIntegers[1] === 1764 && squaredIntegers[2] === 36, 'message: squaredIntegers should be [16, 1764, 36]');", - "// Test function keyword was not used", - "// Test arrow => was used", - "assert(!code.match(/(for)|(while)/g), 'message: loop should not be used');", - "assert(code.match(/map/g) && code.match(/filter/g), 'message: map and filter should be used');" + "getUserInput => assert(!getUserInput('index').match(/function/g), 'message: function keyword was not used.');", + "getUserInput => assert(!getUserInput('index').match(/(for)|(while)/g), 'message: loop should not be used');", + "getUserInput => assert(getUserInput('index').match(/map|filter|reduce/g), 'message: map, filter, or reduce should be used');" ], "type": "waypoint", "releasedOn": "Feb 17, 2017", @@ -322,10 +317,10 @@ "
function greeting(name = \"Anonymous\") {
return \"Hello \" + name;
}
console.log(greeting(\"John\")); // Hello John
console.log(greeting()); // Hello Anonymous
", "The default parameter kicks in when the argument is not specified (it is undefined). As you can see in the example above, the parameter name will receive its default value \"Anonymous\" when you do not provide a value for the parameter. You can add default values for as many parameters as you want.", "
", - "Modify the function increment by adding default parameters so that it will add 1 to number if value is not specified.", - "Note
Don't forget to use strict mode." + "Modify the function increment by adding default parameters so that it will add 1 to number if value is not specified." ], - "challengeSeed": [ + "challengeSeed": [ + "\"use strict\";", "function increment(number, value) {", " return number + value;", "}", @@ -333,9 +328,9 @@ "console.log(increment(5)); // returns NaN" ], "tests": [ - "assert(increment(5, 2) === 7, \"The result of increment(5, 2) should be 7\");", - "assert(increment(5) === 6, \"The result of increment(5) should be 6\");", - "// Test default parameter was used for 'value'" + "assert(increment(5, 2) === 7, 'message: The result of increment(5, 2) should be 7.');", + "assert(increment(5) === 6, 'message: The result of increment(5) should be 6.');", + "getUserInput => assert(getUserInput('index').match(/value\\s*=\\s*1/g), 'message: default parameter 1 was used for value.');" ], "type": "waypoint", "releasedOn": "Feb 17, 2017", @@ -351,10 +346,10 @@ "
function howMany(...args) {
return \"You have passed \" + args.length + \" arguments.\";
}
console.log(howMany(0, 1, 2)); // You have passed 3 arguments
console.log(howMany(\"string\", null, [1, 2, 3], { })); // You have passed 4 arguments.
", "The rest operator eliminates the need to check the args array and allows us to apply map(), filter() and reduce() on the parameters array.", "
", - "Modify the function sum so that is uses the rest operator and it works in the same way with any number of parameters.", - "Note
Don't forget to use strict mode." + "Modify the function sum so that is uses the rest operator and it works in the same way with any number of parameters." ], - "challengeSeed": [ + "challengeSeed": [ + "\"use strict\";", "function sum(x, y, z) {", " const array = [ x, y, z ];", " return array.reduce((a, b) => a + b, 0);", @@ -362,10 +357,11 @@ "console.log(sum(1, 2, 3)); // 6" ], "tests": [ - "assert(sum(0,1,2) === 3, 'The result of sum(0,1,2) should be 3');", - "assert(sum(1,2,3,4) === 10, 'The result of sum(1,2,3,4) should be 10');", - "assert(sum(5) === 5, 'The result of sum(5) should be 5');", - "assert(sum() === 0, 'The result of sum() should be 0');" + "assert(sum(0,1,2) === 3, 'message: The result of sum(0,1,2) should be 3');", + "assert(sum(1,2,3,4) === 10, 'message: The result of sum(1,2,3,4) should be 10');", + "assert(sum(5) === 5, 'message: The result of sum(5) should be 5');", + "assert(sum() === 0, 'message: The result of sum() should be 0');", + "getUserInput => assert(getUserInput('index').match(/function\\s+sum\\s*\\(\\s*...args\\s*\\)\\s*{/g), 'message: The sum function uses the ... spread operator on the args parameter.');" ], "type": "waypoint", "releasedOn": "Feb 17, 2017", @@ -388,16 +384,16 @@ "
", "Copy all contents of arr1 into another array arr2 using the spread operator." ], - "challengeSeed": [ + "challengeSeed": [ + "\"use strict\";", "const arr1 = ['JAN', 'FEB', 'MAR', 'APR', 'MAY'];", - "const arr2 = []; // change this line", - "arr1.push('JUN');", - "console.log(arr2); // arr2 should not be affected" + "const arr2 = [] // change this line", + "console.log(arr2);" ], "tests": [ - "// Test arr2 is correct copy of arr1", - "// Test arr1 has changed", - "// Test spread operator was used" + "assert(arr2.every((v, i) => v === arr1[i]), 'message: arr2 is correct copy of arr1.');", + "getUserInput => assert(getUserInput('index').match(/\\[\\s*...arr1\\s*\\]/g),'message: ... spread operator was used to duplicate arr1.');", + "assert((arr1, arr2) => {arr1.push('JUN'); return arr2.length < arr1.length},'message: arr2 remains unchanged when arr1 is changed.');" ], "type": "waypoint", "releasedOn": "Feb 17, 2017", @@ -408,7 +404,7 @@ "id": "587d7b89367417b2b2512b49", "title": "Use Destructuring Assignment to Assign Variables from Objects", "description": [ - "We earlier saw how spread operator can effectively spread, or unpack, the contents of the array.", + "We saw earlier how spread operator can effectively spread, or unpack, the contents of the array.", "We can do something similar with objects as well. Destructuring assignment is special syntax for neatly assigning values taken directly from an object to variables.", "Consider the following ES5 code:", "
var voxel = {x: 3.6, y: 7.4, z: 6.54 };
var x = voxel.x; // x = 3.6
var y = voxel.y; // y = 7.4
var z = voxel.z; // z = 6.54
", @@ -418,18 +414,22 @@ "
const { x : a, y : b, z : c } = voxel // a = 3.6, b = 7.4, c = 6.54
", "You may read it as \"get the field x and copy the value into a,\" and so on.", "
", - "Use destructuring to obtain the length of the string greeting" + "Use destructuring to obtain the length of the string greeting, and assign the length to len" ], - "challengeSeed": [ + "challengeSeed": [ + "\"use strict\";", "const greeting = 'itadakimasu';", + "", "// change code below this line", "const length = 0; // change this", "// change code above this line", + "", "console.log(length); // should be using destructuring" ], "tests": [ - "// Test len is 11", - "// Test destructuring was used" + "assert(typeof len === 'number', 'message: variable len exists and is a number.');", + "assert(len === 11, 'message: len equals 11');", + "getUserInput => assert(getUserInput('index').match(/\\{\\s*length\\s*:\\s*len\\s*}\\s*=\\s*greeting/g),'message: destructuring was used');" ], "type": "waypoint", "releasedOn": "Feb 17, 2017", @@ -447,7 +447,8 @@ "
", "Use destructuring assignment to obtain max of forecast.tomorrow and assign it to maxOfTomorrow." ], - "challengeSeed": [ + "challengeSeed": [ + "\"use strict\";", "const forecast = {", " today: { min: 72, max: 83 },", " tomorrow: { min: 73.3, max: 84.6 }", @@ -458,8 +459,8 @@ "console.log(maxOfTomorrow); // should be 84.6" ], "tests": [ - "// Test maxOfTomorrow to be 84.6", - "// Test destructuring was used" + "assert(maxOfTomorrow === 84.6, 'message: maxOfTomorrow equals 84.6');", + "getUserInput => assert(getUserInput('index').match(/\\{\\s*tomorrow\\s*:\\s*\\{\\s*max\\s*:\\s*maxOfTomorrow\\s*\\}\\s*\\}\\s*=\\s*forecast/g),'message: nested destructuring was used');" ], "type": "waypoint", "releasedOn": "Feb 17, 2017", @@ -480,7 +481,8 @@ "
", "Use destructuring assignment to swap the values of a and b so that a receives the value stored in b, and b receives the value stored in a." ], - "challengeSeed": [ + "challengeSeed": [ + "\"use strict\";", "let a = 8, b = 6;", "// change code below this line", "", @@ -510,7 +512,8 @@ "
", "Use destructuring assignment with the rest operator to perform an effective Array.prototype.slice() so that arr is a sub-array of the original array source with the first two elements ommitted." ], - "challengeSeed": [ + "challengeSeed": [ + "\"use strict\";", "const source = [1,2,3,4,5,6,7,8,9,10];", "// change code below this line", "const arr = source; // change this", @@ -519,10 +522,9 @@ "console.log(source); // should be [1,2,3,4,5,6,7,8,9,10];" ], "tests": [ - "// Test arr is [3,4,5,6,7,8,9,10];", - "// Test source is [1,2,3,4,5,6,7,8,9,10];", - "// Test destructuring was used", - "// Test slice was not used" + "assert(arr.every((v, i) => v === i + 3),'message: arr is [3,4,5,6,7,8,9,10]');", + "getUserInput => assert(getUserInput('index').match(/\\[\\s*\\w\\s*,\\s*\\w\\s*,\\s*...arr\\s*\\]/g),'message: destructuring was used.');", + "getUserInput => assert(!getUserInput('index').match(/Array.slice\\(\\)/g), 'message: Array.slice() was not used.');" ], "type": "waypoint", "releasedOn": "Feb 17, 2017", @@ -543,7 +545,8 @@ "
", "Use destructuring assignment within the argument to the function half to send only max and min inside the function." ], - "challengeSeed": [ + "challengeSeed": [ + "\"use strict\";", "const stats = {", " max: 56.78,", " standard_deviation: 4.34,", @@ -559,9 +562,9 @@ "console.log(half(stats)); // should be 28.015" ], "tests": [ - "// Test stats is an object", - "// Test half is 28.015", - "// Test destructuring was used" + "assert(typeof stats === 'object', 'message: stats is an object.');", + "assert(half(stats) === 28.015, 'message: half(stats) is 28.015');", + "getUserInput => assert(getUserInput('index').match(/\\(\\s*\\{\\s*\\w+\\s*,\\s*\\w+\\s*\\}\\s*\\)/g), 'message: destructuring was used.');" ], "type": "waypoint", "releasedOn": "Feb 17, 2017", @@ -580,18 +583,19 @@ "Secondly, the example uses backticks (`), not quotes (' or \"), to wrap the string. Notice that the string is multi-line.", "This new way of creating strings gives you more flexibility to create robust strings.", "
", - "Use template literal syntax with backticks to display each entry of the result object's failure array. Each entry should be wrapped inside an li element with the class attribute text-warning." + "Use template literal syntax with backticks to display each entry of the result object's failure array. Each entry should be wrapped inside an li element with the class attribute text-warning, and listed within the resultDisplayArray." ], - "challengeSeed": [ + "challengeSeed": [ + "\"use strict\";", "const result = {", " success: [\"max-length\", \"no-amd\", \"prefer-arrow-functions\"],", " failure: [\"no-var\", \"var-on-top\", \"linebreak\"],", " skipped: [\"id-blacklist\", \"no-dup-keys\"]", "};", "// change code below this line", - "const resultDisplay = null;", + "const resultDisplayArray = null;", "// change code above this line", - "console.log(resultDisplay);", + "console.log(resultDisplayArray);", "/**", " * should look like this", " *
  • no-var
  • ", @@ -600,9 +604,9 @@ " **/" ], "tests": [ - "// Test resultDisplay is a string", - "// Test resultDisplay is the desired output", - "// Test template strings were used" + "assert(typeof resultDisplayArray === 'object' && resultDisplayArray.length === 3, 'message: resultDisplayArray is a list containing result failure messages.');", + "assert(resultDisplayArray.every((v, i) => v === `
  • ${result.failure[i]}
  • `), 'message: resultDisplayArray is the desired output.');", + "getUserInput => assert(getUserInput('index').match(/\\`
  • \\$\\{v\\}<\\/li>\\`/g), 'message: Template strings were used');" ], "type": "waypoint", "releasedOn": "Feb 17, 2017", @@ -623,7 +627,8 @@ "
    ", "Use simple fields with object literals to create and return a Person object." ], - "challengeSeed": [ + "challengeSeed": [ + "\"use strict\";", "// change code below this line", "const createPerson = (name, age, gender) => {", " return {", @@ -636,8 +641,8 @@ "console.log(createPerson(\"Zodiac Hasbro\", 56, \"male\")); // returns a proper object" ], "tests": [ - "// Test the output is {name: \"Zodiac Hasbro\", age: 56, gender: \"male\"}", - "// Test no : was present" + "assert(() => {const res={name:\"Zodiac Hasbro\",age:56,gender:\"male\"}; const person=createPerson(\"Zodiac Hasbro\", 56, \"male\"); return Object.keys(person).every(k => person[k] === res[k]);}, 'message: the output is {name: \"Zodiac Hasbro\", age: 56, gender: \"male\"}.');", + "getUserInput => assert(!getUserInput('index').match(/:/g), 'message: No : were used.');" ], "type": "waypoint", "releasedOn": "Feb 17, 2017", @@ -655,7 +660,8 @@ "
    ", "Refactor the function setGear inside the object bicycle to use the shorthand syntax described above." ], - "challengeSeed": [ + "challengeSeed": [ + "\"use strict\";", "// change code below this line", "const bicycle = {", " gear: 2,", @@ -668,8 +674,8 @@ "console.log(bicycle.gear);" ], "tests": [ - "// Test the output is Sending request to Yanoshi Mimoto", - "// Test no : was present" + "assert(() => { bicycle.setGear(48); return bicycle.gear === 48 }, 'message: setGear is a function and changes the gear variable.');", + "getUserInput => assert(!getUserInput('index').match(/:\\s*function\\s*\\(\\)/g), 'message: Declarative function was used.');" ], "type": "waypoint", "releasedOn": "Feb 17, 2017", @@ -691,7 +697,8 @@ "Use class keyword and write a proper constructor to create the Vegetable class.", "The Vegetable lets you create a vegetable object, with a property name, to be passed to constructor." ], - "challengeSeed": [ + "challengeSeed": [ + "\"use strict\";", "/* Alter code below this line */", "const Vegetable = undefined;", "/* Alter code above this line */", @@ -699,9 +706,9 @@ "console.log(carrot.name); // => should be 'carrot'" ], "tests": [ - "// Test the Vegetable is a class", - "// Test that class keyword was used", - "// Test that other objects could be created with the class" + "assert(typeof Vegetable === 'function' && typeof Vegetable.constructor === 'function', 'message: Vegetable is a class');", + "getUserInput => assert(getUserInput('index').match(/class/g),'message: class keyword was used.');", + "assert(() => {const a = new Vegetable(\"apple\"); return typeof a === 'object';},'message: Instances of Vegetable can be instantiated.');" ], "type": "waypoint", "releasedOn": "Feb 17, 2017", @@ -722,13 +729,14 @@ "
    ", "Use class keyword to create a Thermostat class. The constructor accepts Farenheit temperature.", "Now create getter and setter in the class, to obtain the temperature in Celsius scale.", - "Remember that F = C * 9.0 / 5 + 32, where F is the value of temperature in Fahrenheit scale, and C is the value of the same temperature in Celsius scale", + "Remember that C = 5/9 * (F - 32) and F = C * 9.0 / 5 + 32, where F is the value of temperature in Fahrenheit scale, and C is the value of the same temperature in Celsius scale", "Note", "When you implement this, you would be tracking the temperature inside the class in one scale - either Fahrenheit or Celsius.", "This is the power of getter or setter - you are creating an API for another user, who would get the correct result, no matter which one you track.", "In other words, you are abstracting implementation details from the consumer." ], - "challengeSeed": [ + "challengeSeed": [ + "\"use strict\";", "/* Alter code below this line */", "const Thermostat = undefined;", "/* Alter code above this line */", @@ -738,9 +746,9 @@ "temp = thermos.temperature; // 26 in C" ], "tests": [ - "// Test the Thermostat is a class", - "// Test that class keyword was used", - "// Test that other objects could be created with the class" + "assert(typeof Thermostat === 'function' && typeof Thermostat.constructor === 'function','message: Thermostat is a class');", + "getUserInput => assert(getUserInput('index').match(/class/g),'message: class keyword was used.');", + "assert(() => {const t = new Thermostat(32); return typeof t === 'object' && t.temperature === 0;}, 'message: Instances of Vegetable can be instantiated.');" ], "type": "waypoint", "releasedOn": "Feb 17, 2017", @@ -758,16 +766,18 @@ "A description of the above code:", "
    import { function } from \"file_path_goes_here\"
    // We can also import variables the same way!
    ", "There are a few ways to write an import statement, but the above is a very common use-case.", - "Note
    the whitespace surrounding the function inside the curly braces is a best practice - it makes it easier to read the import statement.", - "Note
    The lessons in this section handle non-browser features. import, and the statements we introduce in the rest of these lessons, won't work on a browser directly, However, we can use various tools to create code out of this to make it work in browser.", + "Note
    The whitespace surrounding the function inside the curly braces is a best practice - it makes it easier to read the import statement.", + "Note
    The lessons in this section handle non-browser features. import, and the statements we introduce in the rest of these lessons, won't work on a browser directly. However, we can use various tools to create code out of this to make it work in browser.", + "Note
    In most cases, the file path requires a ./ before it; otherwise, node will look in the node_modules directory first trying to load it as a dependencie.", "
    ", "Add the appropriate import statement that will allow the current file to use the capitalizeString function. The file where this function lives is called \"string_functions\", and it is in the same directory as the current file." ], - "challengeSeed": [ + "challengeSeed": [ + "\"use strict\";", "capitalizeString(\"hello!\");" ], "tests": [ - "assert(code.match(/import\\s+\\{\\s?capitalizeString\\s?\\}\\s+from\\s+\"string_functions\"/ig)" + "getUserInput => assert(getUserInput('index').match(/import\\s+\\{\\s?capitalizeString\\s?\\}\\s+from\\s+\"string_functions\"/g), 'message: valid import statement');" ], "type": "waypoint", "releasedOn": "Feb 17, 2017", @@ -787,13 +797,14 @@ "
    ", "Below are two variables that I want to make available for other files to use. Utilizing the first way I demonstrated export, export the two variables." ], - "challengeSeed": [ + "challengeSeed": [ + "\"use strict\";", "const foo = \"bar\";", "const boo = \"far\";" ], "tests": [ - "assert(code.match(/export\\s+const\\s+foo\\s+=+\\s\"bar\"/ig))", - "assert(code.match(/export\\s+const\\s+boo\\s+=+\\s\"far\"/ig))" + "getUserInput => assert(getUserInput('index').match(/export\\s+const\\s+foo\\s+=+\\s\"bar\"/g), 'message: foo is exported.');", + "getUserInput => assert(getUserInput('index').match(/export\\s+const\\s+boo\\s+=+\\s\"far\"/g), 'message: bar is exported.');" ], "type": "waypoint", "releasedOn": "Feb 17, 2017", @@ -809,16 +820,17 @@ "
    import * as myMathModule from \"math_functions\"
    myMathModule.add(2,3);
    myMathModule.subtract(5,3);
    ", "And breaking down that code:", "
    import * as object_with_name_of_your_choice from \"file_path_goes_here\"
    object_with_name_of_your_choice.imported_function
    ", - "You may use any name following the import * as portion of the statement. In order to utilize this method, it requires an object that receives the imported values. From here, you will use the dot notation to call your imported values.", + "You may use any name following the import * as portion of the statement. In order to utilize this method, it requires an object that receives the imported values. From here, you will use the dot notation to call your imported values.", "
    ", "The code below requires the contents of a file, \"capitalize_strings\", found in the same directory as it, imported. Add the appropriate import * statement to the top of the file, using the object provided." ], - "challengeSeed": [ + "challengeSeed": [ + "\"use strict\";", "myStringModule.capitalize(\"foo\");", "myStringModule.lowercase(\"Foo\");" ], "tests": [ - "assert(code.match(/import\\s+\\*\\s+as\\s+myStringModule\\s+from\\s+\"capitalize_strings\"/ig))" + "getUserInput => assert(getUserInput('index').match(/import\\s+\\*\\s+as\\s+myStringModule\\s+from\\s+\"capitalize_strings\"/g), 'message: Properly uses import * as syntax.');" ], "type": "waypoint", "releasedOn": "Feb 17, 2017", @@ -837,11 +849,12 @@ "
    ", "The following function should be the fallback value for the module. Please add the necessary code to do so." ], - "challengeSeed": [ + "challengeSeed": [ + "\"use strict\";", "function subtract(x,y) {return x - y;}" ], "tests": [ - "assert(code.match(/export\\s+default\\s+function\\s+subtract\\(x,y\\)\\s+{return\\s+x\\s-\\s+y;}/ig))" + "getUserInput => assert(getUserInput('index').match(/export\\s+default\\s+function\\s+subtract\\(x,y\\)\\s+{return\\s+x\\s-\\s+y;}/g), 'message: Proper used of export fallback.');" ], "type": "waypoint", "releasedOn": "Feb 17, 2017", @@ -859,11 +872,12 @@ "
    ", "In the following code, please import the default export, subtract, from the file \"math_functions\", found in the same directory as this file." ], - "challengeSeed": [ + "challengeSeed": [ + "\"use strict\";", "subtract(7,4);" ], "tests": [ - "assert(code.match(/import\\s+subtract\\s+from\\s+\"math_functions\"/ig))" + "getUserInput => assert(getUserInput('index').match(/import\\s+subtract\\s+from\\s+\"math_functions\"/g), 'message: Properly imports export default method.');" ], "type": "waypoint", "releasedOn": "Feb 17, 2017",