diff --git a/module-exercises/arrays.js b/module-exercises/arrays.js
index baf3f53..cb9871a 100644
--- a/module-exercises/arrays.js
+++ b/module-exercises/arrays.js
@@ -101,20 +101,21 @@ evaluate(example_garbageCollectingArrays);
function passTheAssertions1() {
- ; // declare and assign a1
- ; // declare and assign a2
+ let a1 = []; // declare and assign a1
+ let a2 = a1 ; // declare and assign a2
console.assert(a1 === a2, 'a1 should strictly equal a2');
- ; // declare and assign b1
- ; // declare and assign b2
+ let b1 = ["b"] ; // declare and assign b1
+ let b2 = ["b"]; // declare and assign b2
console.assert(b1 !== b2, 'b1 should not strictly equal b2');
// ---
- ; // write one line to pass the assertions
+ a1[0] = "hi!" ; // write one line to pass the assertions
console.assert(a1[0] === a2[0], 'a1[0] should strictly equal a2[0]');
console.assert(a1[0] === 'hi!', 'a1.x should strictly equal "hi!"');
-
+ b1 = b2 = ['"bye!"', '"bye!"'];
+ b1[0] = "bye!";
; // write two lines to pass the assertions
;
console.assert(b1[0] === b2[0], 'b1[0] should strictly equal b2[0]');
@@ -125,12 +126,12 @@ evaluate(passTheAssertions1);
function passTheAssertions2() {
const value1 = 5;
- let reference1 = [];
+
; // write this line
console.assert(value2 === value1, "value1 should strictly equal value2");
- ; // write this line
+ let reference2 = reference1;// write this line
console.assert(reference2 === reference1, "reference1 should strictly equal reference2");
value2 = value2 + 1; // write this line
diff --git a/module-exercises/conditional-statements.js b/module-exercises/conditional-statements.js
index db4016c..c31a2fe 100644
--- a/module-exercises/conditional-statements.js
+++ b/module-exercises/conditional-statements.js
@@ -1,5 +1,3 @@
-// https://www.youtube.com/watch?v=9O-PCTfT6Rs&list=PLzV58Zm8FuBJFfQN5il3ujx6FDAY8Ds3u&index=3
-
{
const pageTitle = 'conditional statements';
const header = document.createElement("h2");
diff --git a/module-exercises/errors-and-lifecycle.js b/module-exercises/errors-and-lifecycle.js
index 20c029e..dd6328f 100644
--- a/module-exercises/errors-and-lifecycle.js
+++ b/module-exercises/errors-and-lifecycle.js
@@ -47,7 +47,7 @@ this way you can come back later to study the errors and solutions
// --- syntax errors ---
// these are detected at creation phase and will stop the page from loading
-function missingVariableName() {
+/*function missingVariableName() {
const = null;
}
evaluate(missingVariableName);
@@ -102,7 +102,7 @@ function unEscapedLineBreak() {
}
evaluate(unEscapedLineBreak);
-
+*/
// --- semantic errors ---
// these are detected at runtime and will throw an error after the page has loaded
diff --git a/module-exercises/explicit-coercion.js b/module-exercises/explicit-coercion.js
index d6bcfd4..6e3d3a9 100644
--- a/module-exercises/explicit-coercion.js
+++ b/module-exercises/explicit-coercion.js
@@ -23,12 +23,12 @@
// fix the test cases' expected values to pass the function
const StringTests = [
// string values remain unchanged
- { name: 'str, any string', args: ['any string'], expected: null },
+ { name: 'str, any string', args: ['any string'], expected: "any string" },
// casting with String just puts quotes around a thing
- { name: 'num, 3', args: [3], expected: null },
- { name: 'boo, true', args: [true], expected: null },
- { name: 'obj, null', args: [null], expected: null },
- { name: 'und, undefined', args: [undefined], expected: null },
+ { name: 'num, 3', args: [3], expected: "3" },
+ { name: 'boo, true', args: [true], expected: "true" },
+ { name: 'obj, null', args: [null], expected: "null" },
+ { name: 'und, undefined', args: [undefined], expected: "undefined" },
// write at least 5 more test cases for the String function
];
String.quizzing = true;
@@ -45,11 +45,11 @@ const NumberTests = [
{ name: 'num, Infinity', args: [Infinity], expected: Infinity },
{ name: 'num, NaN', args: [NaN], expected: NaN },
// true and false, the only boolean values
- { name: 'boo, true', args: [true], expected: 0 },
- { name: 'boo, false', args: [false], expected: 1 },
+ { name: 'boo, true', args: [true], expected: 1 },
+ { name: 'boo, false', args: [false], expected: 0 },
// null & undefined
- { name: 'obj, null', args: [null], expected: NaN },
- { name: 'und, undefined', args: [undefined], expected: 0 },
+ { name: 'num, null', args: [null], expected: 0 },
+ { name: 'und, undefined', args: [undefined], expected: NaN },
// strings are bit more interesting, write 7 more test cases with string args
{ name: 'str, undefined', args: ['undefined'], expected: NaN },
{ name: 'str, Infinity', args: ['Infinity'], expected: Infinity },
@@ -68,19 +68,19 @@ const BooleanTests = [
{ name: 'boo, false', args: [false], expected: false },
// anything but 0 & NaN is cast to true
{ name: 'num, 3', args: [3], expected: true },
- { name: 'num, 0', args: [0], expected: true },
+ { name: 'num, 0', args: [0], expected: false },
{ name: 'num, 1e3', args: [1000], expected: true },
- { name: 'num, Infinity', args: [Infinity], expected: false },
+ { name: 'num, Infinity', args: [Infinity], expected: true },
{ name: 'num, NaN', args: [NaN], expected: false },
// null & undefined
- { name: 'obj, null', args: [null], expected: true },
- { name: 'und, undefined', args: [undefined], expected: true },
+ { name: 'obj, null', args: [null], expected: false },
+ { name: 'und, undefined', args: [undefined], expected: false },
// anything but an empty string is cast to true
- { name: 'str, undefined', args: ['undefined'], expected: false },
- { name: 'str, false', args: ['false'], expected: false },
+ { name: 'str, undefined', args: ['undefined'], expected: true },
+ { name: 'str, false', args: ['false'], expected: true },
{ name: 'str, Infinity', args: ['Infinity'], expected: true },
{ name: 'str, three', args: ['three'], expected: true },
- { name: 'str, ', args: [''], expected: true },
+ { name: 'str, ', args: [''], expected: false },
{ name: 'str, 3', args: ['3'], expected: true },
];
Boolean.quizzing = true;
diff --git a/module-exercises/for-in-for-of.js b/module-exercises/for-in-for-of.js
index 6fb59b1..afbd519 100644
--- a/module-exercises/for-in-for-of.js
+++ b/module-exercises/for-in-for-of.js
@@ -1,7 +1,5 @@
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in
-// https://javascript.info/array#loops
-// https://javascript.info/object#the-for-in-loop
// https://alligator.io/js/for-of-for-in-loops/
{
diff --git a/module-exercises/functions.js b/module-exercises/functions.js
index f22570a..3b379a3 100644
--- a/module-exercises/functions.js
+++ b/module-exercises/functions.js
@@ -174,11 +174,11 @@ function tracing1() {
};
// set values in the args to pass the assert
- let arg1 = "", arg2 = "", arg3 = "";
+ let arg1 = "y", arg2 = "x", arg3 = "z";
let returnval = f(arg1, arg2, arg3);
console.assert(returnval === "zyx", "1 a");
- arg1 = "", arg2 = "", arg3 = "";
+ arg1 = "z", arg2 = "x", arg3 = "y";
returnval = f(arg1, arg2, arg3);
console.assert(returnval === "yzx", "1 b");
@@ -194,11 +194,11 @@ function tracing2() {
};
// set values in the args to pass the assert
- let arg1 = "", arg2 = "", arg3 = "";
+ let arg1 = "x", arg2 = "y", arg3 = "z";
let returnVal = f(arg1, arg3, arg2);
console.assert(returnVal === "yxz", "returnVal should be yxz");
- arg1 = "", arg2 = "", arg3 = "";
+ arg1 = "x", arg2 = "z", arg3 = "y";
returnVal = f(arg2, arg1, arg3);
console.log(returnVal === "zxy", "returnVal should be zxy");
@@ -217,12 +217,12 @@ function tracing3() {
};
// set values in the args to pass the assert
- let arg1 = "", arg2 = "", arg3 = "";
+ let arg1 = "z", arg2 = "x", arg3 = "y";
let returnVal = f(arg1, arg2, arg3);
console.assert(returnVal === "yxz", "returnVal should be yxz");
- arg1 = "", arg2 = "", arg3 = "";
+ arg1 = "z", arg2 = "y", arg3 = "x";
returnVal = f(arg3, arg2, arg1);
console.assert(returnVal === "zyx", "returnVal should be zyx");
@@ -239,11 +239,11 @@ function tracing4() {
// pass x, y and z to the function in the right order
// don't change their values!
let x = "x", y = "y", z = "z";
- let returnVal = f();
+ let returnVal = f(x,z,y);
console.assert(returnVal === "yxz", "returnVal should be yxz");
x = "x", y = "z", z = "y";
- returnVal = f();
+ returnVal = f(z,x,y);
console.assert(returnVal === "zyx", "returnVal should be zyx");
}
@@ -260,11 +260,11 @@ function tracing5() {
// pass x, y and z to the function in the right order
// don't change their values!
let x = "x", y = "y", z = "z";
- let returnVal = f();
+ let returnVal = f(z,x,y);
console.assert(returnVal === "xzy", "returnVal should be xzy");
x = "y", y = "x", z = "z";
- returnVal = f();
+ returnVal = f(x,z,y);
console.assert(returnVal === "zyx", "returnVal should be zyx");
}
@@ -275,7 +275,7 @@ function tracing6() {
// concatinate the params to pass the tests
function f(param1, param2, param3) {
- const result = null;
+ const result = param3 + param1 + param2;
return result;
};
@@ -295,7 +295,7 @@ function tracing7() {
// concatinate the params to pass the tests
function f(param1, param2, param3) {
- const result = null;
+ const result = param2 + param3 + param1;
return result;
};
@@ -314,8 +314,8 @@ evaluate(tracing7);
function tracing8() {
// arrange the parameters to pass the asserts
- function f() {
- var result = param2 + param1 + param3;
+ function f(param1,param2,param3) {
+ var result = param2 + param3 + param1;
return result;
};
@@ -334,8 +334,8 @@ evaluate(tracing8);
function tracing9() {
// arrange the parameters to pass the asserts
- function f() {
- var result = param1 + param2 + param3;
+ function f(param1,param2,param3) {
+ var result = param3 + param1 + param2;
return result;
};
@@ -354,21 +354,21 @@ evaluate(tracing9);
function tracing10() {
// do what needs to be done!
- function f() { // <--
+ function f(param1,param2,param3,param4) { // <--
var result = param3 + param1 + param2 + param4;
return result;
};
- let arg1 = "", arg2 = "", arg3 = "", arg4 = ""; // <--
+ let arg1 = "y", arg2 = "z", arg3 = "x", arg4 = "w"; // <--
let returnVal = f(arg1, arg2, arg3, arg4);
console.assert(returnVal === "xyzw", "returnVal should be xyzw");
arg1 = "z", arg2 = "w", arg3 = "y", arg4 = "x";
returnVal = f(arg3, arg1, arg4, arg2);
- console.assert(returnVal === "", "returnVal should be ?"); // <--
+ console.assert(returnVal === "xyzw", "returnVal should be xyzw?"); // <--
arg1 = "z", arg2 = "w", arg3 = "y", arg4 = "x";
- returnVal = f(); // <--
+ returnVal = f(arg3,arg2,arg1,arg4); // <--
console.assert(returnVal === "zywx", "returnVal should be zywx");
}
@@ -398,6 +398,7 @@ function example1_testCases() {
const result = a + b;
return result;
}
+
testCases.forEach(test => {
const name = test.name;
diff --git a/module-exercises/index.html b/module-exercises/index.html
index 2ef651b..af5687d 100644
--- a/module-exercises/index.html
+++ b/module-exercises/index.html
@@ -23,7 +23,7 @@
-
+
@@ -39,7 +39,7 @@
challenge exercises
-
+