|
40 | 40 | "<hr>",
|
41 | 41 | "Replace <code>var</code> with <code>let</code>"
|
42 | 42 | ],
|
43 |
| - "challengeSeed": [ |
| 43 | + "challengeSeed": [ |
44 | 44 | "var catName;",
|
45 | 45 | "var quote;",
|
46 | 46 | "function catTalk() {",
|
|
81 | 81 | "Fix the code so that <code>i</code> declared in the if statement is a separate variable than <code>i</code> declared in the first line of the function. Be certain not to use the <code>var</code> keyword anywhere in your code.",
|
82 | 82 | "This exercise is designed to illustrate the difference between how <code>var</code> and <code>let</code> 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."
|
83 | 83 | ],
|
84 |
| - "challengeSeed": [ |
| 84 | + "challengeSeed": [ |
85 | 85 | "",
|
86 | 86 | "function checkScope() {",
|
87 |
| - "\"use strict\";", |
| 87 | + "\"use strict\";", |
88 | 88 | " var i = \"function scope\";",
|
89 | 89 | " if (true) {",
|
90 | 90 | " i = \"block scope\";",
|
|
115 | 115 | "<hr>",
|
116 | 116 | "Change the code so that all variables are declared using <code>let</code> or <code>const</code>. Use <code>let</code> when you want the variable to change, and <code>const</code> when you want the variable to remain constant. Also, rename variables declared with <code>const</code> to conform to common practices, meaning constants should be in all caps"
|
117 | 117 | ],
|
118 |
| - "challengeSeed": [ |
| 118 | + "challengeSeed": [ |
119 | 119 | "function printManyTimes(str) {",
|
120 |
| - " \"use strict\";", |
| 120 | + " \"use strict\";", |
121 | 121 | "",
|
122 | 122 | " // change code below this line",
|
123 | 123 | "",
|
|
153 | 153 | "<hr>",
|
154 | 154 | "An array is declared as <code>const s = [5, 7, 2]</code>. Change the array to <code>[2, 5, 7]</code> using various element assignment."
|
155 | 155 | ],
|
156 |
| - "challengeSeed": [ |
| 156 | + "challengeSeed": [ |
157 | 157 | "const s = [5, 7, 2];",
|
158 | 158 | "function editInPlace() {",
|
159 |
| - " \"use strict\";", |
| 159 | + " \"use strict\";", |
160 | 160 | " // change code below this line",
|
161 | 161 | "",
|
162 | 162 | " // s = [2, 5, 7]; <- this is invalid",
|
|
186 | 186 | "<hr>",
|
187 | 187 | "In this challenge you are going to use <code>Object.freeze</code> to prevent mathematical constants from changing. You need to freeze <code>MATH_CONSTANTS</code> object so that noone is able alter the value of <code>PI</code> or add any more properties to it."
|
188 | 188 | ],
|
189 |
| - "challengeSeed": [ |
| 189 | + "challengeSeed": [ |
190 | 190 | "function freezeObj() {",
|
191 | 191 | " \"use strict\";",
|
192 | 192 | " const MATH_CONSTANTS = {",
|
|
196 | 196 | "",
|
197 | 197 | "",
|
198 | 198 | " // change code above this line",
|
199 |
| - " try {", |
| 199 | + " try {", |
200 | 200 | " MATH_CONSTANTS.PI = 99;",
|
201 | 201 | " } catch( ex ) {",
|
202 | 202 | " console.log(ex);",
|
|
231 | 231 | "<hr>",
|
232 | 232 | "Rewrite the function assigned to the variable <code>magic</code> which returns a new <code>Date()</code> to use arrow function syntax. Also make sure nothing is defined using the keyword <code>var</code>."
|
233 | 233 | ],
|
234 |
| - "challengeSeed": [ |
| 234 | + "challengeSeed": [ |
235 | 235 | "var magic = function() {",
|
236 | 236 | " \"use strict\";",
|
237 | 237 | " return new Date();",
|
|
259 | 259 | "<hr>",
|
260 | 260 | "Rewrite the <code>myConcat</code> function which appends contents of <code>arr2</code> to <code>arr1</code> so that the function uses arrow function syntax."
|
261 | 261 | ],
|
262 |
| - "challengeSeed": [ |
| 262 | + "challengeSeed": [ |
263 | 263 | "var myConcat = function(arr1, arr2) {",
|
264 | 264 | " \"use strict\";",
|
265 | 265 | " return arr1.concat(arr2);",
|
|
272 | 272 | "getUserInput => assert(getUserInput('index').match(/const\\s+myConcat/g), 'message: <code>myConcat</code> should be a constant variable (by using <code>const</code>).');",
|
273 | 273 | "assert(typeof myConcat === 'function', 'message: <code>myConcat</code> should be a function');",
|
274 | 274 | "assert(() => { const a = myConcat([1], [2]); return a[0] == 1 && a[1] == 2; }, 'message: <code>myConcat()</code> returns the correct <code>array</code>');",
|
275 |
| - "getUserInput => assert(!getUserInput('index').match(/function/g), 'message: <code>function</code> keyword was not used.');" |
| 275 | + "getUserInput => assert(!getUserInput('index').match(/function/g), 'message: <code>function</code> keyword was not used.');" |
276 | 276 | ],
|
277 | 277 | "type": "waypoint",
|
278 | 278 | "releasedOn": "Feb 17, 2017",
|
|
293 | 293 | "<hr>",
|
294 | 294 | "Use arrow function syntax to compute the square of only the positive integers (fractions are not integers) in the array <code>realNumberArray</code> and store the new array in the variable <code>squaredIntegers</code>."
|
295 | 295 | ],
|
296 |
| - "challengeSeed": [ |
| 296 | + "challengeSeed": [ |
297 | 297 | "const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34];",
|
298 | 298 | "const squareList = (arr) => {",
|
299 | 299 | " \"use strict\";",
|
|
311 | 311 | "getUserInput => assert(getUserInput('index').match(/const\\s+squaredIntegers/g), 'message: <code>squaredIntegers</code> should be a constant variable (by using <code>const</code>).');",
|
312 | 312 | "assert(Array.isArray(squaredIntegers), 'message: <code>squaredIntegers</code> should be an <code>array</code>');",
|
313 | 313 | "assert(squaredIntegers[0] === 16 && squaredIntegers[1] === 1764 && squaredIntegers[2] === 36, 'message: <code>squaredIntegers</code> should be <code>[16, 1764, 36]</code>');",
|
314 |
| - "getUserInput => assert(!getUserInput('index').match(/function/g), 'message: <code>function</code> keyword was not used.');", |
| 314 | + "getUserInput => assert(!getUserInput('index').match(/function/g), 'message: <code>function</code> keyword was not used.');", |
315 | 315 | "getUserInput => assert(!getUserInput('index').match(/(for)|(while)/g), 'message: loop should not be used');",
|
316 | 316 | "getUserInput => assert(getUserInput('index').match(/map|filter|reduce/g), 'message: <code>map</code>, <code>filter</code>, or <code>reduce</code> should be used');"
|
317 | 317 | ],
|
|
331 | 331 | "<hr>",
|
332 | 332 | "Modify the function <code>increment</code> by adding default parameters so that it will add 1 to <code>number</code> if <code>value</code> is not specified."
|
333 | 333 | ],
|
334 |
| - "challengeSeed": [ |
| 334 | + "challengeSeed": [ |
335 | 335 | "const increment = (function() {",
|
336 | 336 | " \"use strict\";",
|
337 | 337 | " return function increment(number, value) {",
|
|
362 | 362 | "<hr>",
|
363 | 363 | "Modify the function <code>sum</code> so that is uses the rest operator and it works in the same way with any number of parameters."
|
364 | 364 | ],
|
365 |
| - "challengeSeed": [ |
| 365 | + "challengeSeed": [ |
366 | 366 | "const sum = (function() {",
|
367 |
| - " \"use strict\";", |
| 367 | + " \"use strict\";", |
368 | 368 | " return function sum(x, y, z) {",
|
369 | 369 | " const array = [ x, y, z ];",
|
370 | 370 | " return array.reduce((a, b) => a + b, 0);",
|
|
400 | 400 | "<hr>",
|
401 | 401 | "Copy all contents of <code>arr1</code> into another array <code>arr2</code> using the spread operator."
|
402 | 402 | ],
|
403 |
| - "challengeSeed": [ |
404 |
| - "const arr1 = ['JAN', 'FEB', 'MAR', 'APR', 'MAY'];", |
405 |
| - "let arr2;", |
| 403 | + "challengeSeed": [ |
| 404 | + "const arr1 = ['JAN', 'FEB', 'MAR', 'APR', 'MAY'];", |
| 405 | + "let arr2;", |
406 | 406 | "(function() {",
|
407 | 407 | " \"use strict\";",
|
408 | 408 | " arr2 = []; // change this line",
|
|
435 | 435 | "<hr>",
|
436 | 436 | "Use destructuring to obtain the length of the input string <code>str</code>, and assign the length to <code>len</code> in line."
|
437 | 437 | ],
|
438 |
| - "challengeSeed": [ |
| 438 | + "challengeSeed": [ |
439 | 439 | "function getLength(str) {",
|
440 | 440 | " \"use strict\";",
|
441 | 441 | "",
|
|
470 | 470 | "<hr>",
|
471 | 471 | "Use destructuring assignment to obtain <code>max</code> of <code>forecast.tomorrow</code> and assign it to <code>maxOfTomorrow</code>."
|
472 | 472 | ],
|
473 |
| - "challengeSeed": [ |
| 473 | + "challengeSeed": [ |
474 | 474 | "const LOCAL_FORECAST = {",
|
475 | 475 | " today: { min: 72, max: 83 },",
|
476 | 476 | " tomorrow: { min: 73.3, max: 84.6 }",
|
|
509 | 509 | "<hr>",
|
510 | 510 | "Use destructuring assignment to swap the values of <code>a</code> and <code>b</code> so that <code>a</code> receives the value stored in <code>b</code>, and <code>b</code> receives the value stored in <code>a</code>."
|
511 | 511 | ],
|
512 |
| - "challengeSeed": [ |
| 512 | + "challengeSeed": [ |
513 | 513 | "let a = 8, b = 6;",
|
514 | 514 | "(() => {",
|
515 |
| - " \"use strict\";", |
| 515 | + " \"use strict\";", |
516 | 516 | " // change code below this line",
|
517 | 517 | " ",
|
518 | 518 | " // change code above this line",
|
|
542 | 542 | "<hr>",
|
543 | 543 | "Use destructuring assignment with the rest operator to perform an effective <code>Array.prototype.slice()</code> so that <code>arr</code> is a sub-array of the original array <code>source</code> with the first two elements ommitted."
|
544 | 544 | ],
|
545 |
| - "challengeSeed": [ |
| 545 | + "challengeSeed": [ |
546 | 546 | "const source = [1,2,3,4,5,6,7,8,9,10];",
|
547 | 547 | "function removeFirstTwo(list) {",
|
548 | 548 | " \"use strict\";",
|
|
579 | 579 | "<hr>",
|
580 | 580 | "Use destructuring assignment within the argument to the function <code>half</code> to send only <code>max</code> and <code>min</code> inside the function."
|
581 | 581 | ],
|
582 |
| - "challengeSeed": [ |
| 582 | + "challengeSeed": [ |
583 | 583 | "const stats = {",
|
584 | 584 | " max: 56.78,",
|
585 | 585 | " standard_deviation: 4.34,",
|
|
589 | 589 | " average: 35.85",
|
590 | 590 | "};",
|
591 | 591 | "const half = (function() {",
|
592 |
| - " \"use strict\"; // do not change this line", |
| 592 | + " \"use strict\"; // do not change this line", |
593 | 593 | "",
|
594 |
| - " // change code below this line", |
| 594 | + " // change code below this line", |
595 | 595 | " return function half(stats) {",
|
596 | 596 | " // use function argument destructuring",
|
597 | 597 | " return (stats.max + stats.min) / 2.0;",
|
|
626 | 626 | "<hr>",
|
627 | 627 | "Use template literal syntax with backticks to display each entry of the <code>result</code> object's <code>failure</code> array. Each entry should be wrapped inside an <code>li</code> element with the class attribute <code>text-warning</code>, and listed within the <code>resultDisplayArray</code>."
|
628 | 628 | ],
|
629 |
| - "challengeSeed": [ |
| 629 | + "challengeSeed": [ |
630 | 630 | "const result = {",
|
631 | 631 | " success: [\"max-length\", \"no-amd\", \"prefer-arrow-functions\"],",
|
632 | 632 | " failure: [\"no-var\", \"var-on-top\", \"linebreak\"],",
|
|
673 | 673 | "<hr>",
|
674 | 674 | "Use simple fields with object literals to create and return a <code>Person</code> object."
|
675 | 675 | ],
|
676 |
| - "challengeSeed": [ |
| 676 | + "challengeSeed": [ |
677 | 677 | "const createPerson = (name, age, gender) => {",
|
678 | 678 | " \"use strict\";",
|
679 | 679 | " // change code below this line",
|
|
706 | 706 | "<hr>",
|
707 | 707 | "Refactor the function <code>setGear</code> inside the object <code>bicycle</code> to use the shorthand syntax described above."
|
708 | 708 | ],
|
709 |
| - "challengeSeed": [ |
710 |
| - |
| 709 | + "challengeSeed": [ |
| 710 | + |
711 | 711 | "// change code below this line",
|
712 | 712 | "const bicycle = {",
|
713 | 713 | " gear: 2,",
|
|
744 | 744 | "Use <code>class</code> keyword and write a proper constructor to create the <code>Vegetable</code> class.",
|
745 | 745 | "The <code>Vegetable</code> lets you create a vegetable object, with a property <code>name</code>, to be passed to constructor."
|
746 | 746 | ],
|
747 |
| - "challengeSeed": [ |
| 747 | + "challengeSeed": [ |
748 | 748 | "function makeClass() {",
|
749 | 749 | " \"use strict\";",
|
750 | 750 | " /* Alter code below this line */",
|
|
786 | 786 | "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.",
|
787 | 787 | "In other words, you are abstracting implementation details from the consumer."
|
788 | 788 | ],
|
789 |
| - "challengeSeed": [ |
| 789 | + "challengeSeed": [ |
790 | 790 | "function makeClass() {",
|
791 | 791 | " \"use strict\";",
|
792 | 792 | " /* Alter code below this line */",
|
|
827 | 827 | "<hr>",
|
828 | 828 | "Add the appropriate <code>import</code> statement that will allow the current file to use the <code>capitalizeString</code> function. The file where this function lives is called <code>\"string_functions\"</code>, and it is in the same directory as the current file."
|
829 | 829 | ],
|
830 |
| - "challengeSeed": [ |
| 830 | + "head": [ |
| 831 | + "window.require = function (str) {", |
| 832 | + "if (str === 'string_functions') {", |
| 833 | + "return {", |
| 834 | + "capitalizeString: str => str.toUpperCase()", |
| 835 | + "}}};" |
| 836 | + ], |
| 837 | + "challengeSeed": [ |
831 | 838 | "\"use strict\";",
|
832 | 839 | "capitalizeString(\"hello!\");"
|
833 | 840 | ],
|
|
852 | 859 | "<hr>",
|
853 | 860 | "Below are two variables that I want to make available for other files to use. Utilizing the first way I demonstrated <code>export</code>, export the two variables."
|
854 | 861 | ],
|
855 |
| - "challengeSeed": [ |
| 862 | + "head": [ |
| 863 | + "window.exports = function(){};" |
| 864 | + ], |
| 865 | + "challengeSeed": [ |
856 | 866 | "\"use strict\";",
|
857 | 867 | "const foo = \"bar\";",
|
858 | 868 | "const boo = \"far\";"
|
|
879 | 889 | "<hr>",
|
880 | 890 | "The code below requires the contents of a file, <code>\"capitalize_strings\"</code>, found in the same directory as it, imported. Add the appropriate <code>import *</code> statement to the top of the file, using the object provided."
|
881 | 891 | ],
|
882 |
| - "challengeSeed": [ |
| 892 | + "head": [ |
| 893 | + "window.require = function(str) {", |
| 894 | + "if (str === 'capitalize_strings') {", |
| 895 | + "return {", |
| 896 | + "capitalize: str => str.toUpperCase(),", |
| 897 | + "lowercase: str => str.toLowerCase()", |
| 898 | + "}}};" |
| 899 | + ], |
| 900 | + "challengeSeed": [ |
883 | 901 | "\"use strict\";",
|
884 | 902 | "myStringModule.capitalize(\"foo\");",
|
885 | 903 | "myStringModule.lowercase(\"Foo\");"
|
|
904 | 922 | "<hr>",
|
905 | 923 | "The following function should be the fallback value for the module. Please add the necessary code to do so."
|
906 | 924 | ],
|
907 |
| - "challengeSeed": [ |
| 925 | + "head": [ |
| 926 | + "window.exports = function(){};" |
| 927 | + ], |
| 928 | + "challengeSeed": [ |
908 | 929 | "\"use strict\";",
|
909 | 930 | "function subtract(x,y) {return x - y;}"
|
910 | 931 | ],
|
|
927 | 948 | "<hr>",
|
928 | 949 | "In the following code, please import the default export, <code>subtract</code>, from the file <code>\"math_functions\"</code>, found in the same directory as this file."
|
929 | 950 | ],
|
930 |
| - "challengeSeed": [ |
| 951 | + "head": [ |
| 952 | + "window.require = function(str) {", |
| 953 | + "if (str === 'math_functions') {", |
| 954 | + "return function(a, b) {", |
| 955 | + "return a - b;", |
| 956 | + "}}};" |
| 957 | + ], |
| 958 | + "challengeSeed": [ |
931 | 959 | "\"use strict\";",
|
932 | 960 | "subtract(7,4);"
|
933 | 961 | ],
|
|
0 commit comments