|
22 | 22 | ],
|
23 | 23 | "actions": [
|
24 | 24 | "open('let.js')",
|
25 |
| - "set('// call `varTest()`\nfunction varTest() {\n\tvar x = 1;\n\tif (true) {\n\t\tvar x = 2;\n\t\tconsole.log(x);\n\t}\n\tconsole.log(x);\n}\nvarTest();\n\n')" |
| 25 | + "set('// call `varTest()`\nfunction varTest() {\n\tvar x = 1;\n\tif (true) {\n\t\tvar x = 2;\n\t\tconsole.log(x);\n\t}\n\tconsole.log(x);\n}\nvarTest();\n\n\n')" |
26 | 26 | ]
|
27 | 27 | },
|
28 | 28 | {
|
|
31 | 31 | "1/01/02"
|
32 | 32 | ],
|
33 | 33 | "actions": [
|
34 |
| - "insert('\n// use `let` and call `letTest()`\nfunction letTest() {\n\tvar x = 3;\n\tif (true) {\n\t\tvar x = 4;\n\t\tconsole.log(x);\n\t}\n\tconsole.log(x);\n}\nletTest();\n\n')" |
| 34 | + "insert('\n// use `let` and call `letTest()`\nfunction letTest() {\n\tvar x = 3;\n\tif (true) {\n\t\tvar x = 4;\n\t\tconsole.log(x);\n\t}\n\tconsole.log(x);\n}\nletTest();\n\n\n')" |
35 | 35 | ]
|
36 | 36 | },
|
37 | 37 | {
|
38 |
| - "description": "fix the for loop to log numbers from 1 to 5", |
| 38 | + "description": "fix the broken loop to log numbers 1 to 5", |
39 | 39 | "tests": [
|
40 | 40 | "1/01/03"
|
41 | 41 | ],
|
|
48 | 48 | },
|
49 | 49 | {
|
50 | 50 | "title": "Const",
|
51 |
| - "description": "Writing basic functions continued.\n\nWe'll write two more basic functions, this time without any help.", |
| 51 | + "description": "`const` is block-scoped, much like `let` statement.\n\nHowever, the value of a constant cannot change through re-assignment, and it can't be redeclared.\n\n```js\nconst name = 'Shawn';\nname = 'Ben'; // Uncaught TypeError\nconsole.log(name); // Shawn\n```\n\n*Note: Atom uses an older version of Chrome that does not fully implement const yet. Const will work in Atom after a few months.*", |
52 | 52 | "tasks": [
|
53 | 53 | {
|
54 |
| - "description": "write a function `divideOne` divides a number by 1", |
| 54 | + "description": "Declare \"person\" as a `const`", |
55 | 55 | "tests": [
|
56 | 56 | "1/02/01"
|
57 | 57 | ],
|
58 | 58 | "actions": [
|
59 |
| - "open('page-02.js')", |
60 |
| - "set('// divideOne\nfunction divideOne(x) {\n return ::>\n}\n')" |
| 59 | + "open('const.js')", |
| 60 | + "set('/*\nNote: Atom uses an older version of Chrome (47) that does not fully implement `const` yet.\n\n`const` will work in a later version of chrome, so these tests are currently skipped.\n*/\n\n// change password into a const so that it\n// cannot be redeclared\nvar password = 'PASS';\npassword = '1234';\n\n\n')" |
61 | 61 | ]
|
62 | 62 | },
|
63 | 63 | {
|
64 |
| - "description": "write a function `mutiplyone` that multiplies a number by 1", |
| 64 | + "description": "Declare \"person\" as a constant. Check the log to see what will happen.", |
65 | 65 | "tests": [
|
66 | 66 | "1/02/02"
|
67 | 67 | ],
|
68 | 68 | "actions": [
|
69 |
| - "insert('\n// multiplyOne\nfunction multiplyOne(x) {\n return ::>\n}\n')" |
| 69 | + "insert('\n// declare person as a const\n// cannot be redeclared\nvar person = {\n name: 'Shawn',\n city: 'Vancouver'\n};\n\nperson = {\n name: 'Unknown',\n city: 'Las Vegas'\n};\n\nperson.favoriteColor = 'blue';\n\n// what will the output be?\nconsole.log(person);\n\n\n')" |
| 70 | + ] |
| 71 | + }, |
| 72 | + { |
| 73 | + "description": "Declare \"people\" as a constant. Check the log again.", |
| 74 | + "tests": [ |
| 75 | + "1/02/03" |
| 76 | + ], |
| 77 | + "actions": [ |
| 78 | + "insert('\n// declare people as a const\n\nvar people = ['Mandi', 'Mack', 'Ben'];\n\npeople = [];\n\npeople.push('Shawn');\n\n// what will the output be?\nconsole.log(people);\n\n')" |
70 | 79 | ]
|
71 | 80 | }
|
72 | 81 | ]
|
| 82 | + }, |
| 83 | + { |
| 84 | + "title": "Arrow Functions", |
| 85 | + "description": "An arrow function (`=>`) expression has a shorter syntax compared to function expressions and lexically binds the `this` value.\n\nArrow functions are always anonymous.\n\n```js\n// multi-line\nconst add = (x, y) => {\n\treturn x + y;\n};\n// single line, auto returns\nconst subtractOne = x => x - 1;\nconst getOne = () => 1;\n```", |
| 86 | + "tasks": [ |
| 87 | + { |
| 88 | + "description": "Change the \"greet\" function to use an `=>` function", |
| 89 | + "tests": [ |
| 90 | + "1/03/01" |
| 91 | + ], |
| 92 | + "actions": [ |
| 93 | + "open('arrow-function.js')", |
| 94 | + "set('// use =>\nconst greet = function (name) {\n\treturn 'hello ' + name;\n}\n\n\n')" |
| 95 | + ] |
| 96 | + }, |
| 97 | + { |
| 98 | + "description": "Change the \"getName\" function to use an `=>` function without using the keyword `return`", |
| 99 | + "tests": [ |
| 100 | + "1/03/02" |
| 101 | + ], |
| 102 | + "actions": [ |
| 103 | + "insert('\n// use => no return statement\nconst getName = function getName() {\n\treturn 'Joe';\n}\n\n\n')" |
| 104 | + ] |
| 105 | + }, |
| 106 | + { |
| 107 | + "description": "Fix the broken clock by using arrow functions.", |
| 108 | + "tests": [ |
| 109 | + "1/03/03" |
| 110 | + ], |
| 111 | + "actions": [ |
| 112 | + "insert('\n// fix the clock\n// http://codepen.io/redacademy/pen/mPjXVW\n\n')" |
| 113 | + ] |
| 114 | + } |
| 115 | + ], |
| 116 | + "onPageComplete": "Great! Now you should have a good idea how to use `=>` functions, and how arrow functions solve the confusion over `this`" |
| 117 | + }, |
| 118 | + { |
| 119 | + "title": "Template Literal", |
| 120 | + "description": "Template literals are string literals allowing embedded expressions. You can use multi-line strings and string interpolation features with them.\n\nTemplate strings are wrapped in the backtick symbol: '\\`'. Variables can be put inside of template strings using `${ name }` syntax.\n\n```js\nlet single = `string text`;\nlet multi = `string text line 1\n string text line 2`;\n\nlet template = `string text ${expression} string text`;\n```", |
| 121 | + "tasks": [ |
| 122 | + { |
| 123 | + "description": "`log` a template literal using `template`. What does it look like?", |
| 124 | + "actions": [ |
| 125 | + "open('template-literal.js')", |
| 126 | + "set('// change the output to a template literal\n\nfunction template() {\n console.log('I know what a backtick is');\n}\ntemplate();\n\n\n')" |
| 127 | + ], |
| 128 | + "tests": [ |
| 129 | + "1/04/01" |
| 130 | + ] |
| 131 | + }, |
| 132 | + { |
| 133 | + "description": "rewrite `multiline` to use template literals", |
| 134 | + "tests": [ |
| 135 | + "1/04/02" |
| 136 | + ], |
| 137 | + "actions": [ |
| 138 | + "insert('\nfunction multiline() {\n\tconsole.log('1.\\n2.\\n3.');\n}\nmultiline();\n// 1.\n// 2.\n// 3.\n\n\n')" |
| 139 | + ] |
| 140 | + }, |
| 141 | + { |
| 142 | + "description": "rewrite `expressions` to use template literals", |
| 143 | + "tests": [ |
| 144 | + "1/04/03" |
| 145 | + ], |
| 146 | + "hints": [ |
| 147 | + "Use `${expressions}`" |
| 148 | + ], |
| 149 | + "actions": [ |
| 150 | + "insert('\nfunction expression(name) {\n console.log(\n 'Hello ' + name +\n ', your bill is ' +\n (2.25 * 1.15).toFixed(2) +\n '.'\n );\n}\nexpression('Joe');\n\n')" |
| 151 | + ] |
| 152 | + } |
| 153 | + ], |
| 154 | + "onPageComplete": "Great! Now you should have a good idea how to use template literals in your code" |
73 | 155 | }
|
74 | 156 | ]
|
75 | 157 | }
|
|
0 commit comments