diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..00d476c Binary files /dev/null and b/.DS_Store differ diff --git a/module-exercises/arrays.js b/module-exercises/arrays.js index baf3f53..617a906 100644 --- a/module-exercises/arrays.js +++ b/module-exercises/arrays.js @@ -102,23 +102,39 @@ evaluate(example_garbageCollectingArrays); function passTheAssertions1() { ; // declare and assign a1 + let a1 = []; ; // declare and assign a2 + let a2 = a1; + console.assert(a1 === a2, 'a1 should strictly equal a2'); + ; // declare and assign b1 + let b1 = []; ; // declare and assign b2 - console.assert(b1 !== b2, 'b1 should not strictly equal b2'); + let b2 = []; + + console.assert(b1 !== b2, 'b1 should not strictly equal b2'); + // --- ; // write one line to pass the assertions + a1 = a2 = ['hi!']; + 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 = ['bye!']; + b2 = b1; console.assert(b1[0] === b2[0], 'b1[0] should strictly equal b2[0]'); console.assert(b1[0] === 'bye!', 'b1.x should strictly equal "bye!"'); + + } evaluate(passTheAssertions1); @@ -128,24 +144,38 @@ function passTheAssertions2() { let reference1 = []; ; // write this line + + let value2 = value1; + console.assert(value2 === value1, "value1 should strictly equal value2"); ; // write this line + + let reference2 = reference1; + console.assert(reference2 === reference1, "reference1 should strictly equal reference2"); - value2 = value2 + 1; // write this line + value2 = value2 + 1; value1 = '___'; + + console.assert(value1 !== null, "value1 should strictly equal ___"); ; // write this line + referans1[0] = reference2[0]; + reference1 [0] = ['hi!']; + console.log(reference2); + 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!'"); ; // write this line + reference1 = reference2; + console.assert(reference1 === reference2, "references should be strictly equal"); // remove the array from memory - ; // write this line - ; // write this line + ; reference1 = null; + ; reference2 = null; } evaluate(passTheAssertions2); @@ -153,6 +183,12 @@ evaluate(passTheAssertions2); function passTheAssertions3() { ; // write this line ; // write this line +arr1 = []; +arr2 = []; +arr1[1] = arr2[1]; +arr[1] = ['B'] + + 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"'); @@ -163,10 +199,15 @@ function passTheAssertions3() { ; // write this line ; // write this line + arr1[arr2[2]] = ['B']; + arr1[arr2[2]] = arr2[arr1[2]]; + 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 + + 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'); diff --git a/module-exercises/explicit-coercion.js b/module-exercises/explicit-coercion.js index d6bcfd4..20b2db0 100644 --- a/module-exercises/explicit-coercion.js +++ b/module-exercises/explicit-coercion.js @@ -23,12 +23,12 @@ // fix the test cases' expected values to pass the function const StringTests = [ // string values remain unchanged - { name: 'str, any string', args: ['any string'], expected: null }, + { name: 'str, any string', args: ['any string'], expected: 'any string' }, // casting with String just puts quotes around a thing - { name: 'num, 3', args: [3], expected: null }, - { name: 'boo, true', args: [true], expected: null }, - { name: 'obj, null', args: [null], expected: null }, - { name: 'und, undefined', args: [undefined], expected: null }, + { name: 'num, 3', args: [3], expected: '3' }, + { name: 'boo, true', args: [true], expected: 'true' }, + { name: 'obj, null', args: [null], expected: 'null' }, + { name: 'und, undefined', args: [undefined], expected: 'undefined' }, // write at least 5 more test cases for the String function ]; String.quizzing = true; @@ -45,11 +45,11 @@ const NumberTests = [ { name: 'num, Infinity', args: [Infinity], expected: Infinity }, { name: 'num, NaN', args: [NaN], expected: NaN }, // true and false, the only boolean values - { name: 'boo, true', args: [true], expected: 0 }, - { name: 'boo, false', args: [false], expected: 1 }, + { name: 'boo, true', args: [true], expected: 1 }, + { name: 'boo, false', args: [false], expected: 0 }, // null & undefined - { name: 'obj, null', args: [null], expected: NaN }, - { name: 'und, undefined', args: [undefined], expected: 0 }, + { name: '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 @@ const BooleanTests = [ { name: 'boo, false', args: [false], expected: false }, // anything but 0 & NaN is cast to true { name: 'num, 3', args: [3], expected: true }, - { name: 'num, 0', args: [0], expected: true }, + { name: 'num, 0', args: [0], expected: false }, { name: 'num, 1e3', args: [1000], expected: true }, - { name: 'num, Infinity', args: [Infinity], expected: false }, + { name: 'num, Infinity', args: [Infinity], expected: true }, { name: 'num, NaN', args: [NaN], expected: false }, // null & undefined - { name: 'obj, null', args: [null], expected: true }, - { name: 'und, undefined', args: [undefined], expected: true }, + { name: 'obj, null', args: [null], expected: false }, + { name: 'und, undefined', args: [undefined], expected: false }, // anything but an empty string is cast to true - { name: 'str, undefined', args: ['undefined'], expected: false }, - { name: 'str, false', args: ['false'], expected: false }, + { name: 'str, undefined', args: ['undefined'], expected: true }, + { name: 'str, false', args: ['false'], expected: true }, { name: 'str, Infinity', args: ['Infinity'], expected: true }, { name: 'str, three', args: ['three'], expected: true }, - { name: 'str, ', args: [''], expected: true }, + { name: 'str, ', args: [''], expected: false }, { name: 'str, 3', args: ['3'], expected: true }, ]; Boolean.quizzing = true; diff --git a/module-exercises/functions.js b/module-exercises/functions.js index f22570a..b573bd4 100644 --- a/module-exercises/functions.js +++ b/module-exercises/functions.js @@ -174,14 +174,15 @@ 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"); + } evaluate(tracing1); @@ -194,11 +195,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 +218,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 +240,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 +261,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 +276,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 +296,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 +315,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; }; @@ -334,7 +335,7 @@ evaluate(tracing8); 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 +355,21 @@ evaluate(tracing9); function tracing10() { // do what needs to be done! - function f() { // <-- +function f(param3,param1,param2,param4) { // <-- var result = param3 + param1 + param2 + param4; return result; }; - let arg1 = "", arg2 = "", arg3 = "", arg4 = ""; // <-- + let arg1 = "x", arg2 = "y", arg3 = "z", 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 === "yzxw", "returnVal should be ?"); // <-- arg1 = "z", arg2 = "w", arg3 = "y", arg4 = "x"; - returnVal = f(); // <-- + returnVal = f(arg1,arg3,arg2,arg4); // <-- console.assert(returnVal === "zywx", "returnVal should be zywx"); } @@ -431,12 +432,12 @@ evaluate(example2_testCases, exampleTestCases); 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: [5,10], expected: 15}, // create your own test case! + { name: 'sixth', args: [-10,20], expected: 10 }, // create your own test case! ]; function functionToTest1(a, b) { const result = a + b; @@ -445,12 +446,12 @@ function functionToTest1(a, b) { 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: [/* what subtracts to be 5? */6,1], expected: 5 }, + { name: 'second', args: [/* what else subtracts to be 5? */8,3], 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: [100,30], expected: 70 }, // create your own test case! + { name: 'sixth', args: [4,2], expected: 2 }, // create your own test case! ]; function functionToTest2(a, b) { const result = a - b; @@ -461,12 +462,12 @@ evaluate(functionToTest2, writeTestCases2); 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: [/* what multiplies to be 5? */1,5], expected: 5 }, + { name: 'second', args: [/* what else multiplies to be 5? */5,1], 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: [4,5], expected: 20 }, // create your own test case! + { name: 'sixth', args: [3,7], expected: 21 }, // create your own test case! ]; function functionToTest3(a, b) { const result = a * b; @@ -477,12 +478,12 @@ evaluate(functionToTest3, writeTestCases3); 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: [/* what letters in what order will return "zyx"? */'y','x','z'], expected: 'zyx' }, + { name: 'second', args: [/* what letters in what order will return "yzx"? */'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: ['z','y','x'], expected: 'xzy' }, // create your own test case! + { name: 'sixth', args: ['x','z','y'], expected: 'yxz' }, // create your own test case! ]; function functionToTest4(a, b, c) { const result = c + a + b; @@ -493,12 +494,12 @@ evaluate(functionToTest4, writeTestCases4); 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: [/* what letters in what order will return "zyx"? */'x','z','y'], expected: 'zyx' }, + { name: 'second', args: [/* what letters in what order will return "yzx"? */'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: ['z','y','x'], expected: 'yxz' }, // create your own test case! + { name: 'sixth', args: ['y','x','z'], expected: 'xzy' }, // create your own test case! ]; function functionToTest5(a, b, c) { const result = b + c + a; diff --git a/module-exercises/index.html b/module-exercises/index.html index 2ef651b..b622a93 100644 --- a/module-exercises/index.html +++ b/module-exercises/index.html @@ -1,45 +1,42 @@ - + + + - - + understand javascript + - understand javascript - + + - - + + how to work with these exercises - - - how to work with these exercises - - - - - - - - - - - - - - - - - - - - - challenge exercises - - - + + + + + + + + + + + + + + + + + + challenge exercises + diff --git a/module-exercises/loops.js b/module-exercises/loops.js index 0d67c58..99e9079 100644 --- a/module-exercises/loops.js +++ b/module-exercises/loops.js @@ -103,12 +103,14 @@ function loopRefactor1() { while (i !== 8) { whileResult += i; i += 2; + } // 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; + } console.assert(forResult === whileResult, 'both loops should have the same behavior'); @@ -127,10 +129,10 @@ function loopRefactor2() { // fix the three pieces of this for loop to pass the assert let whileResult = 0; - null; - while (null) { + i=5; + while (i>-2) { whileResult = whileResult + i; - null; + i--; } console.assert(forResult === whileResult, 'both loops should have the same behavior'); diff --git a/module-exercises/primitive-operators.js b/module-exercises/primitive-operators.js index 53ad3c0..0ccfcfc 100644 --- a/module-exercises/primitive-operators.js +++ b/module-exercises/primitive-operators.js @@ -35,16 +35,16 @@ const plusTests = [ { name: 'number, boolean', args: [1, true], expected: 2 }, { name: 'number, null', args: [1, null], expected: 1 }, { name: 'number, undefined', args: [1, undefined], expected: NaN }, - { name: 'NaN, anything else', args: [NaN, 'anything else!'], expected: NaN }, + { name: 'NaN, "anything else"', args: [NaN, "anything else"], expected: 'NaNanything else'}, //the test code was shown in orange color, that is why I had to change it // fill in the rest of 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: 'string,number', args: ['akbel',29], expected: 'akbel29' }, + { name: 'string, NaN', args: ['name',NaN], expected: 'nameNaN' }, + { name: 'number,boolean', args: [30,false], expected: 30}, + { name: 'boolean,boolean', args: [true,false], expected: 1}, + { name: 'null,boolean', args: [null,true], expected: 1}, + { name: 'NaN,number', args: [NaN,20], expected: NaN }, + { name: 'undefined,number', args: [undefined,20], expected: NaN }, + { name: 'null,null', args: [null,null], expected: 0 }, ]; function plus(a, b) { return a + b; diff --git a/module-exercises/primitive-types.js b/module-exercises/primitive-types.js index 2ab5eb0..75da40b 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, 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: 'num, 1', args: [1], expected: 'number'}, + { name: 'num, 5', args: [5], expected: 'number' }, + { name: 'num, Nan', args: [NaN], expected: 'number' }, + { name: 'num, infinity', args: [Infinity], expected: 'number' }, + { name: 'num, 1.1', args: [1.1], expected: 'number' }, + { name: 'num, -2', args: [-2], expected: 'number' }, ] function allValuesHaveAType(value) { return typeof value; @@ -90,12 +90,12 @@ evaluate(allValuesHaveAType, typeofTests); // 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; @@ -105,7 +105,6 @@ typeofReturnsAString.quizzing = true; evaluate(typeofReturnsAString, typeofReturnsAStringTests); - function example_aBitAboutNaN() { // NaN is the only value that does not strictly equal itself @@ -125,16 +124,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: true }, + { name: 'ninth', args: [' ', ' '], expected: false }, ]; function strictEquality(a, b) { // if type OR value are not the same, returns false @@ -147,16 +146,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: false }, + { name: 'ninth', args: [' ', ' '], expected: true }, ]; function strictInequality(a, b) { // if type OR value are not the same, returns true diff --git a/module-exercises/truthiness-operators.js b/module-exercises/truthiness-operators.js index 086fa11..2fa8ebb 100644 --- a/module-exercises/truthiness-operators.js +++ b/module-exercises/truthiness-operators.js @@ -20,15 +20,19 @@ const orTests = [ { 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: '2, 2', args: [2, 2], expected: 2 }, + { name: '0, 2', args: [0, 2], expected: 2 }, + { name: 'NaN, "1"', args: [NaN, "1"], expected: "1" }, //I tried to [Nan, false], but I could not find a correct answer + { name: '1, NaN', args: [1, NaN], expected: 1 }, + { name: '1, "false"', args: [1, "false"], expected: 1}, + { name: '1, "true"', args: [1, "true"], expected: 1}, + { name: '"true","true"', args: ["true", "true"], expected: "true" }, + { name: '"false", "false"', args: ["false", "false"], expected: "false" }, ]; + +try { + + function or(a, b) { return a || b; } @@ -46,14 +50,14 @@ const andTests = [ { 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: 'true, 2', args: [true,2], expected: 2 }, + { name: '"true", null', args: ["true",null], expected: null}, //i tried "true" with 1 and 2 but I could not get a correct answer + { name: 'NaN, 1', args: [NaN, 1], expected: NaN}, + { name: 'NaN, "1"', args: [NaN, "1"], expected: NaN }, + { name: '"false",1', args: ["false",1], expected: 1 }, //i expect it to be false + { name: 'true,0', args: [true,0], expected: 0 }, + { name: '"true",0', args: ["true",0], expected: 0 }, + { name: '"false",0', args: ["false",0], expected: 0 }, ]; function and(a, b) { return a && b; @@ -69,15 +73,16 @@ const notTests = [ { 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: 'null', args: [null], expected: true }, + { name: '2', args: [2], expected: false }, + { name: 'true', args: [true], expected: false }, + { name: '"true"', args: ["true"], expected: false }, + { name: 'false', args: [false], expected: true}, + { name: '"false"', args: ["false"], expected: false }, // as I understand "false","true","astring" or whatever in a "" is a string.Doesn't matter what is written inside. + { name: '"aString"', args: ["aString"], expected: false }, + { name: '"numberZero"', args: ["numberZero"], expected: false}, ]; + function not(a) { return !a; } @@ -92,14 +97,14 @@ const ternaryTests = [ { 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,'true', 'false'], expected: 'true' }, + { name: 'undefined', args: ['undefined',1,2], expected: 1 }, + { name: 'null', args: [null,true,false], expected: false }, + { name: '0', args: ['0','yes','no'], expected: 'yes'}, + { name: 'wow', args: ['wow','ja','nee'], expected: 'ja'}, + { name: '"wow"', args: ['wow',1,2], expected: 1 }, + { name: 'NaN', args: ['NaN',1,2], expected: 1 }, + { name: '0', args: ['0',1,2], expected: 1 }, ]; function ternary(a, b, c) { return a ? b : c; @@ -107,7 +112,13 @@ function ternary(a, b, c) { ternary.quizzing = true; evaluate(ternary, ternaryTests); - +} +catch (err) { + console.log(err); + document.body.appendChild( + evaluate.errorSearchComponent('.js file', err) + ); +} { console.groupEnd(); document.body.appendChild(document.createElement('hr')); diff --git a/module-exercises/truthiness.js b/module-exercises/truthiness.js index 1ab700d..177d39f 100644 --- a/module-exercises/truthiness.js +++ b/module-exercises/truthiness.js @@ -8,6 +8,8 @@ console.groupCollapsed(pageTitle); } +try { + function example_truthinessIsCastingToBoolean() { const valuesToStudy = [ @@ -38,12 +40,12 @@ const truthinessTests = [ { 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: 'NaN', args: [NaN], expected: 'falsey' }, //i did not understand what to write here. i tried truthy cases but it did not accept my results as true. i could not find another falsey cases. + { name: '0', args: [0], expected: 'falsey' }, + { name: '""', args: [""], expected: 'falsey' }, + { name: '-0', args: [-0], expected: 'falsey' }, + { name: 'null', args: [null], expected: 'falsey' }, + { name: 'false', args: [false], expected: 'falsey' }, ]; function truthinessByTestCase(x) { const coercedToBool = Boolean(x); @@ -57,30 +59,37 @@ 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 }, + { 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); 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/module-exercises/variables.js b/module-exercises/variables.js index 0ed91de..325851c 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,11 @@ 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 +117,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 +136,13 @@ 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'"); @@ -141,6 +159,13 @@ function fiveVariableSwap() { // 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'"); @@ -190,7 +215,7 @@ function multipleAssignments1() { // 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'"); console.assert(c === "c", "c should store 'c'"); @@ -204,7 +229,7 @@ function multipleAssignments2() { // 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'"); console.assert(c === "c", "c should store 'c'"); @@ -217,7 +242,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'"); @@ -233,7 +258,7 @@ function multipleAssignments4() { // 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'"); console.assert(c === "y", "c should store 'y'"); @@ -270,6 +295,11 @@ function chainedAssignments1() { // can be done in 3 lines or less + temp=b; +b=a1; +a1=a2=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"'); @@ -286,6 +316,7 @@ function chainedAssignments2() { // can be done in 4 lines or less + temp=a,a=b1,b1=b2=c1,c1=c2=c3=temp; console.assert(a === "a", 'a should store "a"'); @@ -317,7 +348,7 @@ function footnote_var() { evaluate(footnote_var); -{ + console.groupEnd(); document.body.appendChild(document.createElement('hr')); -} + diff --git a/week-1-project/devowel-handler.js b/week-1-project/devowel-handler.js index c50d2d2..a96be7f 100644 --- a/week-1-project/devowel-handler.js +++ b/week-1-project/devowel-handler.js @@ -12,20 +12,29 @@ the handler is already set up to: */ function devowelHandler() { - // read and process user input (this works, no need to change it!) - const toDevowel = document.getElementById('devowel-input').value; + 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 wegvowels() { + const vowels = ["a", "e", "o",'ø', "i", "u", "ü"]; + return toDevowel + .split("") + .filter(function(wv) { + return vowels.indexOf(wv.toLowerCase()) == -1; + }) + .join(""); + } + const devoweled = wegvowels(); + // report result to user (this works, no need to change it!) - const outputField = document.getElementById('devowel-output'); + const outputField = document.getElementById("devowel-output"); outputField.innerHTML = devoweled; - console.log('\n--- devowelHandler ---'); - console.log('toDevowel:', typeof toDevowel, ',', toDevowel); - console.log('devoweled:', typeof devoweled, ',', devoweled); -}; -const devowelButton = document.getElementById('devowel-button'); -devowelButton.addEventListener('click', devowelHandler); + console.log("\n--- devowelHandler ---"); + console.log("toDevowel:", typeof toDevowel, ",", toDevowel); + console.log("devoweled:", typeof devoweled, ",", devoweled); +} +const devowelButton = document.getElementById("devowel-button"); +devowelButton.addEventListener("click", devowelHandler); diff --git a/week-1-project/README.md b/week-1-project/https:/akbelcolak.github.io/readme.md similarity index 100% rename from week-1-project/README.md rename to week-1-project/https:/akbelcolak.github.io/readme.md diff --git a/week-1-project/index.html b/week-1-project/index.html index 9397ef9..e784d39 100644 --- a/week-1-project/index.html +++ b/week-1-project/index.html @@ -1,55 +1,119 @@ - + - - - - - week 1 project - - - - - - - - -
-
-
-

-  
- - -
-
-
-

-  
- -
-
-
-

-  
- - -
-
-
-
-

-  
- - - - - - - - - - - - + + welcome to javascript Akbel + + + + + + + + + + +
+ +
+

TYPE AND SEE

+

+ Would you like to play a silly game and could not deside what it is? +
+ Then this site is for you, Type and Enjoy! +

+
+
+ + +
+ You can type anything you like in the box below. It will sort your entry + according to charCode. + +
+ +
+
+

+      
+
+ +
+ You can type anything you like in the box below. It will reverse your + entry. Try to read it aloud! +
+
+ +
+
+

+    
+ +
+ You can type anything you like in the box below. It will shrink your entry + by deleting all the wovels. Do you remember the times when there is no + internet in your phone and messages were so expensive. So that you had to + type without wovels and also understand what your friend has written to + you. If you don't remember or did not experience it, you should definetly + try it! +
+
+ +
+
+

+    
+ +
+ You can type anything you like in the box below. It is a version of + Parrot. Just repeats what you say. Then don't afraid to say it, I LOVE YOU + and I Believe You, You Can Do It! +
+ +
+ +
+ +
+
+

+    
+ + + + + + + + diff --git a/week-1-project/repeat-handler.js b/week-1-project/repeat-handler.js index d0c5d72..c5593eb 100644 --- a/week-1-project/repeat-handler.js +++ b/week-1-project/repeat-handler.js @@ -13,27 +13,27 @@ the handler is already set up to: */ function repeatHandler() { - // read and process user input (this works, no need to change it!) - const strToRepeat = document.getElementById('repeat-string-input').value; + const strToRepeat = document.getElementById("repeat-string-input").value; - const rawNumInput = document.getElementById('repeat-number-input').value; + const rawNumInput = document.getElementById("repeat-number-input").value; const numOfRepetitions = Number(rawNumInput); if (numOfRepetitions !== numOfRepetitions) { throw new TypeError('second input to "repeat it" must be a number'); } - // pass user input through core logic (write this! it doesn't work) - const repeated = `repeat ${strToRepeat} ${numOfRepetitions} times`; + + + const repeated = strToRepeat.repeat(numOfRepetitions); // report result to user (this works, no need to change it!) - const outputField = document.getElementById('repeat-output'); + const outputField = document.getElementById("repeat-output"); outputField.innerHTML = repeated; - console.log('\n--- repeatHandler ---'); - console.log('strToRepeat:', typeof strToRepeat, ',', strToRepeat); - console.log('repeated:', typeof repeated, ',', repeated); -}; -const repeatButton = document.getElementById('repeat-button'); -repeatButton.addEventListener('click', repeatHandler); + console.log("\n--- repeatHandler ---"); + console.log("strToRepeat:", typeof strToRepeat, ",", strToRepeat); + console.log("repeated:", typeof repeated, ",", repeated); +} +const repeatButton = document.getElementById("repeat-button"); +repeatButton.addEventListener("click", repeatHandler); diff --git a/week-1-project/reverse-handler.js b/week-1-project/reverse-handler.js index 6682c5f..6565647 100644 --- a/week-1-project/reverse-handler.js +++ b/week-1-project/reverse-handler.js @@ -17,9 +17,14 @@ function reverseHandler() { // read and process user input (this works, no need to change it!) const toReverse = document.getElementById('reverse-input').value; - // pass user input through core logic (write this! it doesn't work) - const reversed = `reverse ${toReverse}`; - + // pass user input through core logic (write this! it doesn't work) + +   function forReverse(){ +    return toReverse.split('').reverse().join(''); +    }; +    const reversed = forReverse() ; +   + // report result to user (this works, no need to change it!) const outputField = document.getElementById('reverse-output'); outputField.innerHTML = reversed; diff --git a/week-1-project/sort-handler.js b/week-1-project/sort-handler.js index e45575f..847eb79 100644 --- a/week-1-project/sort-handler.js +++ b/week-1-project/sort-handler.js @@ -1,14 +1,11 @@ /* - write a little javascript to: - take in the string 'toSort' - sort all of the characters by charCode number - and assign the new string to 'sorted' - the handler is already set up to: - read user input to the variable 'toSort' - write 'sorted' to the output - */ @@ -17,8 +14,12 @@ function sortHandler() { // read and process user input (this works, no need to change it!) const toSort = document.getElementById('sort-input').value; - // pass user input through core logic (write this! it doesn't work) - const sorted = `sort the charecters in ${toSort}`; +// pass user input through core logic (write this! it doesn't work) +   +  function sortArray() {  +  return toSort.split('').sort().join(''); +  } +  const sorted =sortArray(); // report result to user (this works, no need to change it!) const outputField = document.getElementById('sort-output'); @@ -29,4 +30,4 @@ function sortHandler() { console.log('sorted:', typeof sorted, ',', sorted); }; const sortButton = document.getElementById('sort-button'); -sortButton.addEventListener('click', sortHandler); +sortButton.addEventListener('click', sortHandler); \ No newline at end of file diff --git a/week-1-project/style.css b/week-1-project/style.css index e69de29..901237b 100644 --- a/week-1-project/style.css +++ b/week-1-project/style.css @@ -0,0 +1,96 @@ +body{ + font-family: 'Dosis', sans-serif; + background-color:#f2ad9f; + margin:0; + padding:0; + color:#323339; + text-align: center; + width: 80%; + } + + +header{ + text-align: center; + font: 30px; + margin: 20px; + padding-top:30px; + padding-bottom: 30px; + min-height:80px; + color: #6cbf84 + + } + .box { + max-width: 600px; + text-align: center; + margin: auto; + margin-top: 25px; + margin-bottom: 25px; + } + ul{ + margin:0; + padding:0; + } + + .colored {color: #f26968} + + header a{ + color:#dfe2d2; + text-decoration:none; + text-transform: uppercase; + font-size:12px; + + } + + header li{ + float:right; + padding: 0 10px 0 10px; + display: inline; + } + + button { + background-color: #6cbf84; + border: none; + height: 30px; + width: 400px; + color: #dfe2d2; + margin: 5px; + font-size: 18px; + } + + button:hover { + background-color: #323339; + } + + input { + color: #323339; + font-size: 14px; + } + + footer{ + padding:20px; + background-color:#dfe2d2; + color:#f2ad9f; + margin-top:20px; + text-align: center; + bottom: 0; + width: 100%; + position: fixed; + } + +#repeat-container { + margin-bottom: 100px; +} + + + @media (max-width: 680px) { + .box { + max-width: 400px; + text-align: center; + margin: auto; + margin-top: 10px; + padding: 10px; + } + + body { + font-size: 0.8em; + } \ No newline at end of file diff --git a/week-2-project/.DS_Store b/week-2-project/.DS_Store new file mode 100644 index 0000000..0c07ac5 Binary files /dev/null and b/week-2-project/.DS_Store differ diff --git a/week-2-project/index.html b/week-2-project/index.html index 8badc8c..f8653e8 100644 --- a/week-2-project/index.html +++ b/week-2-project/index.html @@ -5,54 +5,70 @@ - week 2 project + AKBEL-week 2 project - + +
+

HELLo from week two javascript project

+ +
-
-
-
-

-  
- - -
+ +



   
+

The function should give you 2 times of the letters, 3 times of the numbers, 4 times of the symbols and the space. +

-
+



   
+
+

The function should make every letters capital and ignore the symbols. Also the space should be '_'

+
- -
+




   
+
+

The function should shift the letters you typed according to the number you gave.

+
+ +
+ + + +
+

+  
+
+

Type a word, give a length (a number), choose a pattern or just leave it.
+ The function should translate the word you typed according to the length that you wanted.

+
+ + + - -
-
- - + - + \ No newline at end of file diff --git a/week-2-project/scripts/caesarize.js b/week-2-project/scripts/caesarize.js index 4eac053..f6d3b16 100644 --- a/week-2-project/scripts/caesarize.js +++ b/week-2-project/scripts/caesarize.js @@ -9,37 +9,73 @@ */ const caesarizeTests = [ - { name: 'first', args: ["aBcD", 3], expected: 'dEfG' }, - { name: 'second', args: ["aBcD", -3], expected: 'xYzA' }, - { name: 'third', args: ["heLLo worLd!", 0], expected: 'heLLo worLd!' }, - { 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: "first", args: ["aBcD", 3], expected: "dEfG" }, + { name: "second", args: ["aBcD", -3], expected: "xYzA" }, + { name: "third", args: ["heLLo worLd!", 0], expected: "heLLo worLd!" }, + { 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: "#@&&^M*(#" } ]; + function caesarize(str, shiftNum) { - // write me! + + //my array to split + let array = a.split(''); + + //my array for splitted strings + let NEWarray = array.map(x =>{ + + let letternumber = x.charcodeAt(); + + + //for the letters a-z + if (letternumber >= 97 && letternumber <= 122){ + + letternumber += shiftNum; + if (letternumber > 122) {letternumber -= 26;} + else if (letternumber < 97) {letternumber += 26;} + + myCode = String.fromCharCode(letternumber);} + + // for the letters A-Z + else if (letternumber <= 90 && letternumber >= 65){ + + letternumber += shiftNum; + if (letternumber > 90) {letternumber -= 26} + else if (letternumber < 65) {letternumber += 26} + + myCode = String.fromCharCode(letternumber);} + + // for special characters and numbers + else {myCode = x;} + return myCode; + + }); + + return NEWarray.join(''); } -evaluate(caesarize, caesarizeTests); -function caesarizeHandler() { +evaluate(caesarize, caesarizeTests); + +function caesarizeHandler() { // read and process user input (this works, no need to change it!) - const strToCaesarize = document.getElementById('caesarize-string-input').value; + const strToCaesarize = document.getElementById("caesarize-string-input") + .value; - const rawNumInput = document.getElementById('caesarize-number-input').value; + const rawNumInput = document.getElementById("caesarize-number-input").value; const shiftNumber = Number(rawNumInput); if (isNaN(shiftNumber)) { throw new TypeError('second input to "caesarize it" must be a number'); } - // pass user input through core logic (this works! no need to change it) const caesarized = caesarize(strToCaesarize); // report result to user (this works, no need to change it!) - const outputField = document.getElementById('caesarize-output'); + const outputField = document.getElementById("caesarize-output"); outputField.innerHTML = caesarized; console.log('\n--- caesarizeHandler ---'); @@ -48,4 +84,4 @@ function caesarizeHandler() { console.log('caesarized:', typeof caesarized, ',', caesarized); }; const caesarizeButton = document.getElementById('caesarize-button'); -caesarizeButton.addEventListener('click', caesarizeHandler); +caesarizeButton.addEventListener('click', caesarizeHandler); \ No newline at end of file diff --git a/week-2-project/scripts/class.js b/week-2-project/scripts/class.js new file mode 100644 index 0000000..f1cc188 --- /dev/null +++ b/week-2-project/scripts/class.js @@ -0,0 +1,21 @@ +function calculate(a,b,operation) { + switch (operation){ +case sum : return a+b +case subtraction : return a-b +default: return a*b + } +} + +function calculate(a,b,operation){ + + if(operation==="+"){return a+b} + else if (operation ==="-") { return a-b} + else if (operation ==="*") {return a*b} + else (operation ==="/"); {if(b===0) {return undefined} + else if (a===0) {return 0} + return a/b} + +} + +for(let index = 0; index< Array.length; index++) //zero to length of array + diff --git a/week-2-project/scripts/constantize.js b/week-2-project/scripts/constantize.js index 8beed0c..373751a 100644 --- a/week-2-project/scripts/constantize.js +++ b/week-2-project/scripts/constantize.js @@ -23,7 +23,62 @@ const constantizeTests = [ { name: 'sixth', args: ['ALREADY_A_CONSTANT'], expected: 'ALREADY_A_CONSTANT' }, ]; function constantize(str) { + + // write me! + +/* I could not write a funtcion. +I tried to understand the logic and the way a function builts +by looking at stackowerflof,khanacademy exercises and what did my friends wrote in slack and homework sheet for constantize. +I compared the codes, try to understand everything that is written and what are the differences,why and how. + +here are the ones I have looked. + +*** actually ibrahim used the same function that Luis sent by deleting only one () and adding an extra ; +I did not understand how his worked. when I tried it it did not worked. *** + +//luisk + +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('_') + } + +// ibrahim hw constantize + +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); diff --git a/week-2-project/scripts/leftpad.js b/week-2-project/scripts/leftpad.js new file mode 100644 index 0000000..9b4751b --- /dev/null +++ b/week-2-project/scripts/leftpad.js @@ -0,0 +1,107 @@ +/* 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(string, road, pattern) { + + const stringLength = string.length; + const patternLength = pattern.length; + + if (road === 0) {return '';} + if (stringLength === road) {return string;} + else if (road < stringLength) {return string.substring(0,road);} + + //if road will be longer then the string length, I have to arrange the pattern + + //desired patern + let patternString = ''; + + // how long will be the last pattern string + const LastPatternLength = road - stringLength; + + // to follow Luis + // even after reading Luis's code I could not able to write correctly the rest of the function by myself + // I have looked for module operator %, + // understand what it means but I could not use it in another case (tried in KhanAcademy) + // i need more examples for module operators and math.floor + + const howManyTimesPatternFits = Mat.floor(LastPatternLength / patternLength); + + for (let i = 1; i<= howManyTimesPatternFits; i += 1){ + patternString = patternString + pattern; + } + + // exp: string = 3 characters and pattern = 3 characters, desired length is 10. + // then I need to type 2 times of my pattern and 1 charachter from pattern, then write the string. + // the problem is how to chose this 1 charachter (will it be the end letter of the patern or begining letter) + const theRestPattern = LastPatternLength % patternLength; + + const karakterNeeded = pattern.substring(patternLength - theRestPattern); + + patternString = karakterNeeded + patternString; + + const LastPatternString = patternString + string; + + return LastPatternString; + + + } + 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.addEventListener('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/repeatChars.js b/week-2-project/scripts/repeatChars.js index d2209b6..4aab375 100644 --- a/week-2-project/scripts/repeatChars.js +++ b/week-2-project/scripts/repeatChars.js @@ -8,36 +8,230 @@ write a function that repeats the charecters in a string according to these rule */ const repeatCharsTests = [ - { name: 'first', args: ['abc'], expected: 'aabbcc' }, - { name: 'second', args: ['123'], expected: '111222333' }, - { name: 'third', args: ['%-*>'], expected: '%%%%----****>>>>' }, - { name: 'fourth', args: ['h3LL0 W@r!|)'], expected: 'hh333LLLL000 WW@@@@rr!!!!||||))))' }, - { name: 'fifth', args: ['{:-<*>-:}'], expected: '{{{{::::----<<<<****>>>>----::::}}}}' }, - { name: 'sixth', args: [''], expected: '' }, - { name: 'seventh', args: [' '], expected: ' ' }, + { name: "first", args: ["abc"], expected: "aabbcc" }, + { name: "second", args: ["123"], expected: "111222333" }, + { name: "third", args: ["%-*>"], expected: "%%%%----****>>>>" }, + { + name: "fourth", + args: ["h3LL0 W@r!|)"], + expected: "hh333LLLL000 WW@@@@rr!!!!||||))))" + }, + { + name: "fifth", + args: ["{:-<*>-:}"], + expected: "{{{{::::----<<<<****>>>>----::::}}}}" + }, + { name: "sixth", args: [""], expected: "" }, + { name: "seventh", args: [" "], expected: " " } ]; function repeatChars(str) { + +const myLettersArray = ['a','b','c'] +const strArray = str.split(''); + +const resultArray = strArray.map((element)=>{ + if (myLettersArray.indexOf(element) >0){ return element + element; + + } +}) + + // write this! + + + /* + + I could not write the funtcion. +I tried to understand the logic and the way a function builts +by looking at stackowerflof and what did my friends wrote in slack and homework sheet for repeat. +I compared the codes, try to understand everything that is written and what are the differences,why and how. + +//stackoverflow repeat + +var repeat = function(str, count) { + var array = []; + for(var i = 0; i < count;) + array[i++] = str; + return array.join(''); } -evaluate(repeatChars, repeatCharsTests); +//stackoverflow repeat 2 -function repeatCharsHandler() { +var repeatString = function(string, n) { + var result = '', i; + + for (i = 1; i <= n; i *= 2) { + if ((n & i) === i) { + result += string; + } + string = string + string; + } + + return result; +}; + + + //evan to masha repeat + +// more descriptive variable names +function repeatChars(stringInput){ + let result = ''; + let numOfRepeat; + //let numOfRepeat = 0; + for ( let i=0; i1) + // always use ===, not ==. this will avoid tricky bugs + ? 1 + : ((65 <= chCode && chCode<= 90)||(97 <= chCode && chCode<= 122)) + ? 2 + : (48 <= chCode && chCode<= 57) + ? 3 + : 4; + + result += stringInput[i].repeat(numOfRepeat); + } + + return result; + + } + + //repeat masha + function repeatChars(stringInput){ + let c = ``; + let b; + let numOfRepeat; + //let numOfRepeat = 0; + for ( let i=0; i1) ? 1: + ((65 <= b && b<= 90)||(97 <= b && b<= 122)) ? 2: + (48 <= b && b<= 57) ? 3: + 4; + + c += stringInput[i].repeat(numOfRepeat); + } + + return c; + + } +//repeat evan to mert +function repeatChars(str) { + var strArray = str.split(''); + strArray.forEach(function(str) { + var code=str.charCodeAt(); +​ + if (code<=90 && code>=65)||(code<=122 && code>=97); { + str= str + str; + } + else if (code<=57 && code>=48 ) { + str=str+str+str; + } + else { + str=str+str+str+str; + } + }); + return '?'; +}; + //repeat mustafa in the hw sheet + + function repeatChars(str) { + let newString = ""; + + const splittedStr = str.split(""); + + splittedStr.forEach(element => { + if (/[0-9]/.test(element)) { + // + newString = newString + element + element + element; + } else { + if (/[a-zA-Z]/.test(element)) { + newString = newString + element + element; + } else { + newString = newString + element + element + element + element; + } + } + }); + return newString; + } + +//repeat mustafa slack +repeatChars.js ....... function repeatChars(str) { + let count = str.split('').reduce(function(countMap, word) { + countMap[word] = ++countMap[word] || 1; + return countMap; + }, {}); + //Get the letters that were found, and filter out any that only appear once. + let repeat = Object.keys(count) + //.filter(function (key) { return (count[key] > 1); }) + // Then map it and create a string with the correct length, filled with that letter. + .map(function (key) { + return new Array(count[key] + 1).join(key); + }); + return repeat; + } + evaluate(repeatChars, repeatCharsTests); + +//ibrahim hw repeat + +function repeatChars(str) { + // write this! + var strArray = str.split(""); + var strReturn = ""; + strArray.forEach(function(str) { + var code = str.charCodeAt(); + if ((code <= 90 && code >= 65) || (code <= 122 && code >= 97)) { + str = str + str; + } else if (code <= 57 && code >= 48) { + str = str + str + str; + } else { + str = str + str + str + str; + } + + strReturn = strReturn + str; + }); + + return strReturn; + } + +//repeat mert + +function repeatChars(str) { + var code=str.charCodeAt(); + + if (code<=90 && code>=65)||(code<=122 && code>=97); { + str= str + str; + } + else if (code<=57 && code>=48 ) { + str=str+str+str; + } + else { + str=str+str+str+str; + } + }; + strArray.forEach(repeatChars); + +*/ +} +evaluate(repeatChars, repeatCharsTests); + +function repeatCharsHandler() { // read and process user input (this works, no need to change it!) - const stringInput = document.getElementById('repeatChars-input').value; + const stringInput = document.getElementById("repeatChars-input").value; // pass user input through core logic (this works! no need to change it) const repeatCharsed = repeatChars(stringInput); // report result to user (this works, no need to change it!) - const outputField = document.getElementById('repeatChars-output'); + const outputField = document.getElementById("repeatChars-output"); outputField.innerHTML = repeatCharsed; - console.log('\n--- repeatCharsHandler ---'); - console.log('stringInput:', typeof stringInput, ',', stringInput); - console.log('repeatCharsed:', typeof repeatCharsed, ',', repeatCharsed); -}; -const repeatCharsButton = document.getElementById('repeatChars-button'); -repeatCharsButton.addEventListener('click', repeatCharsHandler); + console.log("\n--- repeatCharsHandler ---"); + console.log("stringInput:", typeof stringInput, ",", stringInput); + console.log("repeatCharsed:", typeof repeatCharsed, ",", repeatCharsed); +} +const repeatCharsButton = document.getElementById("repeatChars-button"); +repeatCharsButton.addEventListener("click", repeatCharsHandler); diff --git a/week-2-project/style.css b/week-2-project/style.css index e69de29..606cd2d 100644 --- a/week-2-project/style.css +++ b/week-2-project/style.css @@ -0,0 +1,64 @@ +body{ + font-family: 'Dosis', sans-serif; + background-color:#03101b; + margin:0; + padding:0; + color:beige; + text-align: center; + width: 80%; + } + + +header{ + text-align: center; + font: 30px; + margin: 20px; + padding-top:30px; + padding-bottom: 30px; + min-height:80px; + color: beige; + + } + + .container { + max-width: 600px; + text-align: center; + margin: auto; + margin-top: 25px; + margin-bottom: 25px; + } + + button { + background-color: #eca50b; + border: none; + height: 30px; + width: 200px; + color: #1a1201; + margin: 5px; + font-size: 18px; + } + + button:hover { + background-color: #47e9f5; + } + + input { + color: black; + font-size: 14px; + } + + + + + @media (max-width: 680px) { + .box { + max-width: 400px; + text-align: center; + margin: auto; + margin-top: 10px; + padding: 10px; + } + + body { + font-size: 0.8em; + } \ No newline at end of file diff --git a/week-3-project/README.md b/week-3-project/README.md index 0fbaea2..c521024 100644 --- a/week-3-project/README.md +++ b/week-3-project/README.md @@ -3,3 +3,21 @@ your tasks in this week's project: * structure, style & responsivize the ```./index.html``` file the handlers all work as they are. nothing to change, but still good to study! + +## Week 3 Project + +This week's project introduces two key concepts: +1. __Encoding & Decoding__: The _encrypt_ and _decrypt_ user stories use the same function! One of the core concepts in web development and programming in general is transforming data from one format, to another, and back again. You've been doing this without knowing it! In last week's project you probably solved at least one of the challenges by converting your string to an array, solving the problem as an array, them converting back to a string. +1. __Problem Decomposition__: This is the skill of breaking larger problems into smaller one, solving the smaller problems, and recombining the small solutions into a complete solution. With the _scramble_ user story, we've helped you along by already breaking down the problem into smaller pieces that can be recombined to solve the larger one. Now it's up to you to solve them and recombine them! + + +--- + +| __a user can ...__ | _User Interface_ | _Handlers_ | _Core Logic_ | +| --- | --- | --- | --- | +| _... visit the page_ | (already done for you) | nothing! | nothing! | +| _know what this page is for_ | Structure the page (header, footer, sections, ...)
provide some explanation of what everything will do | (nothing!) | (nothing!) | +| _... encrypt a string_ | nothing | write the middle section | pass all tests for the ```caesarize``` function | +| _... decrypt a string_ | nothing | write the middle section | nothing, you already wrote ```caesarize```! | +| _... scramble a string_ | nothing | nothing | pass all tests for ```chunk```, ```sort-words``` and ```reverse-chunk```.
then use those functions to pass the ```scramble``` tests | +| _... have a pleasant user experience_ | write a stylish styling sheet
make sure everything is responsive | nothing | nothing | \ No newline at end of file diff --git a/week-3-project/handlers/decrypt.js b/week-3-project/handlers/decrypt.js index 5878ad6..6d2569c 100644 --- a/week-3-project/handlers/decrypt.js +++ b/week-3-project/handlers/decrypt.js @@ -1,21 +1,24 @@ function decryptHandler() { // read and process user input (this works, no need to change it!) - const strToDecrypt = document.getElementById('encrypted-string-output').value; + const encryptedArea = document.getElementById('encrypted-text-area'); + const strToDecrypt = encryptedArea.value; - const rawNumInput = document.getElementById('decryption-key-input').value; + const keyInput = document.getElementById('encryption-key-input'); + const rawNumInput = keyInput.value; const shiftNumber = Number(rawNumInput); if (isNaN(shiftNumber)) { throw new TypeError('decryption key must be a number'); } - // pass user input through core logic (this works! no need to change it) - const decrypted = caesarize(strToDecrypt); + // pass user input through core logic + const decrypted = 'write me!'; // report result to user (this works, no need to change it!) - const outputField = document.getElementById('decrypted-string-output'); - outputField.innerHTML = decrypted; + keyInput.value = ''; + const decryptedArea = document.getElementById('decrypted-text-area'); + decryptedArea.value = decrypted; console.log('\n--- decryptHandler ---'); console.log('strToDecrypt:', typeof strToDecrypt, ',', strToDecrypt); diff --git a/week-3-project/handlers/encrypt.js b/week-3-project/handlers/encrypt.js index b2e3325..af922bc 100644 --- a/week-3-project/handlers/encrypt.js +++ b/week-3-project/handlers/encrypt.js @@ -1,21 +1,23 @@ function encryptHandler() { // read and process user input (this works, no need to change it!) - const strToEncrypt = document.getElementById('unencrypted-string-input').value; + const encryptArea = document.getElementById('encrypted-text-area') + const strToEncrypt = encryptArea.value; - const rawNumInput = document.getElementById('encryption-key-input').value; + const keyInput = document.getElementById('encryption-key-input'); + const rawNumInput = keyInput.value; const shiftNumber = Number(rawNumInput); if (isNaN(shiftNumber)) { throw new TypeError('encryption key must be a number'); } - // pass user input through core logic (this works! no need to change it) - const encrypted = caesarize(strToEncrypt); + // pass user input through core logic + const encrypted = 'write me!'; // report result to user (this works, no need to change it!) - const outputField = document.getElementById('encrypted-string-output'); - outputField.innerHTML = encrypted; + keyInput.value = ''; + encryptArea.value = encrypted; console.log('\n--- encryptHandler ---'); console.log('strToEncrypt:', typeof strToEncrypt, ',', strToEncrypt); @@ -24,3 +26,4 @@ function encryptHandler() { }; const encryptButton = document.getElementById('encrypt-button'); encryptButton.addEventListener('click', encryptHandler); +© 2019 GitHub, Inc. \ No newline at end of file diff --git a/week-3-project/handlers/scramble.js b/week-3-project/handlers/scramble.js index f93a0cd..220b49e 100644 --- a/week-3-project/handlers/scramble.js +++ b/week-3-project/handlers/scramble.js @@ -4,7 +4,7 @@ function scrambleHandler() { const toScramble = document.getElementById('scramble-input').value; // pass user input through core logic (this works! no need to change it) - const scrambled = scramble(toScramble); + const scrambled = 'write me!'; // report result to user (this works, no need to change it!) const outputField = document.getElementById('scramble-output'); @@ -15,4 +15,4 @@ function scrambleHandler() { console.log('scrambled:', typeof scrambled, ',', scrambled); }; const scrambleButton = document.getElementById('scramble-button'); -scrambleButton.addEventListener('click', scrambleHandler); +scrambleButton.addEventListener('click', scrambleHandler); \ No newline at end of file diff --git a/week-3-project/index.html b/week-3-project/index.html index e039e38..9c16455 100644 --- a/week-3-project/index.html +++ b/week-3-project/index.html @@ -12,7 +12,7 @@ - + @@ -21,24 +21,22 @@
-
-
+

-

-     
+

-

+     
- +


-

+    
   
@@ -50,4 +48,4 @@ - + \ No newline at end of file