From f18c472d19c0eea29f8ae114391767ccd3b4beb8 Mon Sep 17 00:00:00 2001 From: Mert Demirok Date: Tue, 8 Oct 2019 17:02:26 +0200 Subject: [PATCH 01/38] variables exercises completed --- module-exercises/index.html | 6 ++-- module-exercises/variables.js | 52 +++++++++++++++++++++++++++++------ 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/module-exercises/index.html b/module-exercises/index.html index 2ef651b..fffbfe3 100644 --- a/module-exercises/index.html +++ b/module-exercises/index.html @@ -21,8 +21,8 @@ --> - - + + --> challenge exercises diff --git a/module-exercises/variables.js b/module-exercises/variables.js index 0ed91de..248ecae 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=c; + c=b; + b=a; + a=temp; console.assert(a === "a", "a should store 'a'"); console.assert(b === "b", "b should store 'b'"); @@ -108,7 +114,11 @@ function fourVariableSwap1() { let a = "d", b = "a", c = "b", d = "c"; let temp = ''; - + temp=a; + a=b; + b=c; + c=d; + d=temp; // can be done in 5 lines @@ -126,6 +136,12 @@ function fourVariableSwap2() { // can be done in 6 lines + temp=d; + d=a; + a=temp; + temp=c; + c=b; + b=temp; console.assert(a === "w", "a should store 'w'"); console.assert(b === "x", "b should store 'x'"); @@ -141,6 +157,12 @@ 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'"); @@ -189,7 +211,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 +225,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'"); @@ -218,7 +240,7 @@ function multipleAssignments3() { // 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'"); console.assert(c === "c", "c should store 'c'"); @@ -231,8 +253,15 @@ function multipleAssignments4() { let a = "z", b = "y", c = "x", d = "w"; let temp = ''; - // can be done in 1 line + temp=d; + d=a; + a=temp; + temp=c; + c=b; + b=temp; + // can be done in 6 lines + console.assert(a === "w", "a should store 'w'"); console.assert(b === "x", "b should store 'x'"); @@ -269,7 +298,9 @@ function chainedAssignments1() { let temp = ''; // can be done in 3 lines or less - + temp=a1=a2; + 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"'); @@ -286,7 +317,10 @@ 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"'); console.assert(b1 === "b", 'b1 should store "b"'); From 336389057cfc8fec7628af6f5fa60099c7162096 Mon Sep 17 00:00:00 2001 From: Mert Demirok Date: Tue, 8 Oct 2019 23:50:42 +0200 Subject: [PATCH 02/38] module exercise variable.js and functions.js files are updated --- module-exercises/functions.js | 42 +++++++++++++------------- module-exercises/index.html | 4 +-- module-exercises/variables.js | 56 ++++++++++++++++++----------------- 3 files changed, 52 insertions(+), 50 deletions(-) diff --git a/module-exercises/functions.js b/module-exercises/functions.js index f22570a..5201acb 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,15 +217,14 @@ 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"); - } evaluate(tracing3); @@ -239,11 +238,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 +259,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 +274,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 +294,7 @@ function tracing7() { // concatinate the params to pass the tests function f(param1, param2, param3) { - const result = null; + const result = param2+param3+param1; return result; }; @@ -314,8 +313,8 @@ evaluate(tracing7); function tracing8() { // arrange the parameters to pass the asserts - function f() { - var result = param2 + param1 + param3; + function f(param1,param2,param3) { + var result = param2 + param3 + param1;; return result; }; @@ -334,8 +333,8 @@ evaluate(tracing8); function tracing9() { // arrange the parameters to pass the asserts - function f() { - var result = param1 + param2 + param3; + function f(param1,param2,param3) { + var result = param3 + param1 + param2; return result; }; @@ -354,21 +353,21 @@ evaluate(tracing9); function tracing10() { // do what needs to be done! - function f() { // <-- + function f(param1,param2,param3,param4) { // <-- var result = param3 + param1 + param2 + param4; return result; }; - let arg1 = "", arg2 = "", arg3 = "", arg4 = ""; // <-- + let arg1 = "y", arg2 = "z", arg3 = "x", arg4 = "w"; // <-- let returnVal = f(arg1, arg2, arg3, arg4); console.assert(returnVal === "xyzw", "returnVal should be xyzw"); arg1 = "z", arg2 = "w", arg3 = "y", arg4 = "x"; returnVal = f(arg3, arg1, arg4, arg2); - console.assert(returnVal === "", "returnVal should be ?"); // <-- + console.assert(returnVal === "xyzw", "returnVal should be ?"); // <-- arg1 = "z", arg2 = "w", arg3 = "y", arg4 = "x"; - returnVal = f(); // <-- + returnVal = f(arg3,arg2,arg1,arg4); // <-- console.assert(returnVal === "zywx", "returnVal should be zywx"); } @@ -513,3 +512,4 @@ evaluate(functionToTest5, writeTestCases5); document.body.appendChild(document.createElement('hr')); } +//mert demirok \ No newline at end of file diff --git a/module-exercises/index.html b/module-exercises/index.html index fffbfe3..40145de 100644 --- a/module-exercises/index.html +++ b/module-exercises/index.html @@ -21,7 +21,7 @@ --> - + --> + --> challenge exercises diff --git a/module-exercises/variables.js b/module-exercises/variables.js index 248ecae..5a6adee 100644 --- a/module-exercises/variables.js +++ b/module-exercises/variables.js @@ -22,7 +22,7 @@ function example_declarationAndAssignment() { declaredLetWithoutAssignment = 'assigned after declaration'; // accessing a const/let variable before it is declared will error - declaredLetWithAssignment; // comment this line to remove the error! + // declaredLetWithAssignment; // comment this line to remove the error! // you will generally do both declaration and assignment at once // notice how this slot is only created when this line is reached? @@ -38,7 +38,7 @@ function example_declarationAndAssignment() { // const errorTime; // uncomment this line to throw error! // const variables cannot be reassigned later in the program - constantVariable = 'error time'; + // constantVariable = 'error time'; } evaluate(example_declarationAndAssignment); @@ -87,6 +87,7 @@ function threeVariableSwap1() { 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'"); @@ -99,10 +100,11 @@ function threeVariableSwap2() { let temp = ''; // can be done in 4 lines - temp=c; + temp=a; + a=c; c=b; - b=a; - a=temp; + b=temp; + console.assert(a === "a", "a should store 'a'"); console.assert(b === "b", "b should store 'b'"); @@ -114,12 +116,14 @@ function fourVariableSwap1() { let a = "d", b = "a", c = "b", d = "c"; let temp = ''; + + // can be done in 5 lines temp=a; a=b; b=c; c=d; d=temp; - // can be done in 5 lines + console.assert(a === "a", "a should store 'a'"); @@ -135,13 +139,13 @@ function fourVariableSwap2() { let temp = ''; // can be done in 6 lines + temp=a; + a=d; + d=temp; + temp=b; + b=c; + c=temp; - temp=d; - d=a; - a=temp; - temp=c; - c=b; - b=temp; console.assert(a === "w", "a should store 'w'"); console.assert(b === "x", "b should store 'x'"); @@ -156,7 +160,6 @@ function fiveVariableSwap() { let temp = ' '; // can be done in 6 lines - temp=a; a=e; e=temp; @@ -164,6 +167,7 @@ function fiveVariableSwap() { b=d; d=temp; + console.assert(a === "v", "a should store 'v'"); console.assert(b === "w", "b should store 'w'"); console.assert(c === "x", "c should store 'x'"); @@ -211,7 +215,8 @@ function multipleAssignments1() { let temp = ''; // can be done in 1 line -temp=a, a=b, b=c, c=temp; + temp = a, a = b, b = c, c = temp; + console.assert(a === "a", "a should store 'a'"); console.assert(b === "b", "b should store 'b'"); @@ -225,7 +230,8 @@ function multipleAssignments2() { let temp = ''; // can be done in 1 line - temp=a, a=c ,c=b, b=temp; + temp = a, a = c, c = b, b = temp; + console.assert(a === "a", "a should store 'a'"); console.assert(b === "b", "b should store 'b'"); @@ -239,8 +245,9 @@ function multipleAssignments3() { let temp = ''; // can be done in 1 line + temp=a, a=b, b=c, c=d, d=temp; + - 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'"); console.assert(c === "c", "c should store 'c'"); @@ -253,15 +260,9 @@ function multipleAssignments4() { let a = "z", b = "y", c = "x", d = "w"; let temp = ''; - temp=d; - d=a; - a=temp; - temp=c; - c=b; - b=temp; + // can be done in 1 line + temp=a, a=d, d=temp, temp=b, b=c, c=temp; - // can be done in 6 lines - console.assert(a === "w", "a should store 'w'"); console.assert(b === "x", "b should store 'x'"); @@ -298,9 +299,10 @@ function chainedAssignments1() { let temp = ''; // can be done in 3 lines or less - temp=a1=a2; + 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"'); @@ -318,8 +320,8 @@ function chainedAssignments2() { // can be done in 4 lines or less temp=a; -a=b1; -b1=b2=c1; +a=b1=b2; +b1=b2=c1=c2=c3; c1=c2=c3=temp; console.assert(a === "a", 'a should store "a"'); From a87caf201391ec48bed0886310aee0690c4678b8 Mon Sep 17 00:00:00 2001 From: Mert Demirok Date: Wed, 9 Oct 2019 10:24:50 +0200 Subject: [PATCH 03/38] style added --- week-1-project/index.html | 20 ++++++----- week-1-project/style.css | 70 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 8 deletions(-) diff --git a/week-1-project/index.html b/week-1-project/index.html index 9397ef9..9d44bfd 100644 --- a/week-1-project/index.html +++ b/week-1-project/index.html @@ -7,42 +7,46 @@ week 1 project - + +
-
+


   
-
+


   
-
+


   
-
-
+
+


   
- - +
+

Mert DEMIROK, Copyright © 2019

+
diff --git a/week-1-project/style.css b/week-1-project/style.css index e69de29..f11ccf8 100644 --- a/week-1-project/style.css +++ b/week-1-project/style.css @@ -0,0 +1,70 @@ +body { + background-color: beige; +} + +/*header*/ + +#header { + text-align: center; + margin-top: 50px; +} + + + +/* sort container */ +#sort-container { + background-color: brown; + display: flex; + flex-direction: column; + align-items: center; + margin-top: 50px; + padding: 5%; + + +} +#sort-input { + align-self: center; + +} + +#sort-button { + width: 10%; + +} +#sort-output { + width: 30%; + text-align: center; +} + +/* reverse container */ + +#reverse-container { + background-color: blueviolet; + display: flex; + flex-direction: column; + align-items: center; + margin-top: 50px; + padding: 5%; +} + +/* devowel-container */ + +#devowel-container { + background-color: blue; + display: flex; + flex-direction: column; + align-items: center; + margin-top: 50px; + padding: 5%; +} + +/* repeat-container */ + +#repeat-container { + background-color: crimson; + display: flex; + flex-direction: column; + align-items: center; + margin-top: 50px; + padding: 5%; +} From 3dd8716fcebb18880133ed7a8525c2c36ec30ff7 Mon Sep 17 00:00:00 2001 From: Mert Demirok Date: Wed, 9 Oct 2019 23:28:15 +0200 Subject: [PATCH 04/38] reversehandler code completed --- week-1-project/reverse-handler.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/week-1-project/reverse-handler.js b/week-1-project/reverse-handler.js index 6682c5f..78f1285 100644 --- a/week-1-project/reverse-handler.js +++ b/week-1-project/reverse-handler.js @@ -18,11 +18,18 @@ function reverseHandler() { const toReverse = document.getElementById('reverse-input').value; // pass user input through core logic (write this! it doesn't work) - const reversed = `reverse ${toReverse}`; - + + function reverseString (toReverse){ + let reversed=""; + for (i=toReverse.length-1;i>=0;i--){ + reversed+=toReverse[i]; + } + return reversed; + } + // report result to user (this works, no need to change it!) const outputField = document.getElementById('reverse-output'); - outputField.innerHTML = reversed; + outputField.innerHTML = reverseString (toReverse); console.log('\n--- reverseHandler ---'); console.log('toReverse:', typeof toReverse, ',', toReverse); From 5aca9bcb99dda40476674e8dc54b41806fdf160e Mon Sep 17 00:00:00 2001 From: Mert Demirok Date: Thu, 10 Oct 2019 00:55:28 +0200 Subject: [PATCH 05/38] style and html files are updated --- week-1-project/index.html | 2 +- week-1-project/style.css | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/week-1-project/index.html b/week-1-project/index.html index 9d44bfd..02158f6 100644 --- a/week-1-project/index.html +++ b/week-1-project/index.html @@ -14,7 +14,7 @@
diff --git a/week-1-project/style.css b/week-1-project/style.css index f11ccf8..02bc597 100644 --- a/week-1-project/style.css +++ b/week-1-project/style.css @@ -13,58 +13,67 @@ body { /* sort container */ #sort-container { - background-color: brown; + background-color: rgba(24, 134, 10, 0.164); display: flex; flex-direction: column; align-items: center; margin-top: 50px; padding: 5%; + border-radius: 10%; } #sort-input { align-self: center; + border-style: inset; + height: 30px; } #sort-button { - width: 10%; + width: 200px; + border-radius: 20%; + height: 30px; + border-style: double; } #sort-output { - width: 30%; + width: 200px; text-align: center; } /* reverse container */ #reverse-container { - background-color: blueviolet; + background-color: rgba(24, 134, 10, 0.164); display: flex; flex-direction: column; align-items: center; margin-top: 50px; padding: 5%; + border-radius: 10%; } /* devowel-container */ #devowel-container { - background-color: blue; + background-color: rgba(24, 134, 10, 0.164); display: flex; flex-direction: column; align-items: center; margin-top: 50px; padding: 5%; + border-radius: 10%; } /* repeat-container */ #repeat-container { - background-color: crimson; + background-color: rgba(24, 134, 10, 0.164); display: flex; flex-direction: column; align-items: center; margin-top: 50px; padding: 5%; + border-radius: 10%; } From d2ea248a11d707bb5f3c174f63f5e56061e0c79c Mon Sep 17 00:00:00 2001 From: Mert Demirok Date: Thu, 10 Oct 2019 01:11:12 +0200 Subject: [PATCH 06/38] repeat-handler.js file completed --- week-1-project/repeat-handler.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/week-1-project/repeat-handler.js b/week-1-project/repeat-handler.js index d0c5d72..0341e08 100644 --- a/week-1-project/repeat-handler.js +++ b/week-1-project/repeat-handler.js @@ -25,11 +25,20 @@ function repeatHandler() { // pass user input through core logic (write this! it doesn't work) - const repeated = `repeat ${strToRepeat} ${numOfRepetitions} times`; + // const repeated = `repeat ${strToRepeat} ${numOfRepetitions} times`; + + function repeat (numOfRepetitions){ + output=""; + for (i=1;i<=numOfRepetitions;i++){ + output=output+ " " +strToRepeat; + } + return output; +} + // report result to user (this works, no need to change it!) const outputField = document.getElementById('repeat-output'); - outputField.innerHTML = repeated; + outputField.innerHTML = repeat(numOfRepetitions); console.log('\n--- repeatHandler ---'); console.log('strToRepeat:', typeof strToRepeat, ',', strToRepeat); From 41671b8a4c219f68feb488f3b7aa710b3655e733 Mon Sep 17 00:00:00 2001 From: Mert Demirok Date: Thu, 10 Oct 2019 23:32:03 +0200 Subject: [PATCH 07/38] sorthandler.js code completed --- 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..e678ff6 100644 --- a/week-1-project/sort-handler.js +++ b/week-1-project/sort-handler.js @@ -18,7 +18,12 @@ function sortHandler() { 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}`; + function sortString(toSort){ + var arr = toSort.split(''); + var sorted = arr.sort(); + return sorted.join(''); + } + const sorted = sortString(toSort); // report result to user (this works, no need to change it!) const outputField = document.getElementById('sort-output'); From 5db407179bc6961f3899b3c97f5f746b041acf3d Mon Sep 17 00:00:00 2001 From: Mert Demirok Date: Thu, 10 Oct 2019 23:46:07 +0200 Subject: [PATCH 08/38] devowelhandler.js file codes are completed --- week-1-project/devowel-handler.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/week-1-project/devowel-handler.js b/week-1-project/devowel-handler.js index c50d2d2..21840fd 100644 --- a/week-1-project/devowel-handler.js +++ b/week-1-project/devowel-handler.js @@ -17,7 +17,14 @@ function devowelHandler() { 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 disemvowel(toDevowel) { + var vowels = ['a', 'e', 'i', 'o', 'u']; + return toDevowel.split('').filter(function(el) { + return vowels.indexOf(el.toLowerCase()) == -1; + }).join(''); + } + + const devoweled = disemvowel(toDevowel); // report result to user (this works, no need to change it!) const outputField = document.getElementById('devowel-output'); From 5872ecae2c53bc02fa6e5d69b78558f79ca23253 Mon Sep 17 00:00:00 2001 From: Mert Demirok Date: Fri, 11 Oct 2019 14:07:19 +0200 Subject: [PATCH 09/38] some style changes added to the index.html and style.css files --- week-1-project/index.html | 33 +++++++++++++++++--------- week-1-project/style.css | 50 +++++++++++++++++++++++++++------------ 2 files changed, 57 insertions(+), 26 deletions(-) diff --git a/week-1-project/index.html b/week-1-project/index.html index 02158f6..fda2ee6 100644 --- a/week-1-project/index.html +++ b/week-1-project/index.html @@ -15,36 +15,47 @@
-
-
+
+

+    

What Does This Function Do!

+

This JavaScript function sorts the characters of the + word you typed in accordance with their charCode numbers.

-
-
-
+
+

+    

What Does This Function Do!

+

This JavaScript function reverses the characters of the + word you typed.

-
-
+
+

+    

What Does This Function Do!

+

This JavaScript function takes the vowels out of the + word you typed.

-
-
-
+
+
+

+    

What Does This Function Do!

+

This JavaScript function repeats the words you typed as many as you want.

-
+

Mert DEMIROK, Copyright © 2019

diff --git a/week-1-project/style.css b/week-1-project/style.css index 02bc597..12bb4bf 100644 --- a/week-1-project/style.css +++ b/week-1-project/style.css @@ -1,5 +1,6 @@ body { background-color: beige; + font-family: cursive; } /*header*/ @@ -9,34 +10,30 @@ body { margin-top: 50px; } +#name_header { + background-color: darkgray; + padding: 5px; + border-radius: 10%; +} /* sort container */ #sort-container { - background-color: rgba(24, 134, 10, 0.164); + background-color: rgba(12, 51, 182, 0.164); display: flex; flex-direction: column; align-items: center; margin-top: 50px; padding: 5%; border-radius: 10%; - - } #sort-input { - align-self: center; - border-style: inset; - height: 30px; - + width: 200px; } - #sort-button { width: 200px; - border-radius: 20%; - height: 30px; - border-style: double; - } + #sort-output { width: 200px; text-align: center; @@ -53,11 +50,16 @@ body { padding: 5%; border-radius: 10%; } - +#reverse-input { + width: 200px; +} +#reverse-button { + width: 200px; +} /* devowel-container */ #devowel-container { - background-color: rgba(24, 134, 10, 0.164); + background-color: rgba(136, 134, 10, 0.164); display: flex; flex-direction: column; align-items: center; @@ -66,10 +68,17 @@ body { border-radius: 10%; } +#devowel-input { + width: 200px; +} +#devowel-button { + width: 200px; +} + /* repeat-container */ #repeat-container { - background-color: rgba(24, 134, 10, 0.164); + background-color: rgba(134, 10, 62, 0.164); display: flex; flex-direction: column; align-items: center; @@ -77,3 +86,14 @@ body { padding: 5%; border-radius: 10%; } + +#repeat-input { + width: 200px; +} +#repeat-button { + width: 200px; +} + +#footer{ + text-align: center; +} \ No newline at end of file From 02648ff952da7ba13b3ce003f5907626e6813587 Mon Sep 17 00:00:00 2001 From: Mert Demirok Date: Fri, 11 Oct 2019 20:53:19 +0200 Subject: [PATCH 10/38] font family changed --- .vscode/settings.json | 3 +++ week-1-project/style.css | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..6f3a291 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "liveServer.settings.port": 5501 +} \ No newline at end of file diff --git a/week-1-project/style.css b/week-1-project/style.css index 12bb4bf..0501e39 100644 --- a/week-1-project/style.css +++ b/week-1-project/style.css @@ -1,6 +1,8 @@ +@import url('https://fonts.googleapis.com/css?family=Roboto:400,400i,700&display=swap'); + body { background-color: beige; - font-family: cursive; + font-family: 'Roboto', sans-serif; } /*header*/ From 5ed6ebe73eec6235bee89526b6b75bddabc57837 Mon Sep 17 00:00:00 2001 From: Mert Demirok <55088530+Mert1980@users.noreply.github.com> Date: Fri, 11 Oct 2019 22:43:46 +0200 Subject: [PATCH 11/38] Update README.md --- module-exercises/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/module-exercises/README.md b/module-exercises/README.md index e7914e3..c6e99fa 100644 --- a/module-exercises/README.md +++ b/module-exercises/README.md @@ -1,5 +1,8 @@ ## Module Exercises +Please click the link below to see the my progress in Module Exercises; + + In this folder you'll find a lot of files and two folders: * __[how-to-do-exercises](./how-to-do-exercises)__: Check out this folder for a guide to completing these exercises. Completing these exercises isn't as easy as following FreeCodeCamp or CodeAcademy, but you will learn a whole lot more! You will have an immersive experience working in the Developer Tools. And will be able to study any snippet or function you want instead of being limited to the exercises provided. Taking a look at how ```evaluate``` works before diving into the exercises will make the transition a bit smoother. From 23070479d60ceb5a89ebbe20af82a940591145de Mon Sep 17 00:00:00 2001 From: Mert Demirok <55088530+Mert1980@users.noreply.github.com> Date: Fri, 11 Oct 2019 22:45:38 +0200 Subject: [PATCH 12/38] Update README.md --- module-exercises/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/module-exercises/README.md b/module-exercises/README.md index c6e99fa..0efef3a 100644 --- a/module-exercises/README.md +++ b/module-exercises/README.md @@ -1,6 +1,8 @@ ## Module Exercises -Please click the link below to see the my progress in Module Exercises; +## Please click the link below to see the my progress in Module Exercises; + +Replicated DuckDuckGo Website Using Branches From 2934250ac7dcdf9053bfc68a0a269cca51ba5bb3 Mon Sep 17 00:00:00 2001 From: Mert Demirok <55088530+Mert1980@users.noreply.github.com> Date: Fri, 11 Oct 2019 22:47:15 +0200 Subject: [PATCH 13/38] Update README.md --- module-exercises/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/module-exercises/README.md b/module-exercises/README.md index 0efef3a..3319bba 100644 --- a/module-exercises/README.md +++ b/module-exercises/README.md @@ -2,8 +2,9 @@ ## Please click the link below to see the my progress in Module Exercises; -Replicated DuckDuckGo Website Using Branches +Module Exercises +https://github.com/Mert1980/javascript-1/blob/master/module-exercises/index.html In this folder you'll find a lot of files and two folders: From bfc5b3950b2b487b44b7c06d3e745bd26cbaffc5 Mon Sep 17 00:00:00 2001 From: Mert Demirok <55088530+Mert1980@users.noreply.github.com> Date: Fri, 11 Oct 2019 23:12:23 +0200 Subject: [PATCH 14/38] Update README.md --- module-exercises/README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/module-exercises/README.md b/module-exercises/README.md index 3319bba..edecc0e 100644 --- a/module-exercises/README.md +++ b/module-exercises/README.md @@ -2,10 +2,7 @@ ## Please click the link below to see the my progress in Module Exercises; -Module Exercises - -https://github.com/Mert1980/javascript-1/blob/master/module-exercises/index.html - +Module Exercises In this folder you'll find a lot of files and two folders: * __[how-to-do-exercises](./how-to-do-exercises)__: Check out this folder for a guide to completing these exercises. Completing these exercises isn't as easy as following FreeCodeCamp or CodeAcademy, but you will learn a whole lot more! You will have an immersive experience working in the Developer Tools. And will be able to study any snippet or function you want instead of being limited to the exercises provided. Taking a look at how ```evaluate``` works before diving into the exercises will make the transition a bit smoother. From 4c1ce72a6706405312f9ce006eefc901dfe4eaa6 Mon Sep 17 00:00:00 2001 From: Mert Demirok <55088530+Mert1980@users.noreply.github.com> Date: Fri, 11 Oct 2019 23:12:49 +0200 Subject: [PATCH 15/38] Update README.md --- module-exercises/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module-exercises/README.md b/module-exercises/README.md index edecc0e..c26fb61 100644 --- a/module-exercises/README.md +++ b/module-exercises/README.md @@ -1,6 +1,6 @@ ## Module Exercises -## Please click the link below to see the my progress in Module Exercises; +# Please click the link below to see the my progress in Module Exercises; Module Exercises From c06c7e016bbdd97cd6ba68c4dc4f312c3ce1d98b Mon Sep 17 00:00:00 2001 From: Mert Demirok <55088530+Mert1980@users.noreply.github.com> Date: Fri, 11 Oct 2019 23:13:05 +0200 Subject: [PATCH 16/38] Update README.md --- module-exercises/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module-exercises/README.md b/module-exercises/README.md index c26fb61..4e1c8c0 100644 --- a/module-exercises/README.md +++ b/module-exercises/README.md @@ -1,6 +1,6 @@ ## Module Exercises -# Please click the link below to see the my progress in Module Exercises; +### Please click the link below to see the my progress in Module Exercises; Module Exercises From ff4d86bafc1852c615a449b85eba2e827463110f Mon Sep 17 00:00:00 2001 From: Mert Demirok <55088530+Mert1980@users.noreply.github.com> Date: Fri, 11 Oct 2019 23:13:40 +0200 Subject: [PATCH 17/38] Update README.md --- module-exercises/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module-exercises/README.md b/module-exercises/README.md index 4e1c8c0..8556828 100644 --- a/module-exercises/README.md +++ b/module-exercises/README.md @@ -2,7 +2,7 @@ ### Please click the link below to see the my progress in Module Exercises; -Module Exercises +Module Exercises_Mert In this folder you'll find a lot of files and two folders: * __[how-to-do-exercises](./how-to-do-exercises)__: Check out this folder for a guide to completing these exercises. Completing these exercises isn't as easy as following FreeCodeCamp or CodeAcademy, but you will learn a whole lot more! You will have an immersive experience working in the Developer Tools. And will be able to study any snippet or function you want instead of being limited to the exercises provided. Taking a look at how ```evaluate``` works before diving into the exercises will make the transition a bit smoother. From eb2f8d0a8c3625129fee176623a030ce328ee2fd Mon Sep 17 00:00:00 2001 From: Mert Demirok Date: Sat, 12 Oct 2019 20:40:20 +0200 Subject: [PATCH 18/38] function module exercises completed --- module-exercises/functions.js | 61 +++++++++++++++++------------------ 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/module-exercises/functions.js b/module-exercises/functions.js index 5201acb..20e9046 100644 --- a/module-exercises/functions.js +++ b/module-exercises/functions.js @@ -430,12 +430,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: [1,4], 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: [4,6], expected: 10 }, // create your own test case! + { name: 'sixth', args: [20,30], expected: 50 }, // create your own test case! ]; function functionToTest1(a, b) { const result = a + b; @@ -444,12 +444,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: [7,2], expected: 5 }, + { name: 'second', args: [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: [10,3], expected: 7 }, // create your own test case! + { name: 'sixth', args: [6,2], expected: 4 }, // create your own test case! ]; function functionToTest2(a, b) { const result = a - b; @@ -460,12 +460,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: [1,5], expected: 5 }, + { name: 'second', args: [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: [5,5], expected: 25 }, // create your own test case! + { name: 'sixth', args: [3,5], expected: 15 }, // create your own test case! ]; function functionToTest3(a, b) { const result = a * b; @@ -476,12 +476,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: [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: ['z','y','x'], expected: 'xzy' }, // create your own test case! + { name: 'sixth', args: ['y','x','z'], expected: 'z,y,x' }, // create your own test case! ]; function functionToTest4(a, b, c) { const result = c + a + b; @@ -492,12 +492,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: [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: [z,y,x], expected: 'yxz' }, // create your own test case! + { name: 'sixth', args: [y,x,z], expected: 'x,z,y' }, // create your own test case! ]; function functionToTest5(a, b, c) { const result = b + c + a; @@ -512,4 +512,3 @@ evaluate(functionToTest5, writeTestCases5); document.body.appendChild(document.createElement('hr')); } -//mert demirok \ No newline at end of file From eef7c2d33f72a7c5a0db42242e1716b1160699f2 Mon Sep 17 00:00:00 2001 From: Mert Demirok Date: Sun, 13 Oct 2019 19:33:02 +0200 Subject: [PATCH 19/38] explicit coersion, primitive types and truthiness exercises completed --- module-exercises/explicit-coercion.js | 38 ++++++++------- module-exercises/functions.js | 14 +++--- module-exercises/index.html | 6 +-- module-exercises/primitive-types.js | 70 ++++++++++++++------------- module-exercises/truthiness.js | 50 +++++++++---------- 5 files changed, 91 insertions(+), 87 deletions(-) diff --git a/module-exercises/explicit-coercion.js b/module-exercises/explicit-coercion.js index d6bcfd4..71776c8 100644 --- a/module-exercises/explicit-coercion.js +++ b/module-exercises/explicit-coercion.js @@ -10,8 +10,10 @@ // it is possible to convert values from one type to another -// there are some understandable and learnable (but not always logical) rules to how this happens -// learning explicit type conversions will make many of the tricky bits of JS quite a bit less tricky +// there are some understandable and learnable (but not always logical) rules to +// how this happens +// learning explicit type conversions will make many of the tricky bits of JS quite +// a bit less tricky // write some passing test cases // or fix the existing ones! @@ -23,12 +25,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 +47,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 +70,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 20e9046..4eb475a 100644 --- a/module-exercises/functions.js +++ b/module-exercises/functions.js @@ -476,12 +476,12 @@ evaluate(functionToTest3, writeTestCases3); const writeTestCases4 = [ - { name: 'first', args: [y,x,z], expected: 'zyx' }, - { name: 'second', args: [z,x,y], expected: 'yzx' }, + { 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: ['z','y','x'], expected: 'xzy' }, // create your own test case! - { name: 'sixth', args: ['y','x','z'], expected: 'z,y,x' }, // create your own test case! + { name: 'sixth', args: ['y','x','z'], expected: 'zyx' }, // create your own test case! ]; function functionToTest4(a, b, c) { const result = c + a + b; @@ -492,12 +492,12 @@ evaluate(functionToTest4, writeTestCases4); const writeTestCases5 = [ - { name: 'first', args: [x,z,y], expected: 'zyx' }, - { name: 'second', args: [x,y,z], expected: 'yzx' }, + { 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: [z,y,x], expected: 'yxz' }, // create your own test case! - { name: 'sixth', args: [y,x,z], expected: 'x,z,y' }, // create your own test case! + { 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 40145de..0cfa5d4 100644 --- a/module-exercises/index.html +++ b/module-exercises/index.html @@ -22,11 +22,11 @@ - + --> --> challenge exercises diff --git a/module-exercises/primitive-types.js b/module-exercises/primitive-types.js index 2ab5eb0..f529126 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: [5], expected: 'number' }, + { name: '', args: [NaN], expected: 'number' }, + { name: '', args: [6], expected: 'number' }, + { name: '', args: [5.7], expected: 'number' }, + { name: '', args: [788], expected: 'number' }, + { name: '', args: [Infinity], expected: 'number' }, ] function allValuesHaveAType(value) { return typeof value; @@ -98,9 +98,11 @@ const typeofReturnsAStringTests = [ { name: 'num, 4', args: [4], expected: 'number' }, ]; function typeofReturnsAString(value) { - const typeofValue = typeof value; - return typeof typeofValue; + // const typeofValue = typeof value; + // return typeof typeofValue; + return typeof value } + typeofReturnsAString.quizzing = true; evaluate(typeofReturnsAString, typeofReturnsAStringTests); @@ -125,16 +127,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 +149,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.js b/module-exercises/truthiness.js index 1ab700d..700d06d 100644 --- a/module-exercises/truthiness.js +++ b/module-exercises/truthiness.js @@ -38,12 +38,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: '', args: [1], expected: 'truey' }, + { name: '', args: [0], expected: 'falsey' }, + { name: '', args: ['1'], expected: 'truey' }, + { name: '', args: [''], expected: 'falsey' }, + { name: '', args: [' '], expected: 'truey' }, + { name: '', args: [NaN], expected: 'falsey'}, ]; function truthinessByTestCase(x) { const coercedToBool = Boolean(x); @@ -57,25 +57,25 @@ 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); From de019831c76b7a692c836fed10a6f96618bdba36 Mon Sep 17 00:00:00 2001 From: Mert Demirok Date: Tue, 15 Oct 2019 13:55:36 +0200 Subject: [PATCH 20/38] first truthiness operators exercise completed --- module-exercises/truthiness-operators.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/module-exercises/truthiness-operators.js b/module-exercises/truthiness-operators.js index 086fa11..ccc468a 100644 --- a/module-exercises/truthiness-operators.js +++ b/module-exercises/truthiness-operators.js @@ -20,14 +20,14 @@ 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: '5,0', args: [5,0], expected: 5 }, + { name: '1,0', args: [1,0], expected: 1 }, + { name: '0,-10', args: [0,-10], expected: -10 }, + { name: '"Infinite", NaN', args: ['Infinite', NaN], expected: 'Infinite' }, + { name: '1,1', args: [1,1], expected: 1 }, + { name: '0,1', args: [0,1], expected: 1 }, + { name: '"Infinite",0', args: ["Infinite",0], expected: 'Infinite' }, + { name: '"null",1', args: ["null",1], expected: 'null' }, ]; function or(a, b) { return a || b; From 9cbaf0cd37725bd9ae0d092aad766bbd0527a32a Mon Sep 17 00:00:00 2001 From: Mert Demirok Date: Tue, 15 Oct 2019 14:07:28 +0200 Subject: [PATCH 21/38] files updated due to the amendment in project --- week-2-project/README.md | 1205 ++++++++++++++++++++++- week-2-project/index.html | 1432 ++++++++++++++++++++++++++- week-2-project/scripts/leftpad.js | 1451 ++++++++++++++++++++++++++++ week-2-project/scripts/scramble.js | 47 - 4 files changed, 4052 insertions(+), 83 deletions(-) create mode 100644 week-2-project/scripts/leftpad.js delete mode 100644 week-2-project/scripts/scramble.js diff --git a/week-2-project/README.md b/week-2-project/README.md index a36d142..6d54e0d 100644 --- a/week-2-project/README.md +++ b/week-2-project/README.md @@ -1,3 +1,1202 @@ -In this week's project you have two goals: -1. Write some JavaScript to complete each handler function. We have already set up the handlers to read user input from from the DOM and write your result to the DOM, the handlers also already are conn -1. Make a better UI than the one we gave you: practice HTML5 semantic structuring, correct CSS & responsive design + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + javascript-1/README.md at master · be-hacking-hyf/javascript-1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Skip to content + + + + + + + + + + + + + +
+ +
+ + +
+ +
+ + + +
+
+
+ + + + + + + + + + + + + + + + +
+
+ +
    + + + + +
  • + +
    + +
    + + + Watch + + +
    + Notifications +
    +
    + + + + + + + +
    +
    +
    + +
    +
  • + +
  • +
    +
    + + +
    +
    + + +
    + +
  • + +
  • +
    +
    + +
  • +
+ +

+ + /javascript-1 + + +

+ +
+ + + + + + +
+
+
+ + + + + + + + + Permalink + + + + +
+ + +
+ + Branch: + master + + + + + + + +
+ +
+ + Find file + + + Copy path + +
+
+ + +
+ + Find file + + + Copy path + +
+
+ + + + +
+ + +
+
+ + 1 contributor + + +
+ +

+ Users who have contributed to this file +

+
+ +
+
+
+
+ + + + + +
+ +
+
+ + 16 lines (11 sloc) + + 1.07 KB +
+ +
+ +
+ Raw + Blame + History +
+ + +
+ +
+ +
+
+ +
+
+
+ + + + + +
+

Week 2 Project

+
+

The user stories are not listed in the same order here as they are in the index.html. This page lists them in order of difficulty to help you build up your skillzz over the week

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
a user can ...User InterfaceHandlersCore Logic
... visit the page(already done for you)nothing!nothing!
know what this page is forStructure the page (header, footer, sections, ...)
provide some explanation of what everything will do
(nothing!)(nothing!)
... constantize a stringnothingnothingpass all tests for the constantize function
... caesarize a stringnothingnothingpass all tests for the caesarize function
... repeat the characters in a stringnothingnothingpass all tests for the repeatChars function
... leftpad a stringnothingnothingpass all tests for the leftpad function
... have a pleasant user experiencewrite a stylish styling sheet
make sure everything is responsive
nothingnothing
+
+
+ +
+ + + +
+ + +
+ + +
+
+ + + +
+
+ +
+
+ + +
+ + + + + + +
+ + + You can’t perform that action at this time. +
+ + + + + + + + + + + + + + +
+ + + + diff --git a/week-2-project/index.html b/week-2-project/index.html index 8badc8c..0464357 100644 --- a/week-2-project/index.html +++ b/week-2-project/index.html @@ -1,58 +1,1424 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + javascript-1/index.html at master · be-hacking-hyf/javascript-1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Skip to content + + + + + + + + + + + + + +
+ +
+ + +
+ +
+ + + +
+
+
+ + + + + + + + + + + + + + + + +
+
+ +
    + + + + +
  • + +
    + +
    + + + Watch + + +
    + Notifications +
    +
    + + + + + + + +
    +
    +
    + +
    +
  • + +
  • +
    +
    + + +
    +
    + + +
    + +
  • + +
  • +
    +
    + +
  • +
+ +

+ + /javascript-1 + + +

+ +
+ + + + + +
+
+
+ + + + + + + + Permalink + + + + +
+ + +
+ + Branch: + master + + + + + + + +
+ +
+ + Find file + + + Copy path + +
+
+ + +
+ + Find file + + + Copy path + +
+
+ + + + +
+ + +
+
+ + 1 contributor + + +
+ +

+ Users who have contributed to this file +

+
+ +
+
+
+
+ + + + + +
+ +
+
+ + 60 lines (41 sloc) + + 1.57 KB +
+ +
+ +
+ Raw + Blame + History +
+ + +
+ +
+ +
+
+ +
+
+
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
<!doctype html>
+
<html lang="en">
+
<head>
<meta charset="utf-8">
+
<title>week 2 project</title>
<meta name="description" content="week 2 project">
+
<script src="../evaluate.js"></script>
</head>
+
<body>
+
+
+
<div id='repeatChars-container'>
<input id='repeatChars-input' placeholder='characters to repeatChars' /> <br>
<button id='repeatChars-button'>repeatChars it</button> <br>
<pre id='repeatChars-output'></pre>
</div>
+
<div id='constantize-container'>
<input id='constantize-input' placeholder='string to constantize' /> <br>
<button id='constantize-button'>constantize it</button> <br>
<pre id='constantize-output'></pre>
</div>
+
+
<div id='caesarize-container'>
<textarea id='caesarize-string-input' rows="15" cols="30"></textarea> <br>
<input id='caesarize-number-input' placeholder='encryption key (number)' /> <br>
<button id='caesarize-button'>caesarize it</button> <br>
<pre id='caesarize-output'></pre>
</div>
+
<div id='leftpad-container'>
<input id='leftpad-str-input' placeholder='string to pad' />
<input id='leftpad-len-input' placeholder='target length' />
<input id='leftpad-pad-input' placeholder='pad string' />
<button id='leftpad-button'>leftpad it</button> <br>
<pre id='leftpad-output'></pre>
</div>
+
+
<!-- get rid of these hr's, this type of thing should be done with CSS -->
<hr>
<hr>
+
+
<script src="scripts/repeatChars.js"></script>
<script src="scripts/constantize.js"></script>
<script src="scripts/caesarize.js"></script>
<script src="scripts/leftpad.js"></script>
+
</body>
+
</html>
+ + -
-
-
-
-

   
+
+ + +
+ + +
+ + +
+
- -
-
- - - - +
+
+ +
+
+ - +
+ + + + + +
+ + + You can’t perform that action at this time. +
+ + + + + + + + + + + + + + +
+ + + diff --git a/week-2-project/scripts/leftpad.js b/week-2-project/scripts/leftpad.js new file mode 100644 index 0000000..f4ffd52 --- /dev/null +++ b/week-2-project/scripts/leftpad.js @@ -0,0 +1,1451 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + javascript-1/leftpad.js at master · be-hacking-hyf/javascript-1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Skip to content + + + + + + + + + + + + + +
+ +
+ + +
+ +
+ + + +
+
+
+ + + + + + + + + + + + + + + + +
+
+ +
    + + + + +
  • + +
    + +
    + + + Watch + + +
    + Notifications +
    +
    + + + + + + + +
    +
    +
    + +
    +
  • + +
  • +
    +
    + + +
    +
    + + +
    + +
  • + +
  • +
    +
    + +
  • +
+ +

+ + /javascript-1 + + +

+ +
+ + + + + + +
+
+
+ + + + + + + + + Permalink + + + + +
+ + +
+ + Branch: + master + + + + + + + +
+ +
+ + Find file + + + Copy path + +
+
+ + +
+ + Find file + + + Copy path + +
+
+ + + + +
+
+ + @colevandersWands + colevandersWands + + leftpad-links + + + + 7c89535 + Oct 13, 2019 + +
+ +
+
+ + 1 contributor + + +
+ +

+ Users who have contributed to this file +

+
+ +
+
+
+
+ + + + + +
+ +
+
+ + 69 lines (56 sloc) + + 2.98 KB +
+ +
+ +
+ Raw + Blame + History +
+ + +
+ +
+ +
+
+ +
+
+
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
/* 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/
+ + + +
+ +
+ + + +
+ + +
+ + +
+
+ + + +
+
+ +
+
+ + +
+ + + + + + +
+ + + You can’t perform that action at this time. +
+ + + + + + + + + + + + + + +
+ + + + 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 b0f9a24b880c29b7dfcd2c83d8944579557566c1 Mon Sep 17 00:00:00 2001 From: Mert Demirok <55088530+Mert1980@users.noreply.github.com> Date: Tue, 15 Oct 2019 14:14:04 +0200 Subject: [PATCH 22/38] Update README.md --- week-2-project/README.md | 1215 +------------------------------------- 1 file changed, 13 insertions(+), 1202 deletions(-) diff --git a/week-2-project/README.md b/week-2-project/README.md index 6d54e0d..fd163d2 100644 --- a/week-2-project/README.md +++ b/week-2-project/README.md @@ -1,1202 +1,13 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - javascript-1/README.md at master · be-hacking-hyf/javascript-1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Skip to content - - - - - - - - - - - - - -
- -
- - -
- -
- - - -
-
-
- - - - - - - - - - - - - - - - -
-
- -
    - - - - -
  • - -
    - -
    - - - Watch - - -
    - Notifications -
    -
    - - - - - - - -
    -
    -
    - -
    -
  • - -
  • -
    -
    - - -
    -
    - - -
    - -
  • - -
  • -
    -
    - -
  • -
- -

- - /javascript-1 - - -

- -
- - - - - - -
-
-
- - - - - - - - - Permalink - - - - -
- - -
- - Branch: - master - - - - - - - -
- -
- - Find file - - - Copy path - -
-
- - -
- - Find file - - - Copy path - -
-
- - - - -
- - -
-
- - 1 contributor - - -
- -

- Users who have contributed to this file -

-
- -
-
-
-
- - - - - -
- -
-
- - 16 lines (11 sloc) - - 1.07 KB -
- -
- -
- Raw - Blame - History -
- - -
- -
- -
-
- -
-
-
- - - - - -
-

Week 2 Project

-
-

The user stories are not listed in the same order here as they are in the index.html. This page lists them in order of difficulty to help you build up your skillzz over the week

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
a user can ...User InterfaceHandlersCore Logic
... visit the page(already done for you)nothing!nothing!
know what this page is forStructure the page (header, footer, sections, ...)
provide some explanation of what everything will do
(nothing!)(nothing!)
... constantize a stringnothingnothingpass all tests for the constantize function
... caesarize a stringnothingnothingpass all tests for the caesarize function
... repeat the characters in a stringnothingnothingpass all tests for the repeatChars function
... leftpad a stringnothingnothingpass all tests for the leftpad function
... have a pleasant user experiencewrite a stylish styling sheet
make sure everything is responsive
nothingnothing
-
-
- -
- - - -
- - -
- - -
-
- - - -
-
- -
-
- - -
- - - - - - -
- - - You can’t perform that action at this time. -
- - - - - - - - - - - - - - -
- - - - +## Week 2 Project + +> The user stories are not listed in the same order here as they are in the ```index.html```. This page lists them in order of difficulty to help you build up your skillzz over the week + +| __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!) | +| _... constantize a string_ | nothing | nothing | pass all tests for the ```constantize``` function | +| _... caesarize a string_ | nothing | nothing | pass all tests for the ```caesarize``` function | +| _... repeat the characters in a string_ | nothing | nothing | pass all tests for the ```repeatChars``` function | +| _... leftpad a string_ | nothing | nothing | pass all tests for the ```leftpad``` function | +| _... have a pleasant user experience_ | write a stylish styling sheet
make sure everything is responsive | nothing | nothing | From b95b63ab9b30e2cb017e4b6fe57079fb47945830 Mon Sep 17 00:00:00 2001 From: Mert Demirok <55088530+Mert1980@users.noreply.github.com> Date: Tue, 15 Oct 2019 14:15:04 +0200 Subject: [PATCH 23/38] Update index.html --- week-2-project/index.html | 1435 +------------------------------------ 1 file changed, 35 insertions(+), 1400 deletions(-) diff --git a/week-2-project/index.html b/week-2-project/index.html index 0464357..406f38f 100644 --- a/week-2-project/index.html +++ b/week-2-project/index.html @@ -1,1424 +1,59 @@ + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - javascript-1/index.html at master · be-hacking-hyf/javascript-1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Skip to content - - - - - - - - - - - - - +
+
+
+

   
-
- - -
- -
- - - -
-
-
- - - - - - - - - - - - - - - - -
-
- -
    - - - - -
  • - -
    - -
    - - - Watch - - -
    - Notifications -
    -
    - - - - - - - -
    -
    -
    - -
    -
  • - -
  • -
    -
    - - -
    -
    - - -
    - -
  • - -
  • -
    -
    - -
  • -
- -

- - /javascript-1 - - -

- -
- - - - - - -
-
-
- - - - - - - - - Permalink - - - - -
- - -
- - Branch: - master - - - - - - - -
- -
- - Find file - - - Copy path - -
-
- - -
- - Find file - - - Copy path - -
-
- - - - -
- - -
-
- - 1 contributor - - -
- -

- Users who have contributed to this file -

-
- -
-
-
-
- - - - - -
- -
-
- - 60 lines (41 sloc) - - 1.57 KB -
- -
- -
- Raw - Blame - History -
- - -
- -
- -
-
- -
+
+
+
+

   
-
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
<!doctype html>
-
<html lang="en">
-
<head>
<meta charset="utf-8">
-
<title>week 2 project</title>
<meta name="description" content="week 2 project">
-
<script src="../evaluate.js"></script>
</head>
-
<body>
-
-
-
<div id='repeatChars-container'>
<input id='repeatChars-input' placeholder='characters to repeatChars' /> <br>
<button id='repeatChars-button'>repeatChars it</button> <br>
<pre id='repeatChars-output'></pre>
</div>
-
<div id='constantize-container'>
<input id='constantize-input' placeholder='string to constantize' /> <br>
<button id='constantize-button'>constantize it</button> <br>
<pre id='constantize-output'></pre>
</div>
-
-
<div id='caesarize-container'>
<textarea id='caesarize-string-input' rows="15" cols="30"></textarea> <br>
<input id='caesarize-number-input' placeholder='encryption key (number)' /> <br>
<button id='caesarize-button'>caesarize it</button> <br>
<pre id='caesarize-output'></pre>
</div>
-
<div id='leftpad-container'>
<input id='leftpad-str-input' placeholder='string to pad' />
<input id='leftpad-len-input' placeholder='target length' />
<input id='leftpad-pad-input' placeholder='pad string' />
<button id='leftpad-button'>leftpad it</button> <br>
<pre id='leftpad-output'></pre>
</div>
-
-
<!-- get rid of these hr's, this type of thing should be done with CSS -->
<hr>
<hr>
-
-
<script src="scripts/repeatChars.js"></script>
<script src="scripts/constantize.js"></script>
<script src="scripts/caesarize.js"></script>
<script src="scripts/leftpad.js"></script>
-
</body>
-
</html>
- +
+
+
+
+

   
-
- - - -
- - -
- - -
-
- - - +
+ + + +
+

   
-
-
-
- -
+ +
+
- - - - - -
- - - You can’t perform that action at this time. -
+ + + + + - - - - - - - - - - - - -
- - - From 87af542b640366395cc8d2cba7158c812d76dd43 Mon Sep 17 00:00:00 2001 From: Mert Demirok <55088530+Mert1980@users.noreply.github.com> Date: Tue, 15 Oct 2019 14:16:23 +0200 Subject: [PATCH 24/38] Update leftpad.js --- week-2-project/scripts/leftpad.js | 1516 ++--------------------------- 1 file changed, 65 insertions(+), 1451 deletions(-) diff --git a/week-2-project/scripts/leftpad.js b/week-2-project/scripts/leftpad.js index f4ffd52..6b64782 100644 --- a/week-2-project/scripts/leftpad.js +++ b/week-2-project/scripts/leftpad.js @@ -1,1451 +1,65 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - javascript-1/leftpad.js at master · be-hacking-hyf/javascript-1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Skip to content - - - - - - - - - - - - - -
- -
- - -
- -
- - - -
-
-
- - - - - - - - - - - - - - - - -
-
- -
    - - - - -
  • - -
    - -
    - - - Watch - - -
    - Notifications -
    -
    - - - - - - - -
    -
    -
    - -
    -
  • - -
  • -
    -
    - - -
    -
    - - -
    - -
  • - -
  • -
    -
    - -
  • -
- -

- - /javascript-1 - - -

- -
- - - - - - -
-
-
- - - - - - - - - Permalink - - - - -
- - -
- - Branch: - master - - - - - - - -
- -
- - Find file - - - Copy path - -
-
- - -
- - Find file - - - Copy path - -
-
- - - - -
-
- - @colevandersWands - colevandersWands - - leftpad-links - - - - 7c89535 - Oct 13, 2019 - -
- -
-
- - 1 contributor - - -
- -

- Users who have contributed to this file -

-
- -
-
-
-
- - - - - -
- -
-
- - 69 lines (56 sloc) - - 2.98 KB -
- -
- -
- Raw - Blame - History -
- - -
- -
- -
-
- -
-
-
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/* 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/
- - - -
- -
- - - -
- - -
- - -
-
- - - -
-
- -
-
- - -
- - - - - - -
- - - You can’t perform that action at this time. -
- - - - - - - - - - - - - - -
- - - - +/* 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/ From dae1d2089f5c996abb81aa4e3c75dfdd63cca7fb Mon Sep 17 00:00:00 2001 From: Mert Demirok Date: Wed, 16 Oct 2019 14:15:40 +0200 Subject: [PATCH 25/38] caesarize.js code completed --- week-2-project/scripts/caesarize.js | 44 +++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/week-2-project/scripts/caesarize.js b/week-2-project/scripts/caesarize.js index 4eac053..3065c0e 100644 --- a/week-2-project/scripts/caesarize.js +++ b/week-2-project/scripts/caesarize.js @@ -15,11 +15,49 @@ 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) { + + var input=str; + + var str=input.split(''); + + var code=input.split(''); + + var ceasared=input.split(''); + + for (var i = 0; i < str.length; i++) { + code[i] = str[i].charCodeAt(); + if ((code[i]>=97)&&(code[i]<=122)){ + code[i]+=shiftNum; + if (code[i]>122){ + code[i]=code[i]-26; + } + else if (code[i]<97){ + code[i]=code[i]+26; + } + ceasared[i] = String.fromCharCode(code[i]); + } + else if ((code[i]>=65)&&(code[i]<=90)){ + code[i]+=shiftNum; + if (code[i]>90){ + code[i]=code[i]-26; + } + else if (code[i]<65){ + code[i]=code[i]+26; + } + ceasared[i] = String.fromCharCode(code[i]); + } + + } + return ceasared.join(''); + } + + // console.log(caesarize('aBcD',-3)); + // write me! -} + evaluate(caesarize, caesarizeTests); @@ -36,7 +74,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 97a468ce003166586a75dd7beb9548aabc58cbc4 Mon Sep 17 00:00:00 2001 From: Mert Demirok Date: Fri, 18 Oct 2019 14:13:20 +0200 Subject: [PATCH 26/38] repeatchars.js file is completed --- week-2-project/scripts/repeatChars.js | 35 ++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/week-2-project/scripts/repeatChars.js b/week-2-project/scripts/repeatChars.js index d2209b6..389ad93 100644 --- a/week-2-project/scripts/repeatChars.js +++ b/week-2-project/scripts/repeatChars.js @@ -11,13 +11,40 @@ 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: 'fourth', args: ['h3LL0 W@r!|)'], expected: 'hh333LLLL000 WW@@@@rr!!!!||||))))' }, { name: 'fifth', args: ['{:-<*>-:}'], expected: '{{{{::::----<<<<****>>>>----::::}}}}' }, - { name: 'sixth', args: [''], expected: '' }, { name: 'seventh', args: [' '], expected: ' ' }, + { name: 'sixth', args: [''], expected: '' }, + ]; -function repeatChars(str) { - // write this! +function repeatChars(stringInput) { + +var strArray = stringInput.split(''); +var codeArray = strArray.map(function(code){ + code=code.charCodeAt(); + return code; + }); + +console.log(codeArray); +var newArray = codeArray.map(function(num) { + if (num<=90 && num>=65){ + num = String.fromCharCode(num)+String.fromCharCode(num); + return num; + } + else if (num<=122 && num>=97) { + num = String.fromCharCode(num)+String.fromCharCode(num); + return num; + } + else if (num<=57 && num>=48 ) { + num = String.fromCharCode(num)+String.fromCharCode(num)+String.fromCharCode(num); + return num; + } + else { + num = String.fromCharCode(num)+String.fromCharCode(num)+String.fromCharCode(num)+String.fromCharCode(num); + return num; + } +}); +return newArray.join(''); } evaluate(repeatChars, repeatCharsTests); From 137e62c79896d0e8a4a417da1889cf34b841f646 Mon Sep 17 00:00:00 2001 From: Mert Demirok Date: Fri, 18 Oct 2019 17:01:46 +0200 Subject: [PATCH 27/38] I completed the code for constantize. It passed all the tests --- 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..1c86160 100644 --- a/week-2-project/scripts/constantize.js +++ b/week-2-project/scripts/constantize.js @@ -23,7 +23,20 @@ const constantizeTests = [ { name: 'sixth', args: ['ALREADY_A_CONSTANT'], expected: 'ALREADY_A_CONSTANT' }, ]; function constantize(str) { - // write me! + + var CapArray = str.toUpperCase().split(' '); + + var filteredArray = CapArray.map(function(element){ + var arrayedElement=element.split(''); + var filteredArrayedElement = arrayedElement.filter((c)=>{ + return c.charCodeAt() >= 65 && c.charCodeAt() <= 90 || c.charCodeAt() === 95; + }); + var newArray = filteredArrayedElement.join(''); + return newArray; + }); + + var joinedArray = filteredArray.join('_').replace(/_+/g, '_'); + return joinedArray; } evaluate(constantize, constantizeTests); From 36145f7d3fc97eecf1cd5fa610d10cca4a3ca14e Mon Sep 17 00:00:00 2001 From: Mert Demirok Date: Fri, 18 Oct 2019 19:03:23 +0200 Subject: [PATCH 28/38] style changes applied --- week-2-project/index.html | 21 ++++--- week-2-project/style.css | 115 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+), 7 deletions(-) diff --git a/week-2-project/index.html b/week-2-project/index.html index 406f38f..b6f2acf 100644 --- a/week-2-project/index.html +++ b/week-2-project/index.html @@ -7,31 +7,34 @@ week 2 project - + - +

-
+

   

-
+

   
-
+

-
+

   
@@ -39,10 +42,14 @@ -
+

   
+
+

Mert Demirok © 2019 | Hack your future Belgium | JS | Week 2

+ +

diff --git a/week-2-project/style.css b/week-2-project/style.css index e69de29..4ec174c 100644 --- a/week-2-project/style.css +++ b/week-2-project/style.css @@ -0,0 +1,115 @@ +@import url('https://fonts.googleapis.com/css?family=Roboto:400,400i,700&display=swap'); + +body { + background-color: beige; + font-family: 'Roboto', sans-serif; +} + +/*header*/ + +#header { + text-align: center; + margin-top: 50px; +} + +#name_header { + background-color: darkgray; + padding: 5px; + border-radius: 10%; +} + +/* repeatChars-container */ +#repeatChars-container { + background-color: rgba(12, 51, 182, 0.164); + display: flex; + flex-direction: column; + align-items: center; + margin-top: 50px; + padding: 5%; + border-radius: 30%; +} +#repeatChars-input { + width: 185px; +} +#repeatChars-button { + width: 200px; +} + +#repeatChars-output { + width: 200px; + text-align: center; +} + +/* constantize container */ + +#constantize-container { + background-color: rgba(24, 134, 10, 0.164); + display: flex; + flex-direction: column; + align-items: center; + margin-top: 50px; + padding: 5%; + border-radius: 30%; +} +#constantize-input { + width: 185px; +} +#constantize-button { + width: 200px; +} + +/* caesarize-container */ + +#caesarize-container { + background-color: rgba(136, 134, 10, 0.164); + display: flex; + flex-direction: column; + align-items: center; + margin-top: 50px; + padding: 5%; + border-radius: 30%; +} +#caesarize-input { + width: 185px; +} +#caesarize-number-input { + width: 185px; +} +#caesarize-button { + width: 200px; +} + +/* leftpad-container */ + +#leftpad-container { + background-color: rgba(134, 10, 62, 0.164); + display: flex; + flex-direction: column; + align-items: center; + margin-top: 50px; + padding: 5%; + border-radius: 30%; +} +#leftpad-str-input { + width: 185px; +} +#leftpad-len-input { + width: 185px; +} +#leftpad-pad-input { + width: 185px; +} + +#leftpad-button { + width: 200px; +} + +p { + text-align: center; + display: block; + margin: 0 auto; + clear: both; + padding-top: 5%; + padding-bottom: 5%; + color: rgb(2, 1, 54); + } \ No newline at end of file From db23a603c36ebcbbb137dc827743f4047fd12802 Mon Sep 17 00:00:00 2001 From: Mert Demirok Date: Fri, 18 Oct 2019 19:08:29 +0200 Subject: [PATCH 29/38] footer changed --- week-2-project/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week-2-project/index.html b/week-2-project/index.html index b6f2acf..3124d16 100644 --- a/week-2-project/index.html +++ b/week-2-project/index.html @@ -47,7 +47,7 @@

JavaScript Week-2 Project

-

Mert Demirok © 2019 | Hack your future Belgium | JS | Week 2

+

Mert Demirok © 2019 | Hack Your Future Belgium | JS | Week 2

From dbe6704167098b15b998c800acf6fc1e49062593 Mon Sep 17 00:00:00 2001 From: Mert Demirok Date: Sat, 19 Oct 2019 14:48:04 +0200 Subject: [PATCH 30/38] truthiness operators completed --- module-exercises/index.html | 10 ++--- module-exercises/truthiness-operators.js | 48 ++++++++++++------------ week-2-project/scripts/leftpad.js | 3 ++ 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/module-exercises/index.html b/module-exercises/index.html index 0cfa5d4..a2c4a84 100644 --- a/module-exercises/index.html +++ b/module-exercises/index.html @@ -20,22 +20,22 @@ this will make your study-flow much cleaner --> - + - --> + --> --> --> challenge exercises diff --git a/module-exercises/truthiness-operators.js b/module-exercises/truthiness-operators.js index ccc468a..b47884f 100644 --- a/module-exercises/truthiness-operators.js +++ b/module-exercises/truthiness-operators.js @@ -46,14 +46,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: 'NaN, 0', args: [NaN, 0], expected: NaN }, + { name: 'NaN, undefined', args: [NaN, undefined], expected: NaN }, + { name: 'Undefined, NaN', args: [undefined, NaN], expected: undefined}, + { name: 'NaN, 0', args: [NaN, 0], expected: NaN }, + { name: '0, NaN', args: [0, NaN], expected: 0 }, + { name: 'NaN, null', args: [NaN, null], expected: NaN }, + { name: 'null, NaN', args: [null, NaN], expected: null }, + { name: 'NaN, "false"', args: [NaN, "true"], expected: NaN }, ]; function and(a, b) { return a && b; @@ -69,14 +69,14 @@ 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: '2', args: [2], expected: false }, + { name: '-4', args: [-4], expected: false }, + { name: 'NaN', args: [NaN], expected: true }, + { name: 'undefined', args: [undefined], expected: true }, + { name: 'null', args: [null], expected: true }, + { name: '0.3', args: [0.3], expected: false }, + { name: '150', args: [150], expected: false }, + { name: 'How?', args: ['How?'], expected: false }, ]; function not(a) { return !a; @@ -92,14 +92,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: 'mert', args: [null, 'mert', 'asena'], expected: 'asena' }, + { name: '?', args: [1, '?','!'], expected: '?' }, + { name: 'minus', args: [-10, 'negative', 'positive' ], expected: 'negative' }, + { name: '3.5', args: [-0, '3.5','null'], expected: 'null' }, + { name: 'hi()', args: ['hi()', 'hello','bye'], expected: 'hello' }, + { name: 'undefined', args: [undefined, 'yes','no'], expected: 'no' }, + { name: '100', args: [100, 'hunderd','none'], expected: 'hunderd' }, + { name: '-0', args: [-0,'zero','null'], expected: 'null' }, ]; function ternary(a, b, c) { return a ? b : c; diff --git a/week-2-project/scripts/leftpad.js b/week-2-project/scripts/leftpad.js index 6b64782..ac99364 100644 --- a/week-2-project/scripts/leftpad.js +++ b/week-2-project/scripts/leftpad.js @@ -26,8 +26,11 @@ const leftpadTests = [ { name: 'twentieth', args: ['car', 12, '-=:=-'], expected: '=:=--=:=-car' }, ]; function leftpad(str, len, pad) { + // write me! + } + evaluate(leftpad, leftpadTests); From d4e65f1642d7759e51c410d59b744a6e7592a14d Mon Sep 17 00:00:00 2001 From: Mert Demirok <55088530+Mert1980@users.noreply.github.com> Date: Sat, 19 Oct 2019 14:50:54 +0200 Subject: [PATCH 31/38] Update index.html --- module-exercises/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module-exercises/index.html b/module-exercises/index.html index a2c4a84..a436719 100644 --- a/module-exercises/index.html +++ b/module-exercises/index.html @@ -20,7 +20,7 @@ this will make your study-flow much cleaner --> - -
- - -
+

-
+

   
+
+
+

Mert Demirok © 2019 | Hack Your Future Belgium | JS | Week 3

+ +
+
+
diff --git a/week-3-project/style.css b/week-3-project/style.css index e69de29..5973782 100644 --- a/week-3-project/style.css +++ b/week-3-project/style.css @@ -0,0 +1,134 @@ +@import url('https://fonts.googleapis.com/css?family=Roboto:400,400i,700&display=swap'); + +body { + background-color: beige; + font-family: 'Roboto', sans-serif;} + +/*header*/ + +header { + background: #35424a; + color: #ffffff; + padding-top: 30px; + min-height: 70px; + border-bottom: black 3px solid; } +header a { + color: #ffffff; + text-decoration: none; + text-transform: uppercase; + font-size: 16px; } + +header li { + float: left; + display: inline; + padding: 0 20px 0 20px; } + +header #brand { + float: left; } + + +ul { + margin: 0; + padding: 0; } + +header #brand h1 { + margin: 0; + padding-left: 10px; } + +header nav { + float: right; + margin-top: 10px; } + +header a:hover { + color: #cccccc; + font-weight: bold; } + +.mainbody { + /* background-color: darkgreen; */ + margin-top: 0;} + + + +/* caesaring container */ +#caesaring-container { + background-color: rgba(182, 173, 12, 0.69); + display: flex; + flex-direction: column; + align-items: center; + margin-top: 50px; + padding: 50px; + margin-left: 20%; + margin-right: 20%; + border-block-style: double; + border-block-color: currentColor; + border-block-width: thick; + border-radius: 10%; + width: auto;} + +#unencrypted-string-input{ + width: 200px;} + +#encryption-key-input { + width: 185px;} + +#encrypt-button, #decrypt-button { + width: 200px;} + +#encrypted-string-output { + width: 200px; + text-align: center;} + +#decryption-key-input { + width: 185px;} + +/* scramble container */ + +#scramble-container { + background-color: rgba(182, 117, 12, 0.8); + display: flex; + flex-direction: column; + align-items: center; + margin-top: 50px; + padding: 50px; + margin-left: 20%; + margin-right: 20%; + border-block-style: double; + border-block-color: currentColor; + border-block-width: thick; + border-radius: 10%; + width: auto;} + +#scramble-input { + width: 200px;} + +#scramble-button { + width: 200px;} + +p { + text-align: center; + display: block; + margin: 0 auto; + clear: both; + padding-top: 5%; + padding-bottom: 5%; + color: rgb(2, 1, 54); } + + + @media (max-width: 768px) { + header #brand, + header nav, + header nav li, + #newsletter h1, + .button_1 { + float: none; + text-align: center; + width: 100%; } + + header li { + padding: 0 10px 0 10px; } + + header { + padding-bottom: 20px; } + } + + From 6981eb309016c82f565479fd7038bdaf6bef5f7f Mon Sep 17 00:00:00 2001 From: Mert Demirok Date: Tue, 22 Oct 2019 13:59:23 +0200 Subject: [PATCH 34/38] updated week3 project files --- module-exercises/errors-and-lifecycle.js | 18 +++++++------ module-exercises/index.html | 6 ++--- module-exercises/loops.js | 4 +-- week-2-project/scripts/caesarize.js | 8 +----- week-2-project/scripts/leftpad.js | 20 ++++++++++++-- week-3-project/handlers/decrypt.js | 2 +- week-3-project/handlers/encrypt.js | 2 +- week-3-project/logic/backward-sentence.js | 2 +- week-3-project/logic/caesarize.js | 32 ++++++++++++++++++++--- week-3-project/logic/chunk.js | 2 +- 10 files changed, 67 insertions(+), 29 deletions(-) diff --git a/module-exercises/errors-and-lifecycle.js b/module-exercises/errors-and-lifecycle.js index 20c029e..33b9404 100644 --- a/module-exercises/errors-and-lifecycle.js +++ b/module-exercises/errors-and-lifecycle.js @@ -74,7 +74,7 @@ function unexpectedToken3() { evaluate(unexpectedToken3); function unexpectedToken4() { - const str = "he told me "run!" the horse arrives!"; + const str = "he told me \"run!\" the horse arrives!"; } evaluate(unexpectedToken4); @@ -84,12 +84,12 @@ function missingAfterElement1() { 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,10 @@ function missingBeforeformal() { evaluate(missingBeforeformal); function unEscapedLineBreak() { - const a = 'this is + const a = 'this is\n two lines'; + // const a = `this is + // two lines`; } evaluate(unEscapedLineBreak); @@ -107,7 +109,7 @@ evaluate(unEscapedLineBreak); // these are detected at runtime and will throw an error after the page has loaded function invalidAssignment() { - const x = 1; + let x = 1; x++; } evaluate(invalidAssignment); @@ -144,9 +146,9 @@ evaluate(xIsNull); function bracketIsUndefined() { const myArray = [ - [1, 2, 3] - [4, 5, 6] - [7, 8, 9] + [1, 2, 3], + [4, 5, 6], + [7, 8, 9], ]; } evaluate(bracketIsUndefined); diff --git a/module-exercises/index.html b/module-exercises/index.html index a436719..4cb9ffd 100644 --- a/module-exercises/index.html +++ b/module-exercises/index.html @@ -24,7 +24,7 @@ - --> + @@ -34,8 +34,8 @@ - - --> --> --> + + challenge exercises diff --git a/module-exercises/loops.js b/module-exercises/loops.js index 0d67c58..b0432aa 100644 --- a/module-exercises/loops.js +++ b/module-exercises/loops.js @@ -103,11 +103,11 @@ 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; } diff --git a/week-2-project/scripts/caesarize.js b/week-2-project/scripts/caesarize.js index 3065c0e..6323d3a 100644 --- a/week-2-project/scripts/caesarize.js +++ b/week-2-project/scripts/caesarize.js @@ -18,16 +18,11 @@ const caesarizeTests = [ { name: 'seventh', args: ["#@&&^F*(#", 7], expected: '#@&&^M*(#' }, ]; function caesarize(str, shiftNum) { - var input=str; - var str=input.split(''); - var code=input.split(''); - var ceasared=input.split(''); - - for (var i = 0; i < str.length; i++) { + for (var i = 0; i < str.length; i++) { code[i] = str[i].charCodeAt(); if ((code[i]>=97)&&(code[i]<=122)){ code[i]+=shiftNum; @@ -49,7 +44,6 @@ function caesarize(str, shiftNum) { } ceasared[i] = String.fromCharCode(code[i]); } - } return ceasared.join(''); } diff --git a/week-2-project/scripts/leftpad.js b/week-2-project/scripts/leftpad.js index ac99364..6a514da 100644 --- a/week-2-project/scripts/leftpad.js +++ b/week-2-project/scripts/leftpad.js @@ -27,8 +27,24 @@ const leftpadTests = [ ]; function leftpad(str, len, pad) { - // write me! - + let str = "silman"; + let strarr = str.split(''); + let strlen = strarr.length; + let newstr=[]; + let len = 10; + let pad = "%-"; + + for (var x = len ; x > strlen ; x--) { + strarr.unshift(pad); + console.log(str); + } + for (var x = len ; x < strlen ; x++) { + strarr.pop(); + console.log(str); + } + if (strlen==len){ + console.log(str); + } } evaluate(leftpad, leftpadTests); diff --git a/week-3-project/handlers/decrypt.js b/week-3-project/handlers/decrypt.js index 5878ad6..52f9334 100644 --- a/week-3-project/handlers/decrypt.js +++ b/week-3-project/handlers/decrypt.js @@ -11,7 +11,7 @@ function decryptHandler() { // pass user input through core logic (this works! no need to change it) - const decrypted = caesarize(strToDecrypt); + const decrypted = caesarize(strToDecrypt,shiftNumber); // report result to user (this works, no need to change it!) const outputField = document.getElementById('decrypted-string-output'); diff --git a/week-3-project/handlers/encrypt.js b/week-3-project/handlers/encrypt.js index b2e3325..2396ec1 100644 --- a/week-3-project/handlers/encrypt.js +++ b/week-3-project/handlers/encrypt.js @@ -11,7 +11,7 @@ function encryptHandler() { // pass user input through core logic (this works! no need to change it) - const encrypted = caesarize(strToEncrypt); + const encrypted = caesarize(strToEncrypt,shiftNumber); // report result to user (this works, no need to change it!) const outputField = document.getElementById('encrypted-string-output'); diff --git a/week-3-project/logic/backward-sentence.js b/week-3-project/logic/backward-sentence.js index 1150fc7..d68365a 100644 --- a/week-3-project/logic/backward-sentence.js +++ b/week-3-project/logic/backward-sentence.js @@ -12,7 +12,7 @@ const backwardsCases = [ { name: 'first', args: [' plug (play!)'], expected: ' (play!) plug' }, { name: 'second', args: [' -- - '], expected: ' - -- ' }, { name: 'third', args: ['12 34 '], expected: '34 12 ' }, - { name: 'fourth', args: ['const x = null; '], expected: ';llun = x tsnoc ' }, + { name: 'fourth', args: ['const x = null; '], expected: 'null; = x const ' }, { name: 'fifth', args: [' e e '], expected: ' e e ' }, ]; function backwards(str) { diff --git a/week-3-project/logic/caesarize.js b/week-3-project/logic/caesarize.js index a840159..dc8edfb 100644 --- a/week-3-project/logic/caesarize.js +++ b/week-3-project/logic/caesarize.js @@ -15,9 +15,35 @@ 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! -} + // var strArr=str.split(''); + var code=str.split(''); + var ceasared=str.split(''); + for (var i = 0; i < str.length; i++) { + code[i] = str[i].charCodeAt(); + if ((code[i]>=97)&&(code[i]<=122)){ + code[i]+=shiftNum; + if (code[i]>122){ + code[i]=code[i]-26; + } + else if (code[i]<97){ + code[i]=code[i]+26; + } + ceasared[i] = String.fromCharCode(code[i]); + } + else if ((code[i]>=65)&&(code[i]<=90)){ + code[i]+=shiftNum; + if (code[i]>90){ + code[i]=code[i]-26; + } + else if (code[i]<65){ + code[i]=code[i]+26; + } + ceasared[i] = String.fromCharCode(code[i]); + } + } + return ceasared.join(''); + } evaluate(caesarize, caesarizeTests); diff --git a/week-3-project/logic/chunk.js b/week-3-project/logic/chunk.js index 0af0e05..b423ade 100644 --- a/week-3-project/logic/chunk.js +++ b/week-3-project/logic/chunk.js @@ -40,7 +40,7 @@ const thirdExpected = [ const chunkTests = [ { name: 'first', args: ['const x = null;'], expected: ['const x ', '=', ' null', ';'] }, { name: 'second', args: [secondArg], expected: secondExpected }, - { name: 'second', args: [thirdArg], expected: thirdExpected }, + { name: 'third', args: [thirdArg], expected: thirdExpected }, ]; function chunk(str) { // write me! From 1abf6b4d6f0a58689ad1516022f2a2050fbc51bc Mon Sep 17 00:00:00 2001 From: Mert Demirok Date: Wed, 23 Oct 2019 17:09:41 +0200 Subject: [PATCH 35/38] corrected files for week2 and week3 --- week-2-project/scripts/leftpad.js | 81 ++++++++++++++----- week-3-project/README.md | 22 ++++- week-3-project/handlers/decrypt.js | 15 ++-- week-3-project/handlers/encrypt.js | 12 +-- week-3-project/handlers/scramble.js | 2 +- week-3-project/index.html | 29 +++---- week-3-project/logic/caesarize.js | 53 ++++++------ week-3-project/logic/chunk.js | 2 +- ...{backward-sentence.js => reverse-chunk.js} | 14 ++-- week-3-project/logic/scramble.js | 8 +- week-3-project/logic/sort-words.js | 22 ++++- week-3-project/style.css | 18 ++--- 12 files changed, 178 insertions(+), 100 deletions(-) rename week-3-project/logic/{backward-sentence.js => reverse-chunk.js} (54%) diff --git a/week-2-project/scripts/leftpad.js b/week-2-project/scripts/leftpad.js index 6a514da..01e48bb 100644 --- a/week-2-project/scripts/leftpad.js +++ b/week-2-project/scripts/leftpad.js @@ -25,26 +25,69 @@ const leftpadTests = [ { name: 'nineteenth', args: ['car', 11, '-=:=-'], expected: ':=--=:=-car' }, { name: 'twentieth', args: ['car', 12, '-=:=-'], expected: '=:=--=:=-car' }, ]; + function leftpad(str, len, pad) { - - let str = "silman"; - let strarr = str.split(''); - let strlen = strarr.length; - let newstr=[]; - let len = 10; - let pad = "%-"; - - for (var x = len ; x > strlen ; x--) { - strarr.unshift(pad); - console.log(str); - } - for (var x = len ; x < strlen ; x++) { - strarr.pop(); - console.log(str); - } - if (strlen==len){ - console.log(str); - } + // I need to know the given word length + const strLength = str.length; + // I need to know the given pad word length + const padLength = pad.length; + + // If the desired word length is zero + if (len === 0) { + // Then I return an empty word (string). Here ends. + return ''; + } + + // If the given word length is equals to the desired word length + if (strLength === len) { + // Then I just return the word given. Here ends. + return str; + } + // otherwise, If desired word length is less than the given word length + else if (len < strLength) { + // Then I return part of the given word. + // With the method substring > Starting from the character zero to the desired word length + return str.substring(0, len); + } + + // Here I already know that the desired word length is greater than the given word length + // Then I need to build my left pad + // So I start with an empty string + let padStr = ''; + // I calculate what length the left pad should be + const leftPadLength = len - strLength; + + // So probably the pad given fits entirely one or more times in the length calculated before + // I need to know the integer number from the division of the left pad length between the + // pad given length. Math.floor method help me to do that + const howManyTimesPadFits = Math.floor(leftPadLength / padLength); + + // Then I iterate the number of times the pad can fit and append it to the empty string + // I set before + for (let i = 1; i <= howManyTimesPadFits; i = i + 1) { + padStr = padStr + pad; + } + + // And probably there will be left some characters to complete my left pad length + // So I need to know the remainder from the division + // With module operator (%) I can do it + const howManyCharFromPadNeededToComplete = leftPadLength % padLength; + + // Know I need to get those characters from the pad word given, but I need to get them + // starting from the last. + // With the method substring > I can start from the last character doing the operation + // (word length - number characters to get) > + // https://stackoverflow.com/questions/5873810/how-can-i-get-last-characters-of-a-string + const charsNeeded = pad.substring(padLength - howManyCharFromPadNeededToComplete); + + // Almost done, now I prepend chars needed to complete to my left Pad string + padStr = charsNeeded + padStr; + + // Finally I prepend the left pad string to the word given + const leftPaddedStr = padStr + str; + + // And return the string built + return leftPaddedStr; } evaluate(leftpad, leftpadTests); diff --git a/week-3-project/README.md b/week-3-project/README.md index 0fbaea2..16db012 100644 --- a/week-3-project/README.md +++ b/week-3-project/README.md @@ -1,5 +1,19 @@ -your tasks in this week's project: -* write functions to pass the tests in the ```./logic``` folder -* 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 | + diff --git a/week-3-project/handlers/decrypt.js b/week-3-project/handlers/decrypt.js index 52f9334..91e6e9b 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,shiftNumber); + // pass user input through core logic + const decrypted = caesarize(strToDecrypt,-shiftNumber); // 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 2396ec1..bf51f6d 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) + // pass user input through core logic const encrypted = caesarize(strToEncrypt,shiftNumber); // 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); diff --git a/week-3-project/handlers/scramble.js b/week-3-project/handlers/scramble.js index f93a0cd..114c5ea 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'); diff --git a/week-3-project/index.html b/week-3-project/index.html index f226063..8e059f9 100644 --- a/week-3-project/index.html +++ b/week-3-project/index.html @@ -12,7 +12,7 @@ - + @@ -29,34 +29,29 @@

JavaScript Week-3 Project

- - -
-
-
+

-

-     
+

-

+     
-
+ + +


-

+    
   
-
+

Mert Demirok © 2019 | Hack Your Future Belgium | JS | Week 3

- -
- -
-
+ +
+
diff --git a/week-3-project/logic/caesarize.js b/week-3-project/logic/caesarize.js index dc8edfb..0a74a73 100644 --- a/week-3-project/logic/caesarize.js +++ b/week-3-project/logic/caesarize.js @@ -6,6 +6,8 @@ for example, caesarize("A", 3) will return : "D" because "D" is three letters past "A". + + (yes, this is the same function you wrote last week) */ const caesarizeTests = [ @@ -18,32 +20,33 @@ const caesarizeTests = [ { name: 'seventh', args: ["#@&&^F*(#", 7], expected: '#@&&^M*(#' }, ]; function caesarize(str, shiftNum) { - // var strArr=str.split(''); - var code=str.split(''); - var ceasared=str.split(''); - for (var i = 0; i < str.length; i++) { - code[i] = str[i].charCodeAt(); - if ((code[i]>=97)&&(code[i]<=122)){ - code[i]+=shiftNum; - if (code[i]>122){ - code[i]=code[i]-26; - } - else if (code[i]<97){ - code[i]=code[i]+26; + // var strArr=str.split(''); + var code=str.split(''); + var ceasared=str.split(''); + for (var i = 0; i < str.length; i++) { + code[i] = str[i].charCodeAt(); + if ((code[i]>=97)&&(code[i]<=122)){ + code[i]+=shiftNum; + if (code[i]>122){ + code[i]=code[i]-26; + } + else if (code[i]<97){ + code[i]=code[i]+26; + } + ceasared[i] = String.fromCharCode(code[i]); } - ceasared[i] = String.fromCharCode(code[i]); - } - else if ((code[i]>=65)&&(code[i]<=90)){ - code[i]+=shiftNum; - if (code[i]>90){ - code[i]=code[i]-26; + else if ((code[i]>=65)&&(code[i]<=90)){ + code[i]+=shiftNum; + if (code[i]>90){ + code[i]=code[i]-26; + } + else if (code[i]<65){ + code[i]=code[i]+26; + } + ceasared[i] = String.fromCharCode(code[i]); } - else if (code[i]<65){ - code[i]=code[i]+26; - } - ceasared[i] = String.fromCharCode(code[i]); - } + } + return ceasared.join(''); } - return ceasared.join(''); - } + evaluate(caesarize, caesarizeTests); diff --git a/week-3-project/logic/chunk.js b/week-3-project/logic/chunk.js index b423ade..0af0e05 100644 --- a/week-3-project/logic/chunk.js +++ b/week-3-project/logic/chunk.js @@ -40,7 +40,7 @@ const thirdExpected = [ const chunkTests = [ { name: 'first', args: ['const x = null;'], expected: ['const x ', '=', ' null', ';'] }, { name: 'second', args: [secondArg], expected: secondExpected }, - { name: 'third', args: [thirdArg], expected: thirdExpected }, + { name: 'second', args: [thirdArg], expected: thirdExpected }, ]; function chunk(str) { // write me! diff --git a/week-3-project/logic/backward-sentence.js b/week-3-project/logic/reverse-chunk.js similarity index 54% rename from week-3-project/logic/backward-sentence.js rename to week-3-project/logic/reverse-chunk.js index d68365a..b7cd931 100644 --- a/week-3-project/logic/backward-sentence.js +++ b/week-3-project/logic/reverse-chunk.js @@ -3,19 +3,19 @@ reverse the order of words in a string. a word is anything with spaces on either side of it - the spaces stay put - + the spaces, tabs and newlines stay put */ -const backwardsCases = [ +const reverseChunkTests = [ { name: 'first', args: [' plug (play!)'], expected: ' (play!) plug' }, - { name: 'second', args: [' -- - '], expected: ' - -- ' }, + { name: 'second', args: [' -- - '], expected: ' - -- ' }, { name: 'third', args: ['12 34 '], expected: '34 12 ' }, - { name: 'fourth', args: ['const x = null; '], expected: 'null; = x const ' }, + { name: 'fourth', args: ['const x = null; '], expected: 'null = x const ' }, { name: 'fifth', args: [' e e '], expected: ' e e ' }, ]; -function backwards(str) { +function reverseChunk(str) { // write me! } -evaluate(backwards, backwardsCases); +evaluate(reverseChunk, reverseChunkTests); + diff --git a/week-3-project/logic/scramble.js b/week-3-project/logic/scramble.js index 5bb15ce..16a5ad5 100644 --- a/week-3-project/logic/scramble.js +++ b/week-3-project/logic/scramble.js @@ -20,13 +20,15 @@ const scrambleTests = [ { name: 'first', args: ['the road works.'], expected: 'korsw ador eht.' }, { name: 'second', args: ["name: 'second'"], expected: "aemn: 'cednos'" }, { name: 'third', args: [thirdScrambleArg], expected: thirdScrambleExpected }, + { name: 'fourth', args: ["name: 'second cow'"], expected: "aemn: 'cow cednos'" }, + { name: 'fifth', args: ["name e eman: 'second cow, cba'"], expected: "aemn e aemn: 'cow cednos, cba'" }, ]; function scramble(str) { /* - write a new implementation of scramble, passing the same tests as last week - this time you will use the functions "backwards", "sort", and "chunk" + write this function using "chunk", "sortWords" and "reverseChunk" each of these functions is one step along the way to a scrambled string - this is a nice exercise in using smaller functions to solve larger problems + this is a an exercise to practice using breaking large problems into smaller ones + and then solving the smaller problems and combining the small solutions into a full solution */ } evaluate(scramble, scrambleTests); diff --git a/week-3-project/logic/sort-words.js b/week-3-project/logic/sort-words.js index bbb61f3..53dcef5 100644 --- a/week-3-project/logic/sort-words.js +++ b/week-3-project/logic/sort-words.js @@ -1,6 +1,6 @@ /* sort characters - sort the words in a string, words are substrings separated by spaces + sort the characters in a word, words are substrings separated by spaces */ @@ -9,7 +9,23 @@ const sortTests = [ { name: 'second', args: ['abcd 153'], expected: 'abcd 135' }, { name: 'third', args: ['howdy doody time'], expected: 'dhowy ddooy eimt' }, ]; -function sort(str) { - // write me! + +// let str='howdy doody time'; + +let newArr=str.split(' '); + +function sort(str){ + + let arrstr=str.split(''); + let sortedstr=arrstr.sort(); + return sortedstr.join(''); + if (typeof sortedstr[0]===integer){ + sortedstr.sort(function(a, b){return a - b}) + } } + +const mynewArr= newArr.map(sort); +// console.log(mynewArr); + evaluate(sort, sortTests); + diff --git a/week-3-project/style.css b/week-3-project/style.css index 5973782..acc40f7 100644 --- a/week-3-project/style.css +++ b/week-3-project/style.css @@ -69,17 +69,17 @@ header a:hover { width: 200px;} #encryption-key-input { - width: 185px;} + width: 210px;} #encrypt-button, #decrypt-button { - width: 200px;} + width: 225px;} #encrypted-string-output { width: 200px; text-align: center;} #decryption-key-input { - width: 185px;} + width: 200px;} /* scramble container */ @@ -98,11 +98,11 @@ header a:hover { border-radius: 10%; width: auto;} -#scramble-input { - width: 200px;} +#scramble-input, #scramble-output { + width: 220px;} #scramble-button { - width: 200px;} + width: 225px;} p { text-align: center; @@ -114,7 +114,7 @@ p { color: rgb(2, 1, 54); } - @media (max-width: 768px) { +@media (max-width: 768px) { header #brand, header nav, header nav li, @@ -125,10 +125,10 @@ p { width: 100%; } header li { - padding: 0 10px 0 10px; } + padding: 0 10px 0 10px; } header { padding-bottom: 20px; } - } +} From a90cccd071bd1f42ce6f5f589d87f5e5c530ae59 Mon Sep 17 00:00:00 2001 From: Mert Demirok Date: Sat, 26 Oct 2019 00:53:35 +0200 Subject: [PATCH 36/38] week3 project files are updated --- module-exercises/conditional-statements.js | 65 +++++++++++-------- module-exercises/loops.js | 47 +++++++++----- module-exercises/statements-vs-expressions.js | 10 +-- week-2-project/scripts/leftpad.js | 54 +++------------ week-3-project/handlers/scramble.js | 2 +- week-3-project/logic/chunk.js | 34 +++++++++- week-3-project/logic/reverse-chunk.js | 29 ++++++++- week-3-project/logic/scramble.js | 64 +++++++++++++++++- week-3-project/logic/sort-words.js | 26 ++++---- 9 files changed, 217 insertions(+), 114 deletions(-) diff --git a/module-exercises/conditional-statements.js b/module-exercises/conditional-statements.js index c31a2fe..6abc08a 100644 --- a/module-exercises/conditional-statements.js +++ b/module-exercises/conditional-statements.js @@ -85,15 +85,15 @@ evaluate(example_unreachableCode); // 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: '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: 'if 2', args: ['4', 4], expected: 'if' }, + { name: 'if 3', args: ['3', 3], expected: 'if' }, + { name: 'if 4', args: ['0', 0], expected: 'if' }, + { name: 'if 5', args: ['-1', -1], expected: 'if' }, + { name: 'else 1', args: ['true', 0], expected: 'else' }, + { name: 'else 2', args: ['false', 0], expected: 'else' }, + { name: 'else 3', args: ['NaN', 2], expected: 'else' }, + { name: 'else 4', args: ['null', 0], expected: 'else' }, + { name: 'else 5', args: ['undefined', 0], expected: 'else' }, ]; function conditionalToPass1(a, b) { if (Number(a) === b) { @@ -108,20 +108,20 @@ evaluate(conditionalToPass1, conditionalTestCases1); // 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: [0, NaN], expected: 'if' }, + { name: 'if 3', args: ['null', 'null'], expected: 'if' }, + { name: 'if 4', args: ['undefined', '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: [0, 'null'], expected: 'else if' }, + { name: 'else if 3', args: [0, '[]'], expected: 'else if' }, + { name: 'else if 4', args: [0, '[]'], expected: 'else if' }, + { name: 'else if 5', args:[0, '1'], 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: [0, null], expected: 'else' }, + { name: 'else 3', args: [0, undefined], expected: 'else' }, + { name: 'else 4', args: ["true", true], expected: 'else' }, + { name: 'else 5', args: ["1", true], expected: 'else' }, ]; function conditionalToPass2(a, b) { if (typeof a === typeof b) { @@ -151,11 +151,11 @@ const testsToPass1 = [ ]; // careful of unreachable blocks! are any of yours unreachable? function passTests1(a, b) { - // conditional an if/else conditional statement to pass these tests - // you can pass the tests using only - // primitive values - // Number, String, Boolean - // typeof, ===, !== + if (Boolean(a) === Boolean(b)) { + return 'if'; + } else { + return 'else'; + } } passTests1.quizzing = true; evaluate(passTests1, testsToPass1); @@ -172,7 +172,7 @@ const testsToPass2 = [ { name: 'else if 3', args: [4, 5], expected: 'else if' }, { name: 'else if 4', args: ['true', 'false'], expected: 'else if' }, { name: 'else if 5', args: [NaN, NaN], expected: 'else if' }, - { name: 'else 1', args: [5, '5'], expected: 'else' }, + { name: 'else 1', args: [5, '5'], egxpected: 'else' }, { name: 'else 2', args: ['1000', 1000], expected: 'else' }, { name: 'else 3', args: ['0', 0], expected: 'else' }, { name: 'else 4', args: [true, 1], expected: 'else' }, @@ -180,6 +180,15 @@ const testsToPass2 = [ ]; // careful of unreachable blocks! are any of yours unreachable? function passTests2(a, b) { + + if (typeof a === typeof b) { + return 'if'; + } else if (typeof a !== typeof 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 @@ -219,7 +228,7 @@ evaluate(example_blockScopeInConditionals); const conditionalTests1 = [ // write test cases to pass this function - { name: 'first', args: null, expected: null }, + { name: 'first', args: ['1', '1'], expected: String }, { name: 'second', args: null, expected: null }, { name: 'third', args: null, expected: null }, { name: 'fourth', args: null, expected: null }, diff --git a/module-exercises/loops.js b/module-exercises/loops.js index b0432aa..0b3577c 100644 --- a/module-exercises/loops.js +++ b/module-exercises/loops.js @@ -95,7 +95,6 @@ evaluate(example_blockScopeInLoops); once you understand this, you can refactor any loop no matter how complicated the logic */ - function loopRefactor1() { let whileResult = 0; @@ -107,30 +106,29 @@ function loopRefactor1() { // fix the three pieces of this for loop to pass the assert let forResult = 0; - for (let i = 0 ; i !== 8 ; i+=2) { + for (let i = 0 ; i !== 8 ; i += 2) { forResult += i; } - console.assert(forResult === whileResult, 'both loops should have the same behavior'); + console.assert(forResult === whileResult,'both loops should have the same behavior'); } evaluate(loopRefactor1); - 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'); @@ -150,7 +148,7 @@ function loopRefactor1() { // 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; } @@ -170,7 +168,10 @@ function loopRefactor3() { }; // refactor the while loop into a for loop - let forResult = null; + let forResult = .5; + for (x=9 ; x>2 ; x--){ + forResult *= x; + } console.assert(forResult === whileResult, 'both loops should have the same behavior'); @@ -188,8 +189,10 @@ function loopRefactor4() { }; // refactor the while loop into a for loop - let forResult = null; - + let forResult = -1; + for (x= -1 ; x<2 ; x++){ + forResult = forResult && Boolean(x); + } console.assert(forResult === whileResult, 'both loops should have the same behavior'); } @@ -205,6 +208,11 @@ function loopRefactor5() { // 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'); @@ -222,6 +230,13 @@ function loopRefactor6() { // 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'); @@ -239,15 +254,15 @@ evaluate(loopRefactor6); // replace the null's to pass these tests const loopTests1 = [ - { name: 'first', args: [], expected: [0, 4, 16, 56] }, + { name: 'first', args: [], expected: [0, 4, 16, 52] }, ]; function while1() { const result = []; let i = 0; - while (null) { + while (i<32) { result.push(i * 2); - null; + i = 3*i+2; } return result; } @@ -255,7 +270,7 @@ evaluate(while1, loopTests1); function for1() { const result = []; - for (let i = 0; null; null) { + for (let i = 0; i<32; i=3*i+2) { result.push(i * 2); } return result; diff --git a/module-exercises/statements-vs-expressions.js b/module-exercises/statements-vs-expressions.js index f066999..f2593eb 100644 --- a/module-exercises/statements-vs-expressions.js +++ b/module-exercises/statements-vs-expressions.js @@ -61,11 +61,11 @@ const sharedTests = [ { 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, 1], expected: 'truthy' }, + { name: 'seventh', args: [NaN, 0], expected: 'falsey' }, + { name: 'eighth', args: [NaN, null], expected: 'falsey' }, + { name: 'ninth', args: ['a', 'b'], expected: 'truthy' }, + { name: 'tenth', args: ['0', NaN], expected: 'truthy' }, ]; function ternaryExpression(a, b) { diff --git a/week-2-project/scripts/leftpad.js b/week-2-project/scripts/leftpad.js index 01e48bb..f5fb4ac 100644 --- a/week-2-project/scripts/leftpad.js +++ b/week-2-project/scripts/leftpad.js @@ -27,66 +27,28 @@ const leftpadTests = [ ]; function leftpad(str, len, pad) { - // I need to know the given word length const strLength = str.length; - // I need to know the given pad word length const padLength = pad.length; - - // If the desired word length is zero if (len === 0) { - // Then I return an empty word (string). Here ends. - return ''; - } - - // If the given word length is equals to the desired word length - if (strLength === len) { - // Then I just return the word given. Here ends. + return ''; + }if (strLength === len) { return str; - } - // otherwise, If desired word length is less than the given word length - else if (len < strLength) { - // Then I return part of the given word. - // With the method substring > Starting from the character zero to the desired word length + } else if (len < strLength) { return str.substring(0, len); - } - - // Here I already know that the desired word length is greater than the given word length - // Then I need to build my left pad - // So I start with an empty string - let padStr = ''; - // I calculate what length the left pad should be - const leftPadLength = len - strLength; - - // So probably the pad given fits entirely one or more times in the length calculated before - // I need to know the integer number from the division of the left pad length between the - // pad given length. Math.floor method help me to do that - const howManyTimesPadFits = Math.floor(leftPadLength / padLength); - - // Then I iterate the number of times the pad can fit and append it to the empty string - // I set before - for (let i = 1; i <= howManyTimesPadFits; i = i + 1) { + } let padStr = ''; + const leftPadLength = len - strLength; + const howManyTimesPadFits = Math.floor(leftPadLength / padLength); + for (let i = 1; i <= howManyTimesPadFits; i = i + 1) { padStr = padStr + pad; } - - // And probably there will be left some characters to complete my left pad length - // So I need to know the remainder from the division - // With module operator (%) I can do it const howManyCharFromPadNeededToComplete = leftPadLength % padLength; - // Know I need to get those characters from the pad word given, but I need to get them - // starting from the last. - // With the method substring > I can start from the last character doing the operation - // (word length - number characters to get) > - // https://stackoverflow.com/questions/5873810/how-can-i-get-last-characters-of-a-string const charsNeeded = pad.substring(padLength - howManyCharFromPadNeededToComplete); - // Almost done, now I prepend chars needed to complete to my left Pad string padStr = charsNeeded + padStr; - // Finally I prepend the left pad string to the word given const leftPaddedStr = padStr + str; - // And return the string built return leftPaddedStr; } @@ -107,7 +69,7 @@ function leftpadHandler() { 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); + const leftpadded = leftpad(str, len, pad); // report result to user (this works, no need to change it!) const outputField = document.getElementById('leftpad-output'); diff --git a/week-3-project/handlers/scramble.js b/week-3-project/handlers/scramble.js index 114c5ea..f93a0cd 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 = 'write me!'; + const scrambled = scramble(toScramble); // report result to user (this works, no need to change it!) const outputField = document.getElementById('scramble-output'); diff --git a/week-3-project/logic/chunk.js b/week-3-project/logic/chunk.js index 0af0e05..b2b2131 100644 --- a/week-3-project/logic/chunk.js +++ b/week-3-project/logic/chunk.js @@ -42,7 +42,39 @@ const chunkTests = [ { name: 'second', args: [secondArg], expected: secondExpected }, { name: 'second', args: [thirdArg], expected: thirdExpected }, ]; + + function chunk(str) { - // write me! + function findGroup(a) { + let groupOfCharacter; + let nmr = a.charCodeAt(0); + 65 <= nmr && nmr <= 90 + ? (groupOfCharacter = "strGroup") + : 97 <= nmr && nmr <= 122 + ? (groupOfCharacter = "strGroup") + : nmr == 32 + ? (groupOfCharacter = "strGroup") + : 48 <= nmr && nmr <= 57 + ? (groupOfCharacter = "strGroup") + : (groupOfCharacter = "nonstrGroup"); + return groupOfCharacter; + } + let chunkArr = []; + let tmpArr = str.split(""); + let strOfchunk = ""; + let strArr = tmpArr.map(function(e, i, a) { + if (i === 0) { + strOfchunk = e; + } else if (findGroup(e) === findGroup(a[i - 1])) { + strOfchunk += e; + } else { + chunkArr.push(strOfchunk); + //console.log(chunkArr); + strOfchunk = e; + } + }); + chunkArr.push(strOfchunk); + return chunkArr; } + evaluate(chunk, chunkTests); diff --git a/week-3-project/logic/reverse-chunk.js b/week-3-project/logic/reverse-chunk.js index b7cd931..c3b28a5 100644 --- a/week-3-project/logic/reverse-chunk.js +++ b/week-3-project/logic/reverse-chunk.js @@ -11,11 +11,36 @@ const reverseChunkTests = [ { name: 'first', args: [' plug (play!)'], expected: ' (play!) plug' }, { name: 'second', args: [' -- - '], expected: ' - -- ' }, { name: 'third', args: ['12 34 '], expected: '34 12 ' }, - { name: 'fourth', args: ['const x = null; '], expected: 'null = x const ' }, + { name: 'fourth', args: ['const x = null; '], expected: 'null; = x const ' }, { name: 'fifth', args: [' e e '], expected: ' e e ' }, ]; function reverseChunk(str) { - // write me! + let strSplit= str.split(' '); + let i,n,k; + let strArr1 =[]; //create an empty array + let strArr2 =[]; //create an empty array + let m = 0 + for(i=0;i Date: Sat, 26 Oct 2019 01:12:01 +0200 Subject: [PATCH 37/38] for loop line 59 to 65 updated --- week-3-project/logic/scramble.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/week-3-project/logic/scramble.js b/week-3-project/logic/scramble.js index adb6cfe..40d3bbe 100644 --- a/week-3-project/logic/scramble.js +++ b/week-3-project/logic/scramble.js @@ -53,13 +53,15 @@ const scrambleTests = [ strArr1[i] = '-' }else if(strSplit[i]==';'){ strArr1[i] = ';' + }else if(strSplit[i]=="'"){ + strArr1[i] = "'" }else if(strSplit[i]==':'){ strArr1[i] = ':' }else if(strSplit[i]=='.'){ strArr1[i] = '.' - }else if(strSplit[i]!==''||'-'||';'||':'||'.'){ // else copy original array into array2 + }else { // else copy original array into array2 strArr2[m] = strSplit[i] - strArr1[i] = 'a' // to check the index of " " assign a letter to array1 + strArr1[i] = 'a' // to check the index of special character assign a letter to array1 m = m + 1 } } From 261a4a015ea88e504153bc657efa98fb170f36ba Mon Sep 17 00:00:00 2001 From: Mert Demirok Date: Sat, 26 Oct 2019 11:41:43 +0200 Subject: [PATCH 38/38] for, else if loops and test cases updated --- week-3-project/logic/scramble.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/week-3-project/logic/scramble.js b/week-3-project/logic/scramble.js index 40d3bbe..af4c2cc 100644 --- a/week-3-project/logic/scramble.js +++ b/week-3-project/logic/scramble.js @@ -17,12 +17,12 @@ const thirdScrambleExpected = `diknrs fo ilst a: - acesu osy`; const scrambleTests = [ - { name: 'first', args: ['the road works.'], expected: 'korsw ador eht.' }, - { name: 'second', args: ["name: 'second'"], expected: "aemn: 'cednos'" }, + { name: 'first', args: ['the road works.'], expected: 'eht ador korsw.' }, + { name: 'second', args: ["name: 'second'"], expected: "aemn: 'cdenos'" }, { name: 'third', args: [thirdScrambleArg], expected: thirdScrambleExpected }, - { name: 'fourth', args: ["name: 'second cow'"], expected: "aemn: 'cow cednos'" }, - { name: 'fifth', args: ["name e eman: 'second cow, cba'"], expected: "aemn e aemn: 'cow cednos, cba'" }, -]; + { name: 'fourth', args: ["name: 'second cow'"], expected: "aemn: 'cdenos cow'" }, + { name: 'fifth', args: ["name e eman: 'second cow, cba'"], expected: "aemn e aemn: 'cdenos cow, abc'" }, +]; function sort(str){ //this function sorts the given string taking into account the strings @@ -57,6 +57,8 @@ const scrambleTests = [ strArr1[i] = "'" }else if(strSplit[i]==':'){ strArr1[i] = ':' + }else if(strSplit[i]==','){ + strArr1[i] = ',' }else if(strSplit[i]=='.'){ strArr1[i] = '.' }else { // else copy original array into array2 @@ -65,7 +67,7 @@ const scrambleTests = [ m = m + 1 } } - strArr2.reverse() // reverse the array2 which does not include special characters (' ', ':', ';', '-', '.') + // strArr2.reverse() // reverse the array2 which does not include special characters (' ', ':', ';', '-', '.') // console.log(strArr2); let strArr3=strArr2.join(''); // in order to use sort function we should join the array into string // console.log(strArr3);