From 69c7ee002d4df46076edb5d41155e7a64c5757ed Mon Sep 17 00:00:00 2001 From: Lisa Smeke Date: Wed, 15 Jun 2022 11:10:00 +0200 Subject: [PATCH 01/10] initial commit --- Week3/homework/index.html | 12 ++++++++++++ Week3/homework/step2-1.js | 6 ++---- 2 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 Week3/homework/index.html diff --git a/Week3/homework/index.html b/Week3/homework/index.html new file mode 100644 index 000000000..f8f6f8dc0 --- /dev/null +++ b/Week3/homework/index.html @@ -0,0 +1,12 @@ + + + + + + + Document + + + + + \ No newline at end of file diff --git a/Week3/homework/step2-1.js b/Week3/homework/step2-1.js index d5699882c..2eb02309e 100644 --- a/Week3/homework/step2-1.js +++ b/Week3/homework/step2-1.js @@ -1,16 +1,14 @@ 'use strict'; function foo(func) { - // What to do here? - // Replace this comment and the next line with your code - console.log(func); + console.log('Hi bar!'); } function bar() { console.log('Hello, I am bar!'); } -foo(bar); +foo(bar()); // Do not change or remove anything below this line module.exports = foo; From 656ef56e460ea5f6b3456d4eb90e8696a3e906cd Mon Sep 17 00:00:00 2001 From: Lisa Smeke Date: Wed, 15 Jun 2022 13:20:00 +0200 Subject: [PATCH 02/10] Solves step 2-2 --- Week3/homework/index.html | 8 ++++++++ Week3/homework/step2-2.js | 19 ++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Week3/homework/index.html b/Week3/homework/index.html index f8f6f8dc0..ab94153d9 100644 --- a/Week3/homework/index.html +++ b/Week3/homework/index.html @@ -8,5 +8,13 @@ + + + + + + + + \ No newline at end of file diff --git a/Week3/homework/step2-2.js b/Week3/homework/step2-2.js index dcd135040..a74694466 100644 --- a/Week3/homework/step2-2.js +++ b/Week3/homework/step2-2.js @@ -1,23 +1,24 @@ 'use strict'; function threeFive(startIndex, stopIndex, threeCallback, fiveCallback) { - const numbers = []; + const numbers = [...Array(stopIndex - startIndex + 1).keys()].map(x => x + startIndex); + console.log(numbers); - // Replace this comment and the next line with your code - console.log(startIndex, stopIndex, threeCallback, fiveCallback, numbers); + numbers.forEach(number => { + if (number % 3 === 0) threeCallback(number); + if (number % 5 === 0) fiveCallback(number); + }); } function sayThree(number) { - // Replace this comment and the next line with your code - console.log(number); + console.log(`${number} is divisible by 3 🧮`); } function sayFive(number) { - // Replace this comment and the next line with your code - console.log(number); + console.log(`${number} is divisible by 5 🧮`); } - threeFive(10, 15, sayThree, sayFive); +threeFive(9, 22, sayThree, sayFive); // Do not change or remove anything below this line -module.exports = threeFive; +module.exports = threeFive; \ No newline at end of file From c48699f550f1ff987cca9ef5575fb2acee584133 Mon Sep 17 00:00:00 2001 From: Lisa Smeke Date: Wed, 15 Jun 2022 13:56:24 +0200 Subject: [PATCH 03/10] Solves freeCodeCamp Repeat String exercise --- Week3/homework/index.html | 2 +- Week3/homework/step2-3.js | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Week3/homework/index.html b/Week3/homework/index.html index ab94153d9..63f487cc1 100644 --- a/Week3/homework/index.html +++ b/Week3/homework/index.html @@ -8,7 +8,7 @@ - + diff --git a/Week3/homework/step2-3.js b/Week3/homework/step2-3.js index 00845c5eb..a8bd2268f 100644 --- a/Week3/homework/step2-3.js +++ b/Week3/homework/step2-3.js @@ -4,10 +4,9 @@ function repeatStringNumTimesWithFor(str, num) { // eslint-disable-next-line prefer-const let result = ''; - - // Replace this comment and the next line with your code - console.log(str, num, result); - + for (let i = 0; i < num; i++){ + result += str + ' '; + } return result; } @@ -17,9 +16,12 @@ console.log('for', repeatStringNumTimesWithFor('abc', 3)); function repeatStringNumTimesWithWhile(str, num) { // eslint-disable-next-line prefer-const let result = ''; - - // Replace this comment and the next line with your code - console.log(str, num, result); + let i = 0; + + while (i < num) { + result += str + ' '; + i++; + } return result; } @@ -30,9 +32,13 @@ console.log('while', repeatStringNumTimesWithWhile('abc', 3)); function repeatStringNumTimesWithDoWhile(str, num) { // eslint-disable-next-line prefer-const let result = ''; + let i = 0; - // Replace this comment and the next line with your code - console.log(str, num, result); + do { + result += str + ' '; + i++; + } + while (i < num); return result; } From a3de7b9403e9b252d78b5fe650d74697e608a7c5 Mon Sep 17 00:00:00 2001 From: Lisa Smeke Date: Thu, 16 Jun 2022 11:28:46 +0200 Subject: [PATCH 04/10] Creates Dog object --- Week3/homework/index.html | 10 +++++----- Week3/homework/step2-4.js | 5 ++++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Week3/homework/index.html b/Week3/homework/index.html index 63f487cc1..57b5d0076 100644 --- a/Week3/homework/index.html +++ b/Week3/homework/index.html @@ -7,14 +7,14 @@ Document - + - - + + \ No newline at end of file diff --git a/Week3/homework/step2-4.js b/Week3/homework/step2-4.js index b11b1dcb6..ef4699575 100644 --- a/Week3/homework/step2-4.js +++ b/Week3/homework/step2-4.js @@ -1,10 +1,13 @@ 'use strict'; function Dog() { - // add your code here + this.name = "Firulais"; + this.color = "black"; + this.numLegs = 4; } const hound = new Dog(); +console.log(hound); // Do not change or remove anything below this line module.exports = hound; From 8fc831b36a2c36e0aad986f3bd857edf25c65439 Mon Sep 17 00:00:00 2001 From: Lisa Smeke Date: Thu, 16 Jun 2022 11:59:46 +0200 Subject: [PATCH 05/10] Multiplies nested array --- Week3/homework/index.html | 4 ++-- Week3/homework/step2-5.js | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Week3/homework/index.html b/Week3/homework/index.html index 57b5d0076..ea5a5c60e 100644 --- a/Week3/homework/index.html +++ b/Week3/homework/index.html @@ -10,8 +10,8 @@ - - + + - + + - + \ No newline at end of file diff --git a/Week3/homework/step2-6.js b/Week3/homework/step2-6.js index ffe95b9f7..b5b4248b6 100644 --- a/Week3/homework/step2-6.js +++ b/Week3/homework/step2-6.js @@ -3,14 +3,12 @@ const arr2d = [[1, 2], [3, 4], [5, 6]]; const arr3d = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]; -function flattenArray2d(arr) { - // Replace this comment and the next line with your code - console.log(arr); +function flattenArray2d(arr){ + return arr.flat(); } function flattenArray3d(arr) { - // Replace this comment and the next line with your code - console.log(arr); + return arr.flat(2); } console.log(flattenArray2d(arr2d)); // -> [1, 2, 3, 4, 5, 6] @@ -20,4 +18,4 @@ console.log(flattenArray3d(arr3d)); // -> [1, 2, 3, 4, 5, 6, 7, 8] module.exports = { flattenArray2d, flattenArray3d, -}; +}; \ No newline at end of file From 17a7620d32799b4e9abc951f93ea670bf607946d Mon Sep 17 00:00:00 2001 From: Lisa Smeke Date: Thu, 16 Jun 2022 12:45:09 +0200 Subject: [PATCH 07/10] Explains functions' results --- Week3/homework/step2-7.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Week3/homework/step2-7.js b/Week3/homework/step2-7.js index 3e72e8551..580430662 100644 --- a/Week3/homework/step2-7.js +++ b/Week3/homework/step2-7.js @@ -6,8 +6,6 @@ function f1(val) { return val; } -f1(x); - console.log(x); const y = { x: 9 }; @@ -21,3 +19,7 @@ f2(y); console.log(y); // Add your explanation as a comment here +// The variable in the first function is a number, while the variable in the second function is an object. +// f1 doesn't call the value of x, that's why when we console.log x, we get the value of that constant (9) +// f2 calls the value of x and makes an operation, thus resulting in a new object "{x :10}" + From 30e631191c9f98f09d3b8ef1574299ecdf9cc903 Mon Sep 17 00:00:00 2001 From: Lisa Smeke Date: Thu, 16 Jun 2022 13:04:09 +0200 Subject: [PATCH 08/10] Creates function that adds 6 to any number --- Week3/homework/step3.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Week3/homework/step3.js b/Week3/homework/step3.js index 292724bf4..dfbd7fad4 100644 --- a/Week3/homework/step3.js +++ b/Week3/homework/step3.js @@ -1,8 +1,10 @@ 'use strict'; function createBase(base) { - // Replace this comment and the next line with your code - console.log(base); + function basePlusNum(num) { + return base + num; + } + return basePlusNum; } const addSix = createBase(6); From 5055ce00e638e56755117b7323ae5e10eee5cff8 Mon Sep 17 00:00:00 2001 From: Lisa Smeke Date: Thu, 16 Jun 2022 13:30:17 +0200 Subject: [PATCH 09/10] Writes function that removes duplicates from an array --- Week3/homework/step3-bonus.js | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/Week3/homework/step3-bonus.js b/Week3/homework/step3-bonus.js index 917091d61..7012bfdb6 100644 --- a/Week3/homework/step3-bonus.js +++ b/Week3/homework/step3-bonus.js @@ -1,14 +1,30 @@ 'use strict'; -const values = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c']; - function makeUnique(arr) { - // Replace this comment and the next line with your code - console.log(arr); + let newArr = []; + for (let i = 0; i < arr.length; i++){ + if (newArr.indexOf(arr[i]) === -1) { + newArr.push(arr[i]); + } + } + return newArr; } +const values = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c']; +const names = ['lisa', 'lisa', 'priscilla', 'tania', 'priscilla', 'nadia', 'nadia', 'nadia']; +const numbers = [22, 22, 34, 30, 30, 30, 22, 15, 12, 29, 29, 28, 29]; + + const uniqueValues = makeUnique(values); -console.log(uniqueValues); +const uniqueNames = makeUnique(names); +const uniqueNumbers = makeUnique(numbers); + +console.log(uniqueValues, uniqueNames, uniqueNumbers); + + +// Another SHORTER option is: +// let newArr = [... new Set(arr)]; +// return newArr; // Do not change or remove anything below this line -module.exports = makeUnique; +module.exports = makeUnique; \ No newline at end of file From 43bebfe6a81ee54d79d2036cbe4d7ac9df0d2b93 Mon Sep 17 00:00:00 2001 From: Lisa Smeke Date: Thu, 16 Jun 2022 13:47:08 +0200 Subject: [PATCH 10/10] Deletes space --- Week3/homework/step2-3.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Week3/homework/step2-3.js b/Week3/homework/step2-3.js index a8bd2268f..10431f598 100644 --- a/Week3/homework/step2-3.js +++ b/Week3/homework/step2-3.js @@ -5,7 +5,7 @@ function repeatStringNumTimesWithFor(str, num) { // eslint-disable-next-line prefer-const let result = ''; for (let i = 0; i < num; i++){ - result += str + ' '; + result += str; } return result; } @@ -19,7 +19,7 @@ function repeatStringNumTimesWithWhile(str, num) { let i = 0; while (i < num) { - result += str + ' '; + result += str; i++; }