From 6c94a6b3dd5a71c9010b739b7443f37cea926b9f Mon Sep 17 00:00:00 2001 From: serhat Date: Fri, 11 Oct 2019 23:46:24 +0200 Subject: [PATCH 01/28] Structuring the page --- week-1-project/index.html | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/week-1-project/index.html b/week-1-project/index.html index 9397ef9..3c56b69 100644 --- a/week-1-project/index.html +++ b/week-1-project/index.html @@ -4,16 +4,21 @@ - + + + week 1 project - + - - +
+

Week 1 JS Project

+
+
+


@@ -40,8 +45,12 @@

   
- - +
+
+ From 4a9f1c69f64476978db37a05a3d1529258fe7746 Mon Sep 17 00:00:00 2001 From: serhat Date: Fri, 11 Oct 2019 23:48:31 +0200 Subject: [PATCH 02/28] characters in a string is sorted --- week-1-project/sort-handler.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/week-1-project/sort-handler.js b/week-1-project/sort-handler.js index e45575f..f7e3f39 100644 --- a/week-1-project/sort-handler.js +++ b/week-1-project/sort-handler.js @@ -17,8 +17,13 @@ function sortHandler() { // read and process user input (this works, no need to change it!) const toSort = document.getElementById('sort-input').value; + function sortString(toSort){ + let splited = toSort.split(''); + let sorted = splited.sort(); + return sorted.join(''); + } // pass user input through core logic (write this! it doesn't work) - const sorted = `sort the charecters in ${toSort}`; + const sorted = sortString(toSort); // report result to user (this works, no need to change it!) const outputField = document.getElementById('sort-output'); From c88ac98ae20e906f53159c9242bd795de3a9c900 Mon Sep 17 00:00:00 2001 From: serhat Date: Fri, 11 Oct 2019 23:52:46 +0200 Subject: [PATCH 03/28] characters in a string are reversed --- week-1-project/reverse-handler.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/week-1-project/reverse-handler.js b/week-1-project/reverse-handler.js index 6682c5f..7e7fe7d 100644 --- a/week-1-project/reverse-handler.js +++ b/week-1-project/reverse-handler.js @@ -16,9 +16,16 @@ function reverseHandler() { // read and process user input (this works, no need to change it!) const toReverse = document.getElementById('reverse-input').value; - + + + function reverseString(toReverse){ + let splited = toReverse.split(''); + let reversed = splited.reverse(); + return reversed.join(''); + } + // pass user input through core logic (write this! it doesn't work) - const reversed = `reverse ${toReverse}`; + const reversed = reverseString(toReverse); // report result to user (this works, no need to change it!) const outputField = document.getElementById('reverse-output'); From db0ef490bedd149b49ada167fe614d713c0016d9 Mon Sep 17 00:00:00 2001 From: serhat Date: Fri, 11 Oct 2019 23:54:23 +0200 Subject: [PATCH 04/28] vowels from a string are removed --- week-1-project/devowel-handler.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/week-1-project/devowel-handler.js b/week-1-project/devowel-handler.js index c50d2d2..5dee826 100644 --- a/week-1-project/devowel-handler.js +++ b/week-1-project/devowel-handler.js @@ -16,8 +16,14 @@ function devowelHandler() { // read and process user input (this works, no need to change it!) const toDevowel = document.getElementById('devowel-input').value; - // pass user input through core logic (write this! it doesn't work) - const devoweled = `remove all vowels from ${toDevowel}`; + function removeVowel(toDevowel) { + var vowelsToRemove = ['a', 'e', 'i', 'o', 'u']; + return toDevowel.split('').filter(function(el) { + return vowelsToRemove.indexOf(el.toLowerCase()) == -1; + }).join(''); + } + + const devoweled = removeVowel(toDevowel); // report result to user (this works, no need to change it!) const outputField = document.getElementById('devowel-output'); From af612e2ef12e0804886371eb8ed3c604d3225393 Mon Sep 17 00:00:00 2001 From: serhat Date: Fri, 11 Oct 2019 23:55:43 +0200 Subject: [PATCH 05/28] repeted string --- week-1-project/repeat-handler.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/week-1-project/repeat-handler.js b/week-1-project/repeat-handler.js index d0c5d72..7bed8f7 100644 --- a/week-1-project/repeat-handler.js +++ b/week-1-project/repeat-handler.js @@ -22,10 +22,15 @@ function repeatHandler() { if (numOfRepetitions !== numOfRepetitions) { throw new TypeError('second input to "repeat it" must be a number'); } - + function repeatString(strToRepeat, numOfRepetitions){ + if(numOfRepetitions > 0) + return strToRepeat.repeat(numOfRepetitions) + else + return ""; + } // pass user input through core logic (write this! it doesn't work) - const repeated = `repeat ${strToRepeat} ${numOfRepetitions} times`; + const repeated = repeatString(strToRepeat, numOfRepetitions); // report result to user (this works, no need to change it!) const outputField = document.getElementById('repeat-output'); From c2b738e7d1deac10c503c7d096d4f1f906ece506 Mon Sep 17 00:00:00 2001 From: serhat Date: Fri, 11 Oct 2019 23:56:34 +0200 Subject: [PATCH 06/28] some styling --- week-1-project/style.css | 49 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/week-1-project/style.css b/week-1-project/style.css index e69de29..2f708b1 100644 --- a/week-1-project/style.css +++ b/week-1-project/style.css @@ -0,0 +1,49 @@ +body { + font-family: "Benton Sans", "Helvetica Neue", helvetica, arial, sans-serif; + + } +header{ + text-align: center; + color: #ac0808; + +} + .container { + display: block; + overflow: hidden; + max-width: 600px; + text-align: center; + margin: auto; + margin-top: 20px; + margin-bottom: 20px; + } +/*footer*/ +footer{ + position: absolute; + bottom:0; + width:100%; + margin:0rem; + background:#053b57; + color:white; + text-align:center; + padding:0.5rem; + } + footer a{ + color:yellow; + font-size:1.5rem; + } + @media (max-width: 768px) { + + body { + font-size: 0.8em; + background-color: beige; + + } + + .container { + max-width: 400px; + text-align: center; + margin: auto; + margin-top: 10px; + padding: 10px; + } +} \ No newline at end of file From 3b4f84ab1f3b9d438ef816052dc043cd0b56849f Mon Sep 17 00:00:00 2001 From: serhat Date: Fri, 11 Oct 2019 23:59:53 +0200 Subject: [PATCH 07/28] some of module-exercises are done --- module-exercises/functions.js | 27 ++++++++++++++------------- module-exercises/index.html | 8 ++++---- module-exercises/variables.js | 32 +++++++++++++++++++++++--------- 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/module-exercises/functions.js b/module-exercises/functions.js index f22570a..6898515 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 = "y", arg2 = "x", arg3 = "z"; 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,7 +314,7 @@ evaluate(tracing7); function tracing8() { // arrange the parameters to pass the asserts - function f() { + function f(param3,param2,param1) { var result = param2 + param1 + param3; return result; }; @@ -442,6 +442,7 @@ function functionToTest1(a, b) { const result = a + b; return result; } + evaluate(functionToTest1, writeTestCases1); const writeTestCases2 = [ diff --git a/module-exercises/index.html b/module-exercises/index.html index 2ef651b..483901f 100644 --- a/module-exercises/index.html +++ b/module-exercises/index.html @@ -20,10 +20,10 @@ this will make your study-flow much cleaner --> - - + - + challenge exercises diff --git a/module-exercises/variables.js b/module-exercises/variables.js index 0ed91de..526f48f 100644 --- a/module-exercises/variables.js +++ b/module-exercises/variables.js @@ -82,7 +82,10 @@ function threeVariableSwap1() { let temp = ''; // can be done in 4 lines - + temp= a; + a=b; + b=c; +c=temp; console.assert(a === "a", "a should store 'a'"); console.assert(b === "b", "b should store 'b'"); @@ -96,7 +99,10 @@ function threeVariableSwap2() { let temp = ''; // can be done in 4 lines - + temp=a; + a=c; + c=b; + b=temp; console.assert(a === "a", "a should store 'a'"); console.assert(b === "b", "b should store 'b'"); @@ -110,7 +116,11 @@ function fourVariableSwap1() { let temp = ''; // can be done in 5 lines - + temp=a; + a=b; + b=c; + c=d; + d=temp; console.assert(a === "a", "a should store 'a'"); console.assert(b === "b", "b should store 'b'"); @@ -125,6 +135,7 @@ function fourVariableSwap2() { let temp = ''; // can be done in 6 lines + temp=a, a=d, d=temp, temp=c, c=b, b=temp console.assert(a === "w", "a should store 'w'"); @@ -140,7 +151,7 @@ function fiveVariableSwap() { let temp = ' '; // can be done in 6 lines - + temp=a, a=e, e=temp, temp=b, b=d, d=temp, console.assert(a === "v", "a should store 'v'"); console.assert(b === "w", "b should store 'w'"); @@ -189,7 +200,7 @@ function multipleAssignments1() { let temp = ''; // can be done in 1 line - + temp=a, a=b, b=c, c=temp, console.assert(a === "a", "a should store 'a'"); console.assert(b === "b", "b should store 'b'"); @@ -203,7 +214,7 @@ function multipleAssignments2() { let temp = ''; // can be done in 1 line - + temp=a, a=c, c=b; b=temp, console.assert(a === "a", "a should store 'a'"); console.assert(b === "b", "b should store 'b'"); @@ -217,7 +228,7 @@ function multipleAssignments3() { let temp = ''; // can be done in 1 line - + temp=a, a=b, b=c, c=d, d=temp, console.assert(a === "a", "a should store 'a'"); console.assert(b === "b", "b should store 'b'"); @@ -232,7 +243,7 @@ function multipleAssignments4() { let temp = ''; // can be done in 1 line - +temp=a, a=d, d=temp, temp=b, b=c, c=temp, console.assert(a === "w", "a should store 'w'"); console.assert(b === "x", "b should store 'x'"); @@ -269,7 +280,10 @@ function chainedAssignments1() { let temp = ''; // can be done in 3 lines or less - + temp = a1 + a1=a2=b + b=temp + console.assert(a1 === "a", 'a1 should store "a"'); console.assert(a1 === a2, 'a1 should store the same value as a2'); console.assert(b === "b", 'b should store "b"'); From 941c68b5edc8e2eb102fb53b8e83b8d9f658c633 Mon Sep 17 00:00:00 2001 From: serhat Date: Wed, 16 Oct 2019 21:54:10 +0200 Subject: [PATCH 08/28] some exercises --- module-exercises/explicit-coercion.js | 10 ++--- module-exercises/index.html | 8 ++-- module-exercises/primitive-types.js | 65 ++++++++++++++------------- 3 files changed, 42 insertions(+), 41 deletions(-) diff --git a/module-exercises/explicit-coercion.js b/module-exercises/explicit-coercion.js index d6bcfd4..328e572 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; diff --git a/module-exercises/index.html b/module-exercises/index.html index 483901f..ece56d6 100644 --- a/module-exercises/index.html +++ b/module-exercises/index.html @@ -20,10 +20,10 @@ this will make your study-flow much cleaner --> - + + - + challenge exercises diff --git a/module-exercises/primitive-types.js b/module-exercises/primitive-types.js index 2ab5eb0..cbc629e 100644 --- a/module-exercises/primitive-types.js +++ b/module-exercises/primitive-types.js @@ -59,27 +59,27 @@ evaluate(example_allValuesHaveAType); // the type of a value is very important to understanding how JS works const typeofTests = [ // boolean values - { name: 'boo, true', args: [true], expected: '' }, - { name: 'boo, false', args: [false], expected: '' }, + { name: 'boo, true', args: [true], expected: 'boolean'}, + { name: 'boo, false', args: [false], expected: 'boolean' }, // null's type is 'null'. just remember, don't try yet to understand - { name: 'obj, true', args: [null], expected: '' }, + { name: 'obj, true', args: [null], expected: 'object' }, // undefined. like with null, there is only one value with this type - { name: 'und, undefined', args: [undefined], expected: '' }, + { name: 'und, undefined', args: [undefined], expected: 'undefined' }, // strings are anything with quotes around it - { name: 'str, ', args: [''], expected: '' }, - { name: 'str, anything with quotes!', args: ['anything with quotes!'], expected: '' }, + { name: 'str, ', args: [''], expected: 'string' }, + { name: 'str, anything with quotes!', args: ['anything with quotes!'], expected: 'string' }, // numbers are a bit more strange and varied { name: 'num, 0.0', args: [0.0], expected: 'number' }, { name: 'num, NaN', args: [NaN], expected: 'number' }, { name: 'num, Infinity', args: [Infinity], expected: 'number' }, { name: 'num, 4', args: [4], expected: 'number' }, // write 6 more passing test cases with expected value 'number' - { name: '', args: null, expected: null }, - { name: '', args: null, expected: null }, - { name: '', args: null, expected: null }, - { name: '', args: null, expected: null }, - { name: '', args: null, expected: null }, - { name: '', args: null, expected: null }, + { name: '', args: [Infinity], expected: 'number' }, + { name: '', args: [NaN], expected: 'number' }, + { name: '', args: [1], expected: 'number' }, + { name: '', args: [7], expected: 'number' }, + { name: '', args: [Math.PI], expected: 'number' }, + { name: '', args: [Math.E], expected: 'number' }, ] function allValuesHaveAType(value) { return typeof value; @@ -100,6 +100,7 @@ const typeofReturnsAStringTests = [ function typeofReturnsAString(value) { const typeofValue = typeof value; return typeof typeofValue; + } typeofReturnsAString.quizzing = true; evaluate(typeofReturnsAString, typeofReturnsAStringTests); @@ -125,16 +126,16 @@ evaluate(example_aBitAboutNaN); // fix the expected values to pass the tests const strictEqualityTests = [ - { name: 'NaN', args: [NaN, NaN], expected: null }, - { name: 'first', args: [true, 'true'], expected: null }, - { name: 'second', args: [1, '1'], expected: null }, - { name: 'third', args: ['1', '1'], expected: null }, - { name: 'fourth', args: [1000, 1e3], expected: null }, - { name: 'fifth', args: [+0, -0], expected: null }, - { name: 'sixth', args: [1, 1.0], expected: null }, - { name: 'seventh', args: ['', ""], expected: null }, - { name: 'eighth', args: ["", ``], expected: null }, - { name: 'ninth', args: [' ', ' '], expected: null }, + { name: 'NaN', args: [NaN, NaN], expected: false }, + { name: 'first', args: [true, 'true'], expected: false }, + { name: 'second', args: [1, '1'], expected: false }, + { name: 'third', args: ['1', '1'], expected: true }, + { name: 'fourth', args: [1000, 1e3], expected: true }, + { name: 'fifth', args: [+0, -0], expected: true }, + { name: 'sixth', args: [1, 1.0], expected: true }, + { name: 'seventh', args: ['', ""], expected: true }, + { name: 'eighth', args: ["", ``], expected: false }, + { name: 'ninth', args: [' ', ' '], expected: true }, ]; function strictEquality(a, b) { // if type OR value are not the same, returns false @@ -147,16 +148,16 @@ evaluate(strictEquality, strictEqualityTests); const strictInequalityTests = [ - { name: 'NaN', args: [NaN, NaN], expected: null }, - { name: 'first', args: [true, 'true'], expected: null }, - { name: 'second', args: [1, '1'], expected: null }, - { name: 'third', args: ['1', '1'], expected: null }, - { name: 'fourth', args: [1000, 1e3], expected: null }, - { name: 'fifth', args: [+0, -0], expected: null }, - { name: 'sixth', args: [1, 1.0], expected: null }, - { name: 'seventh', args: ['', ""], expected: null }, - { name: 'eighth', args: ["", ``], expected: null }, - { name: 'ninth', args: [' ', ' '], expected: null }, + { name: 'NaN', args: [NaN, NaN], expected: true }, + { name: 'first', args: [true, 'true'], expected: true }, + { name: 'second', args: [1, '1'], expected: true }, + { name: 'third', args: ['1', '1'], expected: false }, + { name: 'fourth', args: [1000, 1e3], expected: false }, + { name: 'fifth', args: [+0, -0], expected: false }, + { name: 'sixth', args: [1, 1.0], expected: false }, + { name: 'seventh', args: ['', ""], expected: false }, + { name: 'eighth', args: ["", ``], expected: true }, + { name: 'ninth', args: [' ', ' '], expected: false }, ]; function strictInequality(a, b) { // if type OR value are not the same, returns true From cb272465c8fa715e8ab07f133ae1e3607d11eb82 Mon Sep 17 00:00:00 2001 From: serhat Date: Wed, 16 Oct 2019 22:40:36 +0200 Subject: [PATCH 09/28] some changes --- module-exercises/truthiness.js | 142 +++++++++++++++-------------- week-2-project/index.html | 21 +++-- week-2-project/scripts/leftpad.js | 65 +++++++++++++ week-2-project/scripts/scramble.js | 47 ---------- 4 files changed, 150 insertions(+), 125 deletions(-) create mode 100644 week-2-project/scripts/leftpad.js delete mode 100644 week-2-project/scripts/scramble.js diff --git a/module-exercises/truthiness.js b/module-exercises/truthiness.js index 1ab700d..8de9cee 100644 --- a/module-exercises/truthiness.js +++ b/module-exercises/truthiness.js @@ -7,82 +7,88 @@ document.body.appendChild(header); console.groupCollapsed(pageTitle); } +try { + function example_truthinessIsCastingToBoolean() { + const valuesToStudy = [ + true, false, 1, 0, "", " ", NaN, undefined, null, + "got it?", "add some of your own values to study" + ]; + valuesToStudy.forEach(value => { + const type = typeof value; + const castToBoolean = Boolean(value); + const newType = typeof castToBoolean; + const truthiness = castToBoolean + 'y'; + }) + } + evaluate(example_truthinessIsCastingToBoolean); -function example_truthinessIsCastingToBoolean() { - const valuesToStudy = [ - true, false, 1, 0, "", " ", NaN, undefined, null, - "got it?", "add some of your own values to study" - ]; - valuesToStudy.forEach(value => { - const type = typeof value; - const castToBoolean = Boolean(value); - const newType = typeof castToBoolean; - const truthiness = castToBoolean + 'y'; - }) -} -evaluate(example_truthinessIsCastingToBoolean); + const truthinessTests = [ + // flasey values, everything else is truthy! + { name: 'false', args: [false], expected: 'falsey' }, + { name: 'null', args: [null], expected: 'falsey' }, + { name: 'undefined', args: [undefined], expected: 'falsey' }, + { name: '""', args: [""], expected: 'falsey' }, + { name: "''", args: [''], expected: 'falsey' }, + { name: '``', args: [``], expected: 'falsey' }, + { name: '0', args: [0], expected: 'falsey' }, + { name: '0.0', args: [0.0], expected: 'falsey' }, + { name: '+0', args: [+0], expected: 'falsey' }, + { name: '-0', args: [-0], expected: 'falsey' }, + { name: 'NaN', args: [NaN], expected: 'falsey' }, + // try it yourself! write some more test cases + { name: '', args: null, expected: null }, + { name: '', args: null, expected: null }, + { name: '', args: null, expected: null }, + { name: '', args: null, expected: null }, + { name: '', args: null, expected: null }, + { name: '', args: null, expected: null }, + ]; + function truthinessByTestCase(x) { + const coercedToBool = Boolean(x); + const truthiness = coercedToBool + 'y'; + return truthiness; + } + truthinessByTestCase.quizzing = true; + evaluate(truthinessByTestCase, truthinessTests); -const truthinessTests = [ - // flasey values, everything else is truthy! - { name: 'false', args: [false], expected: 'falsey' }, - { name: 'null', args: [null], expected: 'falsey' }, - { name: 'undefined', args: [undefined], expected: 'falsey' }, - { name: '""', args: [""], expected: 'falsey' }, - { name: "''", args: [''], expected: 'falsey' }, - { name: '``', args: [``], expected: 'falsey' }, - { name: '0', args: [0], expected: 'falsey' }, - { name: '0.0', args: [0.0], expected: 'falsey' }, - { name: '+0', args: [+0], expected: 'falsey' }, - { name: '-0', args: [-0], expected: 'falsey' }, - { name: 'NaN', args: [NaN], expected: 'falsey' }, - // try it yourself! write some more test cases - { name: '', args: null, expected: null }, - { name: '', args: null, expected: null }, - { name: '', args: null, expected: null }, - { name: '', args: null, expected: null }, - { name: '', args: null, expected: null }, - { name: '', args: null, expected: null }, -]; -function truthinessByTestCase(x) { - const coercedToBool = Boolean(x); - const truthiness = coercedToBool + 'y'; - return truthiness; -} -truthinessByTestCase.quizzing = true; -evaluate(truthinessByTestCase, truthinessTests); + // change the expected values from null to true or false + // and come on. don't just use trial and error, think a bit harder! + const testsToPass = [ + { name: 'first', args: [0.0], expected: null }, + { name: 'second', args: [null], expected: null }, + { name: 'third', args: ['hacking your future!'], expected: null }, + { name: "fourth", args: [''], expected: null }, + { name: 'fifth', args: ["--<(*)>--"], expected: null }, + { name: 'sixth', args: [undefined], expected: null }, + { name: 'seventh', args: [""], expected: null }, + { name: 'eighth', args: [Symbol('hello')], expected: null }, + { name: 'ninth', args: [``], expected: null }, + { name: 'tenth', args: [true], expected: null }, + { name: 'eleventh', args: [1e3], expected: null }, + { name: 'twelfth', args: [0], expected: null }, + { name: 'thirteenth', args: [Symbol()], expected: null }, + { name: 'fourteenth', args: [-0], expected: null }, + { name: 'fifteenth', args: [NaN], expected: null }, + { name: 'sixteenth', args: [Infinity], expected: null }, + { name: 'seventeenth', args: [Symbol(false)], expected: null }, + { name: 'eighteenth', args: [+0], expected: null }, + { name: 'nineteenth', args: [false], expected: null }, + ]; + Boolean.quizzing = true; + evaluate(Boolean, testsToPass); + delete Boolean.quizzing; -// change the expected values from null to true or false -// and come on. don't just use trial and error, think a bit harder! -const testsToPass = [ - { name: 'first', args: [0.0], expected: null }, - { name: 'second', args: [null], expected: null }, - { name: 'third', args: ['hacking your future!'], expected: null }, - { name: "fourth", args: [''], expected: null }, - { name: 'fifth', args: ["--<(*)>--"], expected: null }, - { name: 'sixth', args: [undefined], expected: null }, - { name: 'seventh', args: [""], expected: null }, - { name: 'eighth', args: [Symbol('hello')], expected: null }, - { name: 'ninth', args: [``], expected: null }, - { name: 'tenth', args: [true], expected: null }, - { name: 'eleventh', args: [1e3], expected: null }, - { name: 'twelfth', args: [0], expected: null }, - { name: 'thirteenth', args: [Symbol()], expected: null }, - { name: 'fourteenth', args: [-0], expected: null }, - { name: 'fifteenth', args: [NaN], expected: null }, - { name: 'sixteenth', args: [Infinity], expected: null }, - { name: 'seventeenth', args: [Symbol(false)], expected: null }, - { name: 'eighteenth', args: [+0], expected: null }, - { name: 'nineteenth', args: [false], expected: null }, -]; -Boolean.quizzing = true; -evaluate(Boolean, testsToPass); -delete Boolean.quizzing; +} catch (err) { + console.log(err); + document.body.appendChild( + evaluate.errorSearchComponent('.js file', err) + ); +} { console.groupEnd(); document.body.appendChild(document.createElement('hr')); } - diff --git a/week-2-project/index.html b/week-2-project/index.html index 8badc8c..1ed7543 100644 --- a/week-2-project/index.html +++ b/week-2-project/index.html @@ -14,12 +14,6 @@ -
-
-
-

-  
-

@@ -41,18 +35,25 @@

   
+
+ + + +
+

+  
- +

- + - + - + \ No newline at end of file diff --git a/week-2-project/scripts/leftpad.js b/week-2-project/scripts/leftpad.js new file mode 100644 index 0000000..6b5a2c7 --- /dev/null +++ b/week-2-project/scripts/leftpad.js @@ -0,0 +1,65 @@ +/* leftpad! +Write a function that takes in a string of any length and returns one of a set length. +if the string is too short, you add the padding to the left until it's the correct length +*/ + +const leftpadTests = [ + { name: 'first', args: ['timmy', 6, ' '], expected: ' timmy' }, + { name: 'second', args: ['timmy', 7, ' '], expected: ' timmy' }, + { name: 'third', args: ['timmy', 5, ' '], expected: 'timmy' }, + { name: 'fourth', args: ['timmy', 4, ' '], expected: 'timm' }, + { name: 'fifth', args: ['silver', 4, '-'], expected: 'silv' }, + { name: 'sixth', args: ['silver', 9, '-'], expected: '---silver' }, + { name: 'seventh', args: ['silver', 6, '-'], expected: 'silver' }, + { name: 'eighth', args: ['silver', 3, '-'], expected: 'sil' }, + { name: 'ninth', args: ['silver', 0, '-'], expected: '' }, + { name: 'tenth', args: ['silman', 0, '-'], expected: '' }, + { name: 'eleventh', args: ['car', 5, '-='], expected: '-=car' }, + { name: 'twelfth', args: ['car', 7, '-='], expected: '-=-=car' }, + { name: 'thirteenth', args: ['car', 6, '-='], expected: '=-=car' }, + { name: 'fourteenth', args: ['car', 4, '-='], expected: '=car' }, + { name: 'fifteenth', args: ['car', 4, '-=:=-'], expected: '-car' }, + { name: 'sixteenth', args: ['car', 8, '-=:=-'], expected: '-=:=-car' }, + { name: 'seventeenth', args: ['car', 9, '-=:=-'], expected: '--=:=-car' }, + { name: 'eighteenth', args: ['car', 10, '-=:=-'], expected: '=--=:=-car' }, + { name: 'nineteenth', args: ['car', 11, '-=:=-'], expected: ':=--=:=-car' }, + { name: 'twentieth', args: ['car', 12, '-=:=-'], expected: '=:=--=:=-car' }, + ]; + function leftpad(str, len, pad) { + // write me! + } + evaluate(leftpad, leftpadTests); + + + function leftpadHandler() { + + // read and process user input (this works, no need to change it!) + const stringToPad = document.getElementById('leftpad-str-input').value; + const targetLengthStr = document.getElementById('leftpad-str-input').value; + let targetLength; + if (isNaN(targetLengthStr) || targetLengthStr === '') { + throw new TypeError('length needs to be a number'); + } else { + targetLength = Number(targetLengthStr); + } + const padding = document.getElementById('leftpad-pad-input').value; + + // pass user input through core logic (this works! no need to change it) + const leftpadded = leftpad(stringToPad, targetLength, padding); + + // report result to user (this works, no need to change it!) + const outputField = document.getElementById('leftpad-output'); + outputField.innerHTML = leftpadded; + + console.log('\n--- leftpadHandler ---'); + console.log('stringToPad:', typeof stringToPad, ',', stringToPad); + console.log('targetLength:', typeof targetLength, ',', targetLength); + console.log('padding:', typeof padding, ',', padding); + console.log('leftpadded:', typeof leftpadded, ',', leftpadded); + }; + const leftpadButton = document.getElementById('leftpad-button'); + leftpadButton.addedEventListener('click', leftpadHandler); + + + // https://www.npmjs.com/package/left-pad + // https://programmingpraxis.com/2016/03/25/leftpad/ \ No newline at end of file diff --git a/week-2-project/scripts/scramble.js b/week-2-project/scripts/scramble.js deleted file mode 100644 index c03fa0f..0000000 --- a/week-2-project/scripts/scramble.js +++ /dev/null @@ -1,47 +0,0 @@ -/* scramble! - -Write a function that does these things to a string: -- sort each word (anything with only numbers or letters, separated by spaces) -- reverse chunks (anything between two punctuation marks, a new line or the beginning/end of the string) -- preserve formatting (leave tabs and newlines in place); - -*/ - -const thirdArg = `a list of drinks: - - milk - - sugar free coke - - soy sauce`; -const thirdExpected = `diknrs fo ilst a: - - iklm - - ceko eefr agrsu - - acesu osy`; - -const scrambleTests = [ - { name: 'first', args: ['the road works.'], expected: 'korsw ador eht.' }, - { name: 'second', args: ["name: 'second'"], expected: "aemn: 'cednos'" }, - { name: 'third', args: [thirdArg], expected: thirdExpected }, -]; -function scramble(str) { - // write me! -} -evaluate(scramble, scrambleTests); - - -function scrambleHandler() { - - // read and process user input (this works, no need to change it!) - const toScramble = document.getElementById('scramble-input').value; - - // pass user input through core logic (this works! no need to change it) - const scrambled = scramble(toScramble); - - // report result to user (this works, no need to change it!) - const outputField = document.getElementById('scramble-output'); - outputField.innerHTML = scrambled; - - console.log('\n--- scrambleHandler ---'); - console.log('toScramble:', typeof toScramble, ',', toScramble); - console.log('scrambled:', typeof scrambled, ',', scrambled); -}; -const scrambleButton = document.getElementById('scramble-button'); -scrambleButton.addEventListener('click', scrambleHandler); From 2ca6dd59fb525e56bcba84dc2a363d394c67b4c2 Mon Sep 17 00:00:00 2001 From: serhat Date: Fri, 18 Oct 2019 17:24:55 +0200 Subject: [PATCH 10/28] index and styleshet created --- week-2-project/index.html | 23 +++++--- week-2-project/style.css | 107 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+), 7 deletions(-) diff --git a/week-2-project/index.html b/week-2-project/index.html index 1ed7543..9eee465 100644 --- a/week-2-project/index.html +++ b/week-2-project/index.html @@ -4,7 +4,10 @@ - + + + + week 2 project @@ -12,9 +15,11 @@ - - - +
+

Week 2 JS Projects

+
+
+


@@ -42,18 +47,22 @@

   
- - +
+


- + + \ No newline at end of file diff --git a/week-2-project/style.css b/week-2-project/style.css index e69de29..ab9d152 100644 --- a/week-2-project/style.css +++ b/week-2-project/style.css @@ -0,0 +1,107 @@ +body { + font-family: "Benton Sans", "Helvetica Neue", helvetica, arial, sans-serif; + +} +header{ + text-align: center; + color: #ac0808; + +} +.container { + display: block; + overflow: hidden; + max-width: 600px; + text-align: center; + margin: auto; + margin-top: 20px; + margin-bottom: 20px; +} +#repeatChars-input { + width: 200px; + padding: 0,5rem; +} +#repeatChars-button { + width: 200px; + padding: 0,5rem; + margin: 0.75rem; +} + +#constantize-input { + width: 200px; + padding: 0,5rem; +} +#constantize-button { + width: 200px; + padding: 0,5rem; + margin: 0.75rem; +} +#caesarize-string-input{ + width: 200px; + padding: 0,5rem; +} +#caesarize-number-input { + width: 200px; + padding: 0,5rem; +} +#caesarize-button { + width: 200px; + padding: 0,5rem; + margin: 0.75rem; +} + +#leftpad-str-input{ + width: 200px; + padding: 0,5rem; + margin: 0.5rem; +} +#leftpad-len-input{ + width: 200px; + padding: 0,5rem; + margin: 0.5rem; +} +#leftpad-pad-input{ + width: 200px; + padding: 0,5rem; + margin: 0.5rem; +} +#leftpad-button{ + width: 200px; + padding: 0,5rem; + margin: 0.75rem; +} + /*footer*/ +footer{ + /*position: absolute;*/ + bottom:0; + width:100%; + margin:0rem; + background:#053b57; + color:white; + text-align:center; + padding:0.5rem; + } + footer a{ + color:yellow; + font-size:1.5 + } + + hr { + display: none; + } + + @media (max-width: 768px) { + + body { + font-size: 0.8em; + background-color: beige; + + } + + .container { + max-width: 400px; + text-align: center; + margin: auto; + margin-top: 10px; + padding: 10px; + } +} \ No newline at end of file From a6d30936e155178657b2c2769997e8b0691e8e5c Mon Sep 17 00:00:00 2001 From: serhat Date: Fri, 18 Oct 2019 17:26:04 +0200 Subject: [PATCH 11/28] caesarize.js created --- week-2-project/scripts/caesarize.js | 43 +++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/week-2-project/scripts/caesarize.js b/week-2-project/scripts/caesarize.js index 4eac053..42fd14d 100644 --- a/week-2-project/scripts/caesarize.js +++ b/week-2-project/scripts/caesarize.js @@ -1,9 +1,6 @@ /* Caesar Cipher - this is a simple encoding algorithm that replaces letters in a message with a new letter - the new letter is determined by shifting N spaces across the alphabet - for example, caesarize("A", 3) will return : "D" because "D" is three letters past "A". */ @@ -15,12 +12,42 @@ const caesarizeTests = [ { name: 'fourth', args: ["heLLo worLd!", 1], expected: 'ifMMp xpsMe!' }, { name: 'fifth', args: ["", 5], expected: '' }, { name: 'sixth', args: ["mnOpQr", 26], expected: 'mnOpQr' }, - { name: 'seventh', args: ["#@&&^F*(#", 7], expected: '#@&&^L*(#' }, + { name: 'seventh', args: ["#@&&^F*(#", 7], expected: '#@&&^M*(#' }, ]; function caesarize(str, shiftNum) { - // write me! -} -evaluate(caesarize, caesarizeTests); + + var input = str; + var str=input.split(''); + + + for (var i = 0; i < str.length; i++) { + str[i] = str[i].charCodeAt(); + if ((str[i]>=97)&&(str[i]<=122)){ + str[i]+=shiftNum; + if (str[i]>122){ + str[i]=str[i]-26; + } + else if(str[i]<97){ + str[i]=str[i]+26; + } + str[i] = String.fromCharCode(str[i]); + } + else if((str[i]>=65)&&(str[i]<=90)){ + str[i]+=shiftNum; + if (str[i]>90){ + str[i]=str[i]-26; + } + else if (str[i]<65){ + str[i]=str[i]+26; + } + str[i] = String.fromCharCode(str[i]); + } + + } + return str.join(''); + } + + evaluate(caesarize, caesarizeTests); function caesarizeHandler() { @@ -36,7 +63,7 @@ function caesarizeHandler() { // pass user input through core logic (this works! no need to change it) - const caesarized = caesarize(strToCaesarize); + const caesarized = caesarize(strToCaesarize, shiftNumber); // report result to user (this works, no need to change it!) const outputField = document.getElementById('caesarize-output'); From e129090711c7067800b43912d208fd5533d80273 Mon Sep 17 00:00:00 2001 From: serhat Date: Fri, 18 Oct 2019 17:26:49 +0200 Subject: [PATCH 12/28] constantize crated --- week-2-project/scripts/constantize.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/week-2-project/scripts/constantize.js b/week-2-project/scripts/constantize.js index 8beed0c..4bcdf04 100644 --- a/week-2-project/scripts/constantize.js +++ b/week-2-project/scripts/constantize.js @@ -24,7 +24,20 @@ const constantizeTests = [ ]; function constantize(str) { // write me! -} + const newStrArrNoSpacesCapitalized = str.toUpperCase().split(' '); + + const wordsFiltered = newStrArrNoSpacesCapitalized.map((word) => { + const wordArr = word.split(''); + const wordArrFiltered = wordArr + .filter((c) => { + return c.charCodeAt() >= 65 && c.charCodeAt() <= 90; + }); + const newWord = wordArrFiltered.join(''); + return newWord; + }); + + return wordsFiltered.join('_') + } evaluate(constantize, constantizeTests); From b366d11ee01e60d5966d6b9b8a8cadb56dc87845 Mon Sep 17 00:00:00 2001 From: serhat Date: Fri, 18 Oct 2019 17:27:31 +0200 Subject: [PATCH 13/28] leftpad.js created --- week-2-project/scripts/leftpad.js | 128 ++++++++++++++++-------------- 1 file changed, 70 insertions(+), 58 deletions(-) diff --git a/week-2-project/scripts/leftpad.js b/week-2-project/scripts/leftpad.js index 6b5a2c7..7e140a9 100644 --- a/week-2-project/scripts/leftpad.js +++ b/week-2-project/scripts/leftpad.js @@ -4,62 +4,74 @@ if the string is too short, you add the padding to the left until it's the corre */ const leftpadTests = [ - { name: 'first', args: ['timmy', 6, ' '], expected: ' timmy' }, - { name: 'second', args: ['timmy', 7, ' '], expected: ' timmy' }, - { name: 'third', args: ['timmy', 5, ' '], expected: 'timmy' }, - { name: 'fourth', args: ['timmy', 4, ' '], expected: 'timm' }, - { name: 'fifth', args: ['silver', 4, '-'], expected: 'silv' }, - { name: 'sixth', args: ['silver', 9, '-'], expected: '---silver' }, - { name: 'seventh', args: ['silver', 6, '-'], expected: 'silver' }, - { name: 'eighth', args: ['silver', 3, '-'], expected: 'sil' }, - { name: 'ninth', args: ['silver', 0, '-'], expected: '' }, - { name: 'tenth', args: ['silman', 0, '-'], expected: '' }, - { name: 'eleventh', args: ['car', 5, '-='], expected: '-=car' }, - { name: 'twelfth', args: ['car', 7, '-='], expected: '-=-=car' }, - { name: 'thirteenth', args: ['car', 6, '-='], expected: '=-=car' }, - { name: 'fourteenth', args: ['car', 4, '-='], expected: '=car' }, - { name: 'fifteenth', args: ['car', 4, '-=:=-'], expected: '-car' }, - { name: 'sixteenth', args: ['car', 8, '-=:=-'], expected: '-=:=-car' }, - { name: 'seventeenth', args: ['car', 9, '-=:=-'], expected: '--=:=-car' }, - { name: 'eighteenth', args: ['car', 10, '-=:=-'], expected: '=--=:=-car' }, - { name: 'nineteenth', args: ['car', 11, '-=:=-'], expected: ':=--=:=-car' }, - { name: 'twentieth', args: ['car', 12, '-=:=-'], expected: '=:=--=:=-car' }, - ]; - function leftpad(str, len, pad) { - // write me! - } - evaluate(leftpad, leftpadTests); - - - function leftpadHandler() { - - // read and process user input (this works, no need to change it!) - const stringToPad = document.getElementById('leftpad-str-input').value; - const targetLengthStr = document.getElementById('leftpad-str-input').value; - let targetLength; - if (isNaN(targetLengthStr) || targetLengthStr === '') { - throw new TypeError('length needs to be a number'); - } else { - targetLength = Number(targetLengthStr); + { name: 'first', args: ['timmy', 6, ' '], expected: " timmy" }, + { name: 'second', args: ['timmy', 7, ' '], expected: " timmy" }, + { name: 'third', args: ['timmy', 5, ' '], expected: "timmy" }, + { name: 'fourth', args: ['timmy', 4, ' '], expected: "timm" }, + { name: 'fifth', args: ['silver', 4, '-'], expected: "silv" }, + { name: 'sixth', args: ['silver', 9, '-'], expected: "---silver" }, + { name: 'seventh', args: ['silver', 6, '-'], expected: "silver" }, + { name: 'eighth', args: ['silver', 3, '-'], expected: "sil" }, + { name: 'ninth', args: ['silver', 0, '-'], expected: "" }, + { name: 'tenth', args: ['silman', 0, '-'], expected: "" }, + { name: 'eleventh', args: ['car', 5, '-='], expected: "-=-=car" }, + { name: 'twelfth', args: ['car', 7, '-='], expected: "-=-=-=-=car" }, + { name: 'thirteenth', args: ['car', 6, '-='], expected: "-=-=-=car" }, + { name: 'fourteenth', args: ['car', 4, '-='], expected: "-=car" }, + { name: 'fifteenth', args: ['car', 4, '-=:=-'], expected: "-=:=-car" }, + { name: 'sixteenth', args: ['car', 8, '-=:=-'], expected: "-=:=--=:=--=:=--=:=--=:=-car" }, + { name: 'seventeenth', args: ['car', 9, '-=:=-'], expected: "-=:=--=:=--=:=--=:=--=:=--=:=-car" }, + { name: 'eighteenth', args: ['car', 10, '-=:=-'], expected: "-=:=--=:=--=:=--=:=--=:=--=:=--=:=-car" }, + { name: 'nineteenth', args: ['car', 11, '-=:=-'], expected: "-=:=--=:=--=:=--=:=--=:=--=:=--=:=--=:=-car" }, + { name: 'twentieth', args: ['car', 12, '-=:=-'], expected: "-=:=--=:=--=:=--=:=--=:=--=:=--=:=--=:=--=:=-car" }, +]; +function leftpad(str, len, pad) { + // write me! + var lenStr= str.length; + var strReturn = ""; + if(lenStr==len){ + strReturn = str; + }else if(lenStr>len){ + strReturn=str.substring(0,len); + }else if(lenStr Date: Fri, 18 Oct 2019 17:28:14 +0200 Subject: [PATCH 14/28] repeatChars.js created --- week-2-project/scripts/repeatChars.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/week-2-project/scripts/repeatChars.js b/week-2-project/scripts/repeatChars.js index d2209b6..57ee602 100644 --- a/week-2-project/scripts/repeatChars.js +++ b/week-2-project/scripts/repeatChars.js @@ -18,6 +18,24 @@ const repeatCharsTests = [ ]; function repeatChars(str) { // write this! + var strArr = str.split(''); + var strReturn=""; + strArr.forEach(function(str) { + var code=str.charCodeAt(); + if ( (code<=90 && code>=65)||(code<=122 && code>=97) ){ + str += str; + }else if (code<=57 && code>=48 ) { + str =str+str+str; + }else{ + str = str+str+str+str; + } + + strReturn=strReturn+str; + + }); + + return strReturn; + } evaluate(repeatChars, repeatCharsTests); From 11a31b422bb7f9b7b9e8dcfa10b39ef05c90af8d Mon Sep 17 00:00:00 2001 From: serhat Date: Sat, 26 Oct 2019 17:57:24 +0200 Subject: [PATCH 15/28] some update --- week-1-project/index.html | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/week-1-project/index.html b/week-1-project/index.html index 3c56b69..f282f48 100644 --- a/week-1-project/index.html +++ b/week-1-project/index.html @@ -47,10 +47,7 @@

Week 1 JS Project

- + From 07b338ba9410faff2a2ac593ae165953bd9502f8 Mon Sep 17 00:00:00 2001 From: serhat Date: Sat, 26 Oct 2019 20:47:18 +0200 Subject: [PATCH 16/28] caesarize is done --- week-3-project/logic/caesarize.js | 33 ++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/week-3-project/logic/caesarize.js b/week-3-project/logic/caesarize.js index fb0f0b0..83414e3 100644 --- a/week-3-project/logic/caesarize.js +++ b/week-3-project/logic/caesarize.js @@ -21,5 +21,36 @@ const caesarizeTests = [ ]; function caesarize(str, shiftNum) { // write me! -} + + var input = str; + var str=input.split(''); + + + for (var i = 0; i < str.length; i++) { + str[i] = str[i].charCodeAt(); + if ((str[i]>=97)&&(str[i]<=122)){ + str[i]+=shiftNum; + if (str[i]>122){ + str[i]=str[i]-26; + } + else if(str[i]<97){ + str[i]=str[i]+26; + } + str[i] = String.fromCharCode(str[i]); + } + else if((str[i]>=65)&&(str[i]<=90)){ + str[i]+=shiftNum; + if (str[i]>90){ + str[i]=str[i]-26; + } + else if (str[i]<65){ + str[i]=str[i]+26; + } + str[i] = String.fromCharCode(str[i]); + } + + } + return str.join(''); + } + evaluate(caesarize, caesarizeTests); From b70d9707e92dd5d21d434d64a8a541a2396b49ce Mon Sep 17 00:00:00 2001 From: serhat Date: Thu, 14 Nov 2019 23:19:36 +0100 Subject: [PATCH 17/28] variables completed --- module-exercises/variables.js | 46 ++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/module-exercises/variables.js b/module-exercises/variables.js index d7cffc1..bbaa8a8 100644 --- a/module-exercises/variables.js +++ b/module-exercises/variables.js @@ -81,7 +81,10 @@ try { let temp = ''; // can be done in 4 lines - + temp = a; + a = b; + b = c; + c = temp; console.assert(a === 1, "a should store 1"); console.assert(b === 2, "b should store 2"); @@ -95,8 +98,11 @@ try { let temp = ''; // can be done in 4 lines - - + temp = a; + a = c; + c = b; + b = temp; + console.assert(a === 1, "a should store 1"); console.assert(b === 2, "b should store 2"); console.assert(c === 3, "c should store 3"); @@ -109,7 +115,11 @@ try { let temp = ''; // can be done in 5 lines - + temp = a; + a = b; + b = c; + c = d; + d = temp; console.assert(a === 1, "a should store 1"); console.assert(b === 2, "b should store 2"); @@ -124,7 +134,12 @@ try { let temp = ''; // can be done in 6 lines - + temp = a; + a = d; + d = temp; + temp = b; + b = c; + c = temp; console.assert(a === "w", "a should store 'w'"); console.assert(b === "x", "b should store 'x'"); @@ -139,7 +154,12 @@ try { let temp = ' '; // can be done in 6 lines - + temp = a; + a = e; + e = temp; + temp = b; + b = d; + d = temp; console.assert(a === "v", "a should store 'v'"); console.assert(b === "w", "b should store 'w'"); @@ -189,7 +209,7 @@ try { // can be done in 1 line - + temp = a, a = b, b = c, c = temp; console.assert(a === 1, "a should store 1"); console.assert(b === 2, "b should store 2"); console.assert(c === 3, "c should store 3"); @@ -202,7 +222,7 @@ try { let temp = ''; // can be done in 1 line - + temp = a, a = c, c = b, b = temp; console.assert(a === 1, "a should store 1"); console.assert(b === 2, "b should store 2"); @@ -217,6 +237,7 @@ try { // can be done in 1 line + temp = a, a = b, b = c, c = d, d = temp; console.assert(a === 1, "a should store 1"); console.assert(b === 2, "b should store 2"); @@ -232,6 +253,7 @@ try { // can be done in 1 line + temp = a, a = d, d = temp, temp = b, b = c, c = temp; console.assert(a === "w", "a should store 'w'"); console.assert(b === "x", "b should store 'x'"); @@ -268,6 +290,9 @@ try { let temp = ''; // can be done in 3 lines or less + temp = a1; + a1 = a2 = b; + b = temp; console.assert(a1 === 1, 'a1 should store 1'); console.assert(a1 === a2, 'a1 should store the same value as a2'); @@ -284,7 +309,10 @@ try { let temp = ''; // can be done in 4 lines or less - + temp = a; + a = b1; + b1 = b2 = c1; + c1 = c2 = c3 = temp; console.assert(a === 1, 'a should store 1'); From 9260c0406f487490c0d058bcb33ef2cf052a9299 Mon Sep 17 00:00:00 2001 From: serhat Date: Fri, 15 Nov 2019 01:55:06 +0100 Subject: [PATCH 18/28] function.js completed --- module-exercises/functions.js | 96 +++++++++++++++++------------------ 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/module-exercises/functions.js b/module-exercises/functions.js index 7126e26..2a4ef8b 100644 --- a/module-exercises/functions.js +++ b/module-exercises/functions.js @@ -174,11 +174,11 @@ try { }; // 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 @@ try { }; // 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 = "y", arg2 = "x", arg3 = "z"; returnVal = f(arg2, arg1, arg3); console.log(returnVal === "zxy", "returnVal should be zxy"); @@ -217,12 +217,12 @@ try { }; // 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 @@ try { // 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 @@ try { // 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 @@ try { // 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 @@ try { // concatinate the params to pass the tests function f(param1, param2, param3) { - const result = null; + const result = param2 + param3 + param1; return result; }; @@ -314,7 +314,7 @@ try { function tracing8() { // arrange the parameters to pass the asserts - function f() { + function f(param3, param2, param1) { var result = param2 + param1 + param3; return result; }; @@ -334,7 +334,7 @@ try { function tracing9() { // arrange the parameters to pass the asserts - function f() { + function f(param2, param3, param1) { var result = param1 + param2 + param3; return result; }; @@ -354,21 +354,21 @@ try { 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 ?"); // <-- arg1 = "z", arg2 = "w", arg3 = "y", arg4 = "x"; - returnVal = f(); // <-- + returnVal = f(arg3, arg2, arg1, arg4); // <-- console.assert(returnVal === "zywx", "returnVal should be zywx"); } @@ -431,12 +431,12 @@ try { const writeTestCases1 = [ - { name: 'first', args: [/* what adds to be 5? */], expected: 5 }, - { name: 'second', args: [/* what else adds to be 5? */], expected: 5 }, - { name: 'third', args: [-2, 2], expected: null }, // what return value do you expect? - { name: 'fourth', args: [100, 20], expected: null }, // what return value do you expect? - { name: 'fifth', args: [], expected: null }, // create your own test case! - { name: 'sixth', args: [], expected: null }, // create your own test case! + { name: 'first', args: [0, 5], expected: 5 }, + { name: 'second', args: [2, 3], expected: 5 }, + { name: 'third', args: [-2, 2], expected: 0 }, // what return value do you expect? + { name: 'fourth', args: [100, 20], expected: 120 }, // what return value do you expect? + { name: 'fifth', args: [2, 2], expected: 4 }, // create your own test case! + { name: 'sixth', args: [2, 6], expected: 8 }, // create your own test case! ]; function functionToTest1(a, b) { const result = a + b; @@ -445,12 +445,12 @@ try { evaluate(functionToTest1, writeTestCases1); const writeTestCases2 = [ - { name: 'first', args: [/* what subtracts to be 5? */], expected: 5 }, - { name: 'second', args: [/* what else subtracts to be 5? */], expected: 5 }, - { name: 'third', args: [10, 2], expected: null }, // what return value do you expect? - { name: 'fourth', args: [10, 20], expected: null }, // what return value do you expect? - { name: 'fifth', args: [], expected: null }, // create your own test case! - { name: 'sixth', args: [], expected: null }, // create your own test case! + { name: 'first', args: [10, 5], expected: 5 }, + { name: 'second', args: [7, 2], expected: 5 }, + { name: 'third', args: [10, 2], expected: 8 }, // what return value do you expect? + { name: 'fourth', args: [10, 20], expected: -10 }, // what return value do you expect? + { name: 'fifth', args: [7, 7], expected: 0 }, // create your own test case! + { name: 'sixth', args: [6, 4], expected: 2 }, // create your own test case! ]; function functionToTest2(a, b) { const result = a - b; @@ -461,12 +461,12 @@ try { const writeTestCases3 = [ - { name: 'first', args: [/* what multiplies to be 5? */], expected: 5 }, - { name: 'second', args: [/* what else multiplies to be 5? */], expected: 5 }, - { name: 'third', args: [10, 2], expected: null }, // what return value do you expect? - { name: 'fourth', args: [10, 20], expected: null }, // what return value do you expect? - { name: 'fifth', args: [], expected: null }, // create your own test case! - { name: 'sixth', args: [], expected: null }, // create your own test case! + { name: 'first', args: [1, 5], expected: 5 }, + { name: 'second', args: [2, 2.5], expected: 5 }, + { name: 'third', args: [10, 2], expected: 20 }, // what return value do you expect? + { name: 'fourth', args: [10, 20], expected: 200 }, // what return value do you expect? + { name: 'fifth', args: [2, 9], expected: 18 }, // create your own test case! + { name: 'sixth', args: [1, 0], expected: 0 }, // create your own test case! ]; function functionToTest3(a, b) { const result = a * b; @@ -477,12 +477,12 @@ try { const writeTestCases4 = [ - { name: 'first', args: [/* what letters in what order will return "zyx"? */], expected: 'zyx' }, - { name: 'second', args: [/* what letters in what order will return "yzx"? */], expected: 'yzx' }, - { name: 'third', args: ['y', 'z', 'x'], expected: null }, // what return value do you expect? - { name: 'fourth', args: ['x', 'y', 'z'], expected: null }, // what return value do you expect? - { name: 'fifth', args: [], expected: null }, // create your own test case! - { name: 'sixth', args: [], expected: null }, // create your own test case! + { name: 'first', args: ['y', 'x', 'z'], expected: 'zyx' }, + { name: 'second', args: ['z', 'x', 'y'], expected: 'yzx' }, + { name: 'third', args: ['y', 'z', 'x'], expected: 'xyz' }, // what return value do you expect? + { name: 'fourth', args: ['x', 'y', 'z'], expected: 'zxy' }, // what return value do you expect? + { name: 'fifth', args: ['e','r','t'], expected: 'ter' }, // create your own test case! + { name: 'sixth', args: ['2','4','6'], expected: '624' }, // create your own test case! ]; function functionToTest4(a, b, c) { const result = c + a + b; @@ -493,12 +493,12 @@ try { const writeTestCases5 = [ - { name: 'first', args: [/* what letters in what order will return "zyx"? */], expected: 'zyx' }, - { name: 'second', args: [/* what letters in what order will return "yzx"? */], expected: 'yzx' }, - { name: 'third', args: ['y', 'z', 'x'], expected: null }, // what return value do you expect? - { name: 'fourth', args: ['x', 'y', 'z'], expected: null }, // what return value do you expect? - { name: 'fifth', args: [], expected: null }, // create your own test case! - { name: 'sixth', args: [], expected: null }, // create your own test case! + { name: 'first', args: ['x','z','y'], expected: 'zyx' }, + { name: 'second', args: ['x','y','z'], expected: 'yzx' }, + { name: 'third', args: ['y', 'z', 'x'], expected: "zxy" }, // what return value do you expect? + { name: 'fourth', args: ['x', 'y', 'z'], expected: "yzx" }, // what return value do you expect? + { name: 'fifth', args: [6,2,4], expected: 12 }, // create your own test case! + { name: 'sixth', args: ['at','ser','h'], expected: "serhat" }, // create your own test case! ]; function functionToTest5(a, b, c) { const result = b + c + a; From d4ac732cc125b2134f39dd26f6efb75eb48bd6ce Mon Sep 17 00:00:00 2001 From: serhat Date: Sat, 16 Nov 2019 18:14:09 +0100 Subject: [PATCH 19/28] primitive-types completed --- module-exercises/primitive-types.js | 74 ++++++++++++++--------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/module-exercises/primitive-types.js b/module-exercises/primitive-types.js index 360d7a0..6ecbb29 100644 --- a/module-exercises/primitive-types.js +++ b/module-exercises/primitive-types.js @@ -59,27 +59,27 @@ try { // the type of a value is very important to understanding how JS works const typeofTests = [ // boolean values - { name: 'boo, true', args: [true], expected: '' }, - { name: 'boo, false', args: [false], expected: '' }, + { name: 'boo, true', args: [true], expected: 'boolean' }, + { name: 'boo, false', args: [false], expected: 'boolean' }, // null's type is 'null'. just remember, don't try yet to understand - { name: 'obj, true', args: [null], expected: '' }, + { name: 'obj, true', args: [null], expected: 'object' }, // undefined. like with null, there is only one value with this type - { name: 'und, undefined', args: [undefined], expected: '' }, + { name: 'und, undefined', args: [undefined], expected: 'undefined' }, // strings are anything with quotes around it - { name: 'str, ', args: [''], expected: '' }, - { name: 'str, anything with quotes!', args: ['anything with quotes!'], expected: '' }, + { name: 'str, ', args: [''], expected: 'string' }, + { name: 'str, anything with quotes!', args: ['anything with quotes!'], expected: 'string' }, // numbers are a bit more strange and varied { name: 'num, 0.0', args: [0.0], expected: 'number' }, { name: 'num, NaN', args: [NaN], expected: 'number' }, { name: 'num, Infinity', args: [Infinity], expected: 'number' }, { name: 'num, 4', args: [4], expected: 'number' }, // write 6 more passing test cases with expected value 'number' - { name: '', args: null, expected: null }, - { name: '', args: null, expected: null }, - { name: '', args: null, expected: null }, - { name: '', args: null, expected: null }, - { name: '', args: null, expected: null }, - { name: '', args: null, expected: null }, + { name: 'boo, true', args: [true], expected: 'boolean' }, + { name: 'num, 4', args: [4], expected: 'number' }, + { name: 'str, ""', args: [""], expected: 'string' }, + { name: 'str, "serhat', args: ["serhat"], expected: 'string' }, + { name: 'und, undefined', args: [undefined], expected: 'undefined' }, + { name: 'obj, null', args: [null], expected: 'object' }, ] function allValuesHaveAType(value) { return typeof value; @@ -90,12 +90,12 @@ try { // fix the test cases' expected values to pass the function const typeofReturnsAStringTests = [ - { name: 'boo, true', args: [true], expected: 'boolean' }, - { name: 'boo, false', args: [false], expected: 'boolean' }, - { name: 'obj, true', args: [null], expected: 'object' }, - { name: 'und, undefined', args: [undefined], expected: 'undefined' }, + { name: 'boo, true', args: [true], expected: 'string' }, + { name: 'boo, false', args: [false], expected: 'string' }, + { name: 'obj, true', args: [null], expected: 'string' }, + { name: 'und, undefined', args: [undefined], expected: 'string' }, { name: 'str, anything with quotes!', args: ['anything with quotes!'], expected: 'string' }, - { name: 'num, 4', args: [4], expected: 'number' }, + { name: 'num, 4', args: [4], expected: 'string' }, ]; function typeofReturnsAString(value) { const typeofValue = typeof value; @@ -125,16 +125,16 @@ try { // fix the expected values to pass the tests const strictEqualityTests = [ - { name: 'NaN', args: [NaN, NaN], expected: null }, - { name: 'first', args: [true, 'true'], expected: null }, - { name: 'second', args: [1, '1'], expected: null }, - { name: 'third', args: ['1', '1'], expected: null }, - { name: 'fourth', args: [1000, 1e3], expected: null }, - { name: 'fifth', args: [+0, -0], expected: null }, - { name: 'sixth', args: [1, 1.0], expected: null }, - { name: 'seventh', args: ['', ""], expected: null }, - { name: 'eighth', args: ["", ``], expected: null }, - { name: 'ninth', args: [' ', ' '], expected: null }, + { name: 'NaN', args: [NaN, NaN], expected: false }, + { name: 'first', args: [true, 'true'], expected: false }, + { name: 'second', args: [1, '1'], expected: false }, + { name: 'third', args: ['1', '1'], expected: true }, + { name: 'fourth', args: [1000, 1e3], expected: true }, + { name: 'fifth', args: [+0, -0], expected: true }, + { name: 'sixth', args: [1, 1.0], expected: true }, + { name: 'seventh', args: ['', ""], expected: true }, + { name: 'eighth', args: ["", ``], expected: true }, + { name: 'ninth', args: [' ', ' '], expected: false }, ]; function strictEquality(a, b) { // if type OR value are not the same, returns false @@ -147,16 +147,16 @@ try { const strictInequalityTests = [ - { name: 'NaN', args: [NaN, NaN], expected: null }, - { name: 'first', args: [true, 'true'], expected: null }, - { name: 'second', args: [1, '1'], expected: null }, - { name: 'third', args: ['1', '1'], expected: null }, - { name: 'fourth', args: [1000, 1e3], expected: null }, - { name: 'fifth', args: [+0, -0], expected: null }, - { name: 'sixth', args: [1, 1.0], expected: null }, - { name: 'seventh', args: ['', ""], expected: null }, - { name: 'eighth', args: ["", ``], expected: null }, - { name: 'ninth', args: [' ', ' '], expected: null }, + { name: 'NaN', args: [NaN, NaN], expected: true }, + { name: 'first', args: [true, 'true'], expected: true }, + { name: 'second', args: [1, '1'], expected: true }, + { name: 'third', args: ['1', '1'], expected: false }, + { name: 'fourth', args: [1000, 1e3], expected: false }, + { name: 'fifth', args: [+0, -0], expected: false }, + { name: 'sixth', args: [1, 1.0], expected: false }, + { name: 'seventh', args: ['', ""], expected: false }, + { name: 'eighth', args: ["", ``], expected: false }, + { name: 'ninth', args: [' ', ' '], expected: true }, ]; function strictInequality(a, b) { // if type OR value are not the same, returns true From faad1e823b1f4ea3d89478b98721ef3a0c0323b3 Mon Sep 17 00:00:00 2001 From: serhat Date: Sat, 16 Nov 2019 19:03:43 +0100 Subject: [PATCH 20/28] explicit-coercion completed --- module-exercises/explicit-coercion.js | 32 +++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/module-exercises/explicit-coercion.js b/module-exercises/explicit-coercion.js index 5cf015c..4ae8dcc 100644 --- a/module-exercises/explicit-coercion.js +++ b/module-exercises/explicit-coercion.js @@ -23,12 +23,12 @@ try { // 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 @@ try { { 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: 'obj, 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 @@ try { { 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; From 9365cc59cd8ae4c6a6974b120bd9a27aff910746 Mon Sep 17 00:00:00 2001 From: serhat Date: Sat, 16 Nov 2019 23:30:23 +0100 Subject: [PATCH 21/28] truthiness & truthiness-operators completed --- module-exercises/truthiness-operators.js | 64 ++++++++++++------------ module-exercises/truthiness.js | 50 +++++++++--------- 2 files changed, 57 insertions(+), 57 deletions(-) diff --git a/module-exercises/truthiness-operators.js b/module-exercises/truthiness-operators.js index a1f05ef..d3cb7b5 100644 --- a/module-exercises/truthiness-operators.js +++ b/module-exercises/truthiness-operators.js @@ -20,14 +20,14 @@ try { { name: '"true", NaN', args: ["true", NaN], expected: "true" }, { name: 'NaN, NaN', args: [NaN, NaN], expected: NaN }, // complete these test cases - { name: null, args: null, expected: null }, - { name: null, args: null, expected: null }, - { name: null, args: null, expected: null }, - { name: null, args: null, expected: null }, - { name: null, args: null, expected: null }, - { name: null, args: null, expected: null }, - { name: null, args: null, expected: null }, - { name: null, args: null, expected: null }, + { name: '0, 0', args: [0, 0], expected: 0 }, + { name: 'NaN, 0', args: [NaN, 0], expected: 0 }, + { name: '"true", "false"', args: ["true", "false"], expected: "true" }, + { name: 'Infinity, NaN', args:[Infinity, NaN], expected: Infinity }, + { name: '"false","false"', args: ["false","false"], expected: "false" }, + { name: '0,1', args: [0,1], expected: 1 }, + { name: '0, NaN', args: [0, NaN], expected: NaN }, + { name: '1,1', args: [1,1], expected: 1 }, ]; function or(a, b) { return a || b; @@ -46,14 +46,14 @@ try { { name: '"true", NaN', args: ["true", NaN], expected: NaN }, { name: 'NaN, NaN', args: [NaN, NaN], expected: NaN }, // complete these test cases - { name: null, args: null, expected: null }, - { name: null, args: null, expected: null }, - { name: null, args: null, expected: null }, - { name: null, args: null, expected: null }, - { name: null, args: null, expected: null }, - { name: null, args: null, expected: null }, - { name: null, args: null, expected: null }, - { name: null, args: null, expected: null }, + { name: '1,1', args: [1,1], expected: 1 }, + { name: '"serhat", "10"', args: ["serhat", "10"], expected: "10" }, + { name: '"true", "true"', args: ["true","true"], expected: "true" }, + { name: 'NaN, 1', args: [NaN,1], expected: NaN }, + { name: '"false","false"', args: ["false","false"], expected: "false" }, + { name: '0,0', args: [0,0], expected: 0 }, + { name: 'undefined,NaN', args: [undefined, NaN], expected: undefined }, + { name: '0,1', args: [0,1], expected: 0 }, ]; function and(a, b) { return a && b; @@ -69,14 +69,14 @@ try { { name: 'NaN', args: [NaN], expected: true }, { name: '"hi!"', args: ['hi!'], expected: false }, // complete these test cases - { name: null, args: null, expected: null }, - { name: null, args: null, expected: null }, - { name: null, args: null, expected: null }, - { name: null, args: null, expected: null }, - { name: null, args: null, expected: null }, - { name: null, args: null, expected: null }, - { name: null, args: null, expected: null }, - { name: null, args: null, expected: null }, + { name: '1', args: [1], expected: false }, + { name: '0', args: [0], expected: true }, + { name: 'undefined', args: [undefined], expected: true }, + { name: 'Infinity', args: [Infinity], expected: false }, + { name: 'NaN', args: [NaN], expected: true }, + { name: '"', args: [""], expected: true }, + { name: '"str"', args: ["str"], expected: false }, + { name: "42", args: [42], expected: false }, ]; function not(a) { return !a; @@ -92,14 +92,14 @@ try { { name: '"hi!"', args: ['hi!', '?', ':'], expected: '?' }, { name: '0', args: [0, 'truthy', 'falsey'], expected: 'falsey' }, // complete these test cases - { name: null, args: null, expected: null }, - { name: null, args: null, expected: null }, - { name: null, args: null, expected: null }, - { name: null, args: null, expected: null }, - { name: null, args: null, expected: null }, - { name: null, args: null, expected: null }, - { name: null, args: null, expected: null }, - { name: null, args: null, expected: null }, + { name: '1', args: [1, "a","b"], expected: "a" }, + { name: '0', args: [0, "a","b"], expected: "b" }, + { name: "true", args: [true, 1,2], expected: 1 }, + { name: "false", args: [false,1,2], expected: 2 }, + { name: 'NaN', args: [NaN, "true", "false"], expected: "false" }, + { name: 'Infinity', args: [Infinity, "true","false"], expected: "true" }, + { name: 'undefined', args: [undefined, "true","false"], expected: "false" }, + { name: '""', args: ["", "true","false"], expected: "false" }, ]; function ternary(a, b, c) { return a ? b : c; diff --git a/module-exercises/truthiness.js b/module-exercises/truthiness.js index 8de9cee..b16f3e6 100644 --- a/module-exercises/truthiness.js +++ b/module-exercises/truthiness.js @@ -38,12 +38,12 @@ try { { name: '-0', args: [-0], expected: 'falsey' }, { name: 'NaN', args: [NaN], expected: 'falsey' }, // try it yourself! write some more test cases - { name: '', args: null, expected: null }, - { name: '', args: null, expected: null }, - { name: '', args: null, expected: null }, - { name: '', args: null, expected: null }, - { name: '', args: null, expected: null }, - { name: '', args: null, expected: null }, + { name: '""', args: [""], expected: 'falsey' }, + { name: '1', args: ['1'], expected: 'truey' }, + { name: 'NaN', args: [NaN], expected: 'falsey' }, + { name: '"serhat', args: ['serhat'], expected: 'truey' }, + { name: '0', args: [0], expected: 'falsey' }, + { name: 'null', args: [null], expected: 'falsey' }, ]; function truthinessByTestCase(x) { const coercedToBool = Boolean(x); @@ -57,25 +57,25 @@ try { // change the expected values from null to true or false // and come on. don't just use trial and error, think a bit harder! const testsToPass = [ - { name: 'first', args: [0.0], expected: null }, - { name: 'second', args: [null], expected: null }, - { name: 'third', args: ['hacking your future!'], expected: null }, - { name: "fourth", args: [''], expected: null }, - { name: 'fifth', args: ["--<(*)>--"], expected: null }, - { name: 'sixth', args: [undefined], expected: null }, - { name: 'seventh', args: [""], expected: null }, - { name: 'eighth', args: [Symbol('hello')], expected: null }, - { name: 'ninth', args: [``], expected: null }, - { name: 'tenth', args: [true], expected: null }, - { name: 'eleventh', args: [1e3], expected: null }, - { name: 'twelfth', args: [0], expected: null }, - { name: 'thirteenth', args: [Symbol()], expected: null }, - { name: 'fourteenth', args: [-0], expected: null }, - { name: 'fifteenth', args: [NaN], expected: null }, - { name: 'sixteenth', args: [Infinity], expected: null }, - { name: 'seventeenth', args: [Symbol(false)], expected: null }, - { name: 'eighteenth', args: [+0], expected: null }, - { name: 'nineteenth', args: [false], expected: null }, + { name: 'first', args: [0.0], expected: false }, + { name: 'second', args: [null], expected: false }, + { name: 'third', args: ['hacking your future!'], expected: true }, + { name: "fourth", args: [''], expected: false }, + { name: 'fifth', args: ["--<(*)>--"], expected: true }, + { name: 'sixth', args: [undefined], expected: false }, + { name: 'seventh', args: [""], expected: false }, + { name: 'eighth', args: [Symbol('hello')], expected: true }, + { name: 'ninth', args: [``], expected: false }, + { name: 'tenth', args: [true], expected: true }, + { name: 'eleventh', args: [1e3], expected: true }, + { name: 'twelfth', args: [0], expected: false }, + { name: 'thirteenth', args: [Symbol()], expected: true }, + { name: 'fourteenth', args: [-0], expected: false }, + { name: 'fifteenth', args: [NaN], expected: false }, + { name: 'sixteenth', args: [Infinity], expected: true }, + { name: 'seventeenth', args: [Symbol(false)], expected: true }, + { name: 'eighteenth', args: [+0], expected: false }, + { name: 'nineteenth', args: [false], expected: false }, ]; Boolean.quizzing = true; evaluate(Boolean, testsToPass); From d09a90df54e8d90e3a6e511a0be50d8be17dae23 Mon Sep 17 00:00:00 2001 From: serhat Date: Sun, 17 Nov 2019 01:30:32 +0100 Subject: [PATCH 22/28] arrays completed --- module-exercises/arrays.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/module-exercises/arrays.js b/module-exercises/arrays.js index 56f4011..7578171 100644 --- a/module-exercises/arrays.js +++ b/module-exercises/arrays.js @@ -101,22 +101,22 @@ try { function passTheAssertions1() { - ; // declare and assign a1 - ; // declare and assign a2 + let a1 = [1]; // 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 = [2]; // declare and assign b1 + let b2 = [3]; // 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!"'); - ; // write two lines to pass the assertions - ; + b1[0] = 'bye!'; // write two lines to pass the assertions + b2[0] = b1[0]; console.assert(b1[0] === b2[0], 'b1[0] should strictly equal b2[0]'); console.assert(b1[0] === 'bye!', 'b1.x should strictly equal "bye!"'); } @@ -127,16 +127,16 @@ try { const value1 = 5; let reference1 = []; - ; // write this line + let value2 = value1; // 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 console.assert(value1 !== null, "value1 should strictly equal ___"); - ; // write this line + reference1[0] = 'hi!'; // write this line console.assert(reference1[0] === reference2[0], "references[0] should be strictly equal"); console.assert(reference1[0] === 'hi!', "reference1[0] should be strictly equal to 'hi!'"); @@ -151,8 +151,8 @@ try { function passTheAssertions3() { - ; // write this line - ; // write this line + let arr1 = ['A','B']; // write this line + let arr2 = ['A','B']; // write this line console.assert(arr1 !== arr2, 'the variables should not be strictly equal'); console.assert(arr1[1] === arr2[1], 'their first entries should be the same'); console.assert(arr1[1] === 'B', 'arr1[1]] should be "B"'); @@ -161,18 +161,18 @@ try { console.assert(arr1[index] === arr2[index], 'arr1[index] should strictly equal arr2[index]'); console.assert(arr1[index] === 'A', 'arr1[index] should be "A"'); - ; // write this line - ; // write this line + arr1[arr2[2]] = arr1[1]; // write this line + arr2[arr1[2]] = arr1[arr2[2]]; // write this line console.assert(arr1[arr2[2]] === 'B', 'arr2[2] should be "B"s index in arr1'); console.assert(arr1[arr2[2]] === arr2[arr1[2]], 'some tricky nested thing should be true'); - ; // write this line + let arr3 = arr2; // write this line console.assert(arr1 !== arr2, 'arr1 should strictly equal arr2'); console.assert(arr3 !== arr1, 'arr3 should not strictly equal arr`'); console.assert(arr3 === arr2, 'arr3 should strictly equal arr2'); console.assert(arr3[index] === arr1[0], 'arr3[index] should strictly equal arr1[0]'); - ; // write this line + arr3[2] = arr2[0]; // write this line console.assert(arr3[2] === arr2[index], 'arr3[2] should strictly equal arr2[index]'); } evaluate(passTheAssertions3); From 6b9cb80a6e73cb9ba676ef857a50bde99b3ab8c7 Mon Sep 17 00:00:00 2001 From: serhat Date: Sun, 17 Nov 2019 23:48:10 +0100 Subject: [PATCH 23/28] objects & arrays-objects completed --- module-exercises/arrays-vs-objects.js | 12 ++++++--- module-exercises/objects.js | 38 +++++++++++++-------------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/module-exercises/arrays-vs-objects.js b/module-exercises/arrays-vs-objects.js index 4a7e82c..c6a4352 100644 --- a/module-exercises/arrays-vs-objects.js +++ b/module-exercises/arrays-vs-objects.js @@ -17,7 +17,9 @@ try { let _ = null; // swap the values stored in each structure - + _ = obj.prop; + obj.prop = arr[0]; + arr[0] = _; console.assert(obj.prop === "object", "obj.prop should be 'object"); console.assert(arr[0] === "array", "arr[0] should be 'array"); @@ -32,11 +34,14 @@ try { // swap the values stored in each structure using brackets and these variables const objKey = 'prop'; const arrIndex = 0; + _ = obj[objKey]; + obj[objKey] = arr[arrIndex]; + arr[arrIndex] = _ ; // asserts - console.assert(obj[obj_key] === "object", "obj assert"); - console.assert(arr[arr_index] === "array", "arr assert"); + console.assert(obj[objKey] === "object", "obj assert"); + console.assert(arr[arrIndex] === "array", "arr assert"); } evaluate(swapValues2); @@ -54,6 +59,7 @@ try { const arr2 = [3, 2, 1]; const arr3 = [1, 2, 3]; // do you remember why '===' won't work here? + console.assert(evaluate.compareValues(arr1, arr2), 'arr: same values, different order'); console.assert(evaluate.compareValues(arr1, arr3), 'arr: same values, same order'); diff --git a/module-exercises/objects.js b/module-exercises/objects.js index 7c5d633..261e070 100644 --- a/module-exercises/objects.js +++ b/module-exercises/objects.js @@ -113,34 +113,34 @@ try { function passTheAssertions1() { - ; // declare and assign a1 - ; // declare and assign a2 + const 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 + const b1 = {}; // declare and assign b1 + let b2 = {}; // declare and assign b2 console.assert(b1 !== b2, 'b1 should not strictly equal b2'); // --- - ; // write one line to pass the assertions + a1.x = 'hi!'; // write one line to pass the assertions console.assert(a1.x === a2.x, 'a1.x should strictly equal a2.x'); console.assert(a1.x === 'hi!', 'a1.x should strictly equal "hi!"'); - ; // write two lines to pass the assertions - ; + b1.x = 'bye!'; // write two lines to pass the assertions + b2.x = b1.x; console.assert(b1.x === b2.x, 'b1.x should strictly equal b2.x'); console.assert(b1.x === 'bye!', 'b1.x should strictly equal "bye!"'); // -- const index = 'y'; - ; // write one line to pass the assertions + a1.y = 'roof!'; // write one line to pass the assertions console.assert(a1[index] === a2[index], 'a1[index] should strictly equal a2[index]'); console.assert(a1[index] === 'roof!', 'a1[index] should strictly equal "roof!"'); - ; // write two lines to pass the assertions - ; + b1.y = 'floor!'; // write two lines to pass the assertions + b2.y = b1.y; console.assert(b1[index] === b2[index], 'b1[index] should strictly equal b2[index]'); console.assert(b1[index] === 'floor!', 'b1[index] should strictly equal "floor!"'); @@ -153,16 +153,16 @@ try { const value1 = 5; let reference1 = {}; - ; // write this line + let value2 = value1; // 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 console.assert(value1 !== null, "value1 should strictly equal ___"); - ; // write this line + reference1.x = 'hi!'; // write this line console.assert(reference1.x === reference2.x, "references.x should be strictly equal"); console.assert(reference1.x === 'hi!', "references.x should strictly equal 'hi!'"); @@ -178,8 +178,8 @@ try { function passTheAssertions3() { - ; // write this line - ; // write this line + let obj1 = {x: 'A', y: 'B'}; // write this line + let obj2 = {x: 'A', y: 'B'}; // write this line console.assert(obj1 !== obj2, 'the variables should not be strictly equal'); console.assert(obj1.y === obj2.y, 'their first entries should be the same'); console.assert(obj1.y === 'B', 'obj1.y should be "B"'); @@ -188,18 +188,18 @@ try { console.assert(obj1[index] === obj2[index], 'obj1[index] should strictly equal obj2[index]'); console.assert(obj1[index] === 'A', 'obj1[index] should be "A"'); - ; // write this line - ; // write this line + obj1[obj2.z] = 'B'; // write this line + obj2[obj1.z]= obj1[obj2.z]; // write this line console.assert(obj1[obj2.z] === 'B', 'obj2.z should be "B"s index in obj1'); console.assert(obj1[obj2.z] === obj2[obj1.z], 'some tricky nested thing should be true'); - ; // write this line + let obj3 = obj2; // write this line console.assert(obj1 !== obj2, 'obj1 should strictly equal obj2'); console.assert(obj3 !== obj1, 'obj3 should not strictly equal obj`'); console.assert(obj3 === obj2, 'obj3 should strictly equal obj2'); console.assert(obj3[index] === obj1.x, 'obj3[index] should strictly equal obj1.x'); - ; // write this line + obj3.z = obj2[index]; // write this line console.assert(obj3.z === obj2[index], 'obj3.z should strictly equal obj2[index]'); } evaluate(passTheAssertions3); From 624ffcd478a3a228521ab9457f27df629a20091f Mon Sep 17 00:00:00 2001 From: serhat Date: Mon, 18 Nov 2019 11:47:28 +0100 Subject: [PATCH 24/28] block-scope completed --- module-exercises/block-scope.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/module-exercises/block-scope.js b/module-exercises/block-scope.js index 71347e3..0726f93 100644 --- a/module-exercises/block-scope.js +++ b/module-exercises/block-scope.js @@ -41,6 +41,7 @@ try { const aString = 'inner value'; console.assert(aString === 'inner value', 'aString should be "inner value"'); } + console.assert(aString === 'outer value', 'aString should be "outer value"'); } @@ -48,10 +49,10 @@ try { function blockScopeExercise1() { - ; // write this line + const a = 'hi!'; // write this line console.assert(a === 'hi!', 'a should be "hi!"'); { - ; // write this line + const a = 'hola!'; // write this line console.assert(a === 'hola!', 'a should be "hola!"'); } console.assert(a === 'hi!', 'a should be "hi!"'); @@ -59,10 +60,10 @@ try { evaluate(blockScopeExercise1); function blockScopeExercise2() { - ; // write this line + const a = 'hi!'; // write this line console.assert(a === 'hi!', 'a should be "hi!"'); { - ; // write this line + let b = 'hola!'; // write this line console.assert(b === 'hola!', 'b should be "hola!"'); console.assert(a === 'hi!', 'a should be "hi!"'); } @@ -71,26 +72,26 @@ try { evaluate(blockScopeExercise2); function blockScopeExercise3() { - ; // write this line + const a = 'hi!'; // write this line console.assert(a === 'hi!', 'a should be "hi!"'); { - ; // write this line + let b = 'hola!'; // write this line console.assert(b === 'hola!', 'b should be "hola!"'); console.assert(a === 'hi!', 'a should be "hi!"'); } - ; // write this line + let b = 'hola!'; // write this line console.assert(b === 'hola!', 'b should be "hola!"'); console.assert(a === 'hi!', 'a should be "hi!"'); } evaluate(blockScopeExercise3); function blockScopeExercise4() { - ; // write this line + let x = 'null'; // write this line console.assert(x === 'null', 'x should be "null!"'); { const a = 5; const b = 4; - ; // write this line + x = a * b ; // write this line console.assert(x === 20, 'x should be 20'); } console.assert(x === 20, 'x should be 20'); @@ -98,12 +99,12 @@ try { evaluate(blockScopeExercise4); function blockScopeExercise5() { - ; // write this line + let x = 'null'; // write this line console.assert(x === 'null', 'x should be "null!"'); { const a = false; const b = true; - ; // write this line + if (x = b ){ x = 20; } // write this line console.assert(x === 20, 'x should be true'); } console.assert(x === 20, 'x should be true'); From 37658e1c9e0cbebd4ccf37a92d90ac97ed95eee1 Mon Sep 17 00:00:00 2001 From: serhat Date: Mon, 18 Nov 2019 15:32:54 +0100 Subject: [PATCH 25/28] conditional-statements completed --- module-exercises/conditional-statements.js | 94 ++++++++++++---------- 1 file changed, 52 insertions(+), 42 deletions(-) diff --git a/module-exercises/conditional-statements.js b/module-exercises/conditional-statements.js index c225d07..9728967 100644 --- a/module-exercises/conditional-statements.js +++ b/module-exercises/conditional-statements.js @@ -87,15 +87,15 @@ try { // complete the args array to pass each test case const conditionalTestCases1 = [ { name: 'if 1', args: ['5', 5], expected: 'if' }, - { name: 'if 2', args: null, expected: 'if' }, - { name: 'if 3', args: null, expected: 'if' }, - { name: 'if 4', args: null, expected: 'if' }, - { name: 'if 5', args: null, expected: 'if' }, + { name: 'if 2', args: ['0',0], expected: 'if' }, + { name: 'if 3', args: ['',0], expected: 'if' }, + { name: 'if 4', args: [5, 5], expected: 'if' }, + { name: 'if 5', args: ['2', 2], expected: 'if' }, { name: 'else 1', args: [true, 0], expected: 'else' }, - { name: 'else 2', args: null, expected: 'else' }, - { name: 'else 3', args: null, expected: 'else' }, - { name: 'else 4', args: null, expected: 'else' }, - { name: 'else 5', args: null, expected: 'else' }, + { name: 'else 2', args: [1, 0], expected: 'else' }, + { name: 'else 3', args: ['9','ll'], expected: 'else' }, + { name: 'else 4', args: ['9',0], expected: 'else' }, + { name: 'else 5', args: [9, 7], expected: 'else' }, ]; function conditionalToPass1(a, b) { if (Number(a) === b) { @@ -110,20 +110,20 @@ try { // complete the args array to pass each test case const conditionalTestCases2 = [ { name: 'if 1', args: ['happy', 'day'], expected: 'if' }, - { name: 'if 2', args: null, expected: 'if' }, - { name: 'if 3', args: null, expected: 'if' }, - { name: 'if 4', args: null, expected: 'if' }, - { name: 'if 5', args: null, expected: 'if' }, + { name: 'if 2', args: ['true','false'], expected: 'if' }, + { name: 'if 3', args: [false, true], expected: 'if' }, + { name: 'if 4', args: [null,null], expected: 'if' }, + { name: 'if 5', args: [0,1], expected: 'if' }, { name: 'else if 1', args: [1, ''], expected: 'else if' }, - { name: 'else if 2', args: null, expected: 'else if' }, - { name: 'else if 3', args: null, expected: 'else if' }, - { name: 'else if 4', args: null, expected: 'else if' }, - { name: 'else if 5', args: null, expected: 'else if' }, + { name: 'else if 2', args: [false, 1], expected: 'else if' }, + { name: 'else if 3', args: ['true',false], expected: 'else if' }, + { name: 'else if 4', args: ["1",0], expected: 'else if' }, + { name: 'else if 5', args: [true,0], expected: 'else if' }, { name: 'else 1', args: [true, 1], expected: 'else' }, - { name: 'else 2', args: null, expected: 'else' }, - { name: 'else 3', args: null, expected: 'else' }, - { name: 'else 4', args: null, expected: 'else' }, - { name: 'else 5', args: null, expected: 'else' }, + { name: 'else 2', args: [null,0], expected: 'else' }, + { name: 'else 3', args: ["1",1], expected: 'else' }, + { name: 'else 4', args: ['',NaN], expected: 'else' }, + { name: 'else 5', args: [false,0], expected: 'else' }, ]; function conditionalToPass2(a, b) { if (typeof a === typeof b) { @@ -153,7 +153,11 @@ try { ]; // careful of unreachable blocks! are any of yours unreachable? function passTests1(a, b) { - // conditional an if/else conditional statement to pass these tests + if (Boolean(a) === Boolean(b)) { + return 'if'; + }else { + return 'else'; + }// conditional an if/else conditional statement to pass these tests // you can pass the tests using only // primitive values // Number, String, Boolean @@ -182,7 +186,13 @@ try { ]; // careful of unreachable blocks! are any of yours unreachable? function passTests2(a, b) { - // conditional an if/elseif/else conditional statement to pass these tests + if ( a === b ) { + return 'if'; + } else if ( Number(a) !== Number(b)){ + return 'else if'; + } else { + return 'else'; + }// conditional an if/elseif/else conditional statement to pass these tests // you can pass the tests using only // primitive values // Number, String, Boolean @@ -221,16 +231,16 @@ try { const conditionalTests1 = [ // write test cases to pass this function - { name: 'first', args: null, expected: null }, - { name: 'second', args: null, expected: null }, - { name: 'third', args: null, expected: null }, - { name: 'fourth', args: null, expected: null }, - { name: 'fifth', args: null, expected: null }, - { name: 'sixth', args: null, expected: null }, - { name: 'seventh', args: null, expected: null }, - { name: 'eighth', args: null, expected: null }, - { name: 'ninth', args: null, expected: null }, - { name: 'tenth', args: null, expected: null }, + { name: 'first', args: [true,true], expected: true }, + { name: 'second', args: [1,1], expected: true }, + { name: 'third', args: ["2",1], expected: false }, + { name: 'fourth', args: [true,0], expected: true }, + { name: 'fifth', args: [NaN,NaN], expected: false }, + { name: 'sixth', args: ["1", 1], expected: false }, + { name: 'seventh', args: ["",""], expected: false }, + { name: 'eighth', args: [false, true], expected: true }, + { name: 'ninth', args: [1, 2], expected: true }, + { name: 'tenth', args: ["r", true], expected: false }, ]; function conditionalFunction1(a, b) { let result = null; @@ -249,16 +259,16 @@ try { const conditionalTests2 = [ // write test cases to pass this function - { name: 'first', args: null, expected: null }, - { name: 'second', args: null, expected: null }, - { name: 'third', args: null, expected: null }, - { name: 'fourth', args: null, expected: null }, - { name: 'fifth', args: null, expected: null }, - { name: 'sixth', args: null, expected: null }, - { name: 'seventh', args: null, expected: null }, - { name: 'eighth', args: null, expected: null }, - { name: 'ninth', args: null, expected: null }, - { name: 'tenth', args: null, expected: null }, + { name: 'first', args: [1,1], expected: 1 }, + { name: 'second', args: [true,false], expected: true }, + { name: 'third', args: [true, 1], expected: false }, + { name: 'fourth', args: [true, 0], expected: false }, + { name: 'fifth', args: [2, 1], expected: 1 }, + { name: 'sixth', args: [false,true], expected: true }, + { name: 'seventh', args: [1, true], expected: false }, + { name: 'eighth', args: ["otur","kalk"], expected: "kalk"}, + { name: 'ninth', args: ["oreo","peanut"], expected: "peanut" }, + { name: 'tenth', args: ["str", 1], expected: null }, ]; function conditionalFunction2(a, b) { let result = null; From be2f63daa95bebdc329cc43254d4c0b3f727bb3a Mon Sep 17 00:00:00 2001 From: serhat Date: Mon, 18 Nov 2019 15:58:47 +0100 Subject: [PATCH 26/28] statements-vs-expressions completed --- module-exercises/statements-vs-expressions.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/module-exercises/statements-vs-expressions.js b/module-exercises/statements-vs-expressions.js index 1c50062..40f189a 100644 --- a/module-exercises/statements-vs-expressions.js +++ b/module-exercises/statements-vs-expressions.js @@ -61,11 +61,11 @@ try { { name: 'fourth', args: [0, ""], expected: 'falsey' }, { name: 'fifth', args: [" ", 1], expected: 'truthy' }, // write a few more tests - { name: 'sixth', args: null, expected: null }, - { name: 'seventh', args: null, expected: null }, - { name: 'eighth', args: null, expected: null }, - { name: 'ninth', args: null, expected: null }, - { name: 'tenth', args: null, expected: null }, + { name: 'sixth', args: [NaN, true], expected: "truthy" }, + { name: 'seventh', args: [1,0], expected: "truthy" }, + { name: 'eighth', args: [NaN,NaN], expected: "falsey" }, + { name: 'ninth', args: ["",''], expected: "falsey" }, + { name: 'tenth', args: [false,false], expected:"falsey" }, ]; function ternaryExpression(a, b) { From 294854a7eaebba79440876efc5409f982d1260f7 Mon Sep 17 00:00:00 2001 From: serhat Date: Mon, 18 Nov 2019 20:31:13 +0100 Subject: [PATCH 27/28] loops completed --- module-exercises/loops.js | 46 +++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/module-exercises/loops.js b/module-exercises/loops.js index 0c29e90..8323cc5 100644 --- a/module-exercises/loops.js +++ b/module-exercises/loops.js @@ -108,7 +108,7 @@ try { // fix the three pieces of this for loop to pass the assert let forResult = 0; - for (null; null; null) { + for (let i = 0; i !== 8; i += 2) { forResult += i; } @@ -122,16 +122,16 @@ try { function loopRefactor2() { let forResult = 0; - for (i = 5; i > -2; i--) { + for (let i = 5; i > -2; i--) { forResult = forResult + i; } // fix the three pieces of this for loop to pass the assert let whileResult = 0; - null; - while (null) { + let i = 5; + while (i > -2) { whileResult = whileResult + i; - null; + i--; } console.assert(forResult === whileResult, 'both loops should have the same behavior'); @@ -151,7 +151,7 @@ try { // fix the three pieces of this for loop to pass the assert let forResult = 0; - for (null; null; null) { + for (let i = 0; i !== 8; i += 2) { forResult += i; } @@ -171,7 +171,10 @@ try { }; // refactor the while loop into a for loop - let forResult = null; + let forResult = .5; + for(let x =9; x > 2 ; x--){ + forResult *= x; + } console.assert(forResult === whileResult, 'both loops should have the same behavior'); @@ -189,7 +192,10 @@ try { }; // refactor the while loop into a for loop - let forResult = null; + let forResult = true; + for(let x = -1; x < 2; x++){ + forResult = forResult && Boolean(x); + } console.assert(forResult === whileResult, 'both loops should have the same behavior'); @@ -206,6 +212,11 @@ try { // refactor the for loop into a while loop let whileResult = 0; + let i = -3; + while (i === 10 || i < 20){ + whileResult = i; + i *= -1.5; + } console.assert(forResult === whileResult, 'both loops should have the same behavior'); @@ -223,6 +234,13 @@ try { // refactor the for loop into a while loop let whileResult = 0; + let i = 0; + let j = 10; + while (i !== j){ + whileResult = i; + i++; + j--; + } console.assert(forResult === whileResult, 'both loops should have the same behavior'); @@ -246,9 +264,9 @@ try { function while1() { const result = []; let i = 0; - while (null) { + while (1 < 26) { result.push(i * 2); - null; + i = i * 3 + 2; } return result; } @@ -256,7 +274,7 @@ try { function for1() { const result = []; - for (let i = 0; null; null) { + for (let i = 0; i < 26; i = i * 3 + 2) { result.push(i * 2); } return result; @@ -307,10 +325,10 @@ try { function while3(input) { const result = []; - let i = null; + let i = input * 3; while (i > input) { result.push(i); - null; + i -= 2; } return result; } @@ -318,7 +336,7 @@ try { function for3(input) { const result = []; - for (let i = null; i > input; null) { + for (let i = input * 3; i > input; i -= 2) { result.push(i); } return result; From 51facfbab8b0ed37d52ff30c207231a6e830d19c Mon Sep 17 00:00:00 2001 From: serhat Date: Mon, 18 Nov 2019 22:59:03 +0100 Subject: [PATCH 28/28] fixed a few errors --- module-exercises/errors-and-lifecycle.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/module-exercises/errors-and-lifecycle.js b/module-exercises/errors-and-lifecycle.js index 66ed6c7..a15070f 100644 --- a/module-exercises/errors-and-lifecycle.js +++ b/module-exercises/errors-and-lifecycle.js @@ -48,7 +48,7 @@ try { // these are detected at creation phase and will stop the page from loading function missingVariableName() { - const = null; + const a = null; } evaluate(missingVariableName); @@ -58,38 +58,38 @@ try { evaluate(missingInConst) function unexpectedToken1() { - const a = 1: + const a = 1; } evaluate(unexpectedToken1); function unexpectedToken2() { - const x = 3]; + const x = 3; } evaluate(unexpectedToken2); function unexpectedToken3() { let a = { b: 3 }; - let b = a.b.3; + let b = a[b]; } evaluate(unexpectedToken3); function unexpectedToken4() { - const str = "he told me "run!" the horse arrives!"; + const str = "he told me 'run!' the horse arrives!"; } evaluate(unexpectedToken4); function missingAfterElement1() { - const myArray = [1, 2, 3; + const myArray = [1, 2, 3]; } evaluate(missingAfterElement1) function missingAfterElement1() { - const myArray = [1, 2 3]; + const myArray = [1, 2, 3]; } evaluate(missingAfterElement1) function missingBeforeformal() { - function getNine { + function getNine() { const x = 6, y = 3; return x + y; } @@ -97,8 +97,7 @@ try { evaluate(missingBeforeformal); function unEscapedLineBreak() { - const a = 'this is - two lines'; + const a = 'this is two lines'; } evaluate(unEscapedLineBreak);