diff --git a/Week1/homework/app.js b/Week1/homework/app.js index a9b5f75d8..e69de29bb 100644 --- a/Week1/homework/app.js +++ b/Week1/homework/app.js @@ -1,11 +0,0 @@ -'use strict'; - -{ - const bookTitles = [ - // Replace with your own book titles - 'harry_potter_chamber_secrets', - ]; - - // Replace with your own code - console.log(bookTitles); -} diff --git a/Week1/homework/index.html b/Week1/homework/index.html index b22147cd1..e69de29bb 100644 --- a/Week1/homework/index.html +++ b/Week1/homework/index.html @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/Week1/homework/style.css b/Week1/homework/style.css index bab13ec23..e69de29bb 100644 --- a/Week1/homework/style.css +++ b/Week1/homework/style.css @@ -1 +0,0 @@ -/* add your styling here */ \ No newline at end of file diff --git a/Week3/homework/step2-1.js b/Week3/homework/step2-1.js index d5699882c..28fa47a4b 100644 --- a/Week3/homework/step2-1.js +++ b/Week3/homework/step2-1.js @@ -1,9 +1,7 @@ 'use strict'; function foo(func) { - // What to do here? - // Replace this comment and the next line with your code - console.log(func); + func(); } function bar() { diff --git a/Week3/homework/step2-2.js b/Week3/homework/step2-2.js index dcd135040..e17f1cbcc 100644 --- a/Week3/homework/step2-2.js +++ b/Week3/homework/step2-2.js @@ -1,22 +1,32 @@ 'use strict'; -function threeFive(startIndex, stopIndex, threeCallback, fiveCallback) { - const numbers = []; - - // Replace this comment and the next line with your code - console.log(startIndex, stopIndex, threeCallback, fiveCallback, numbers); -} - function sayThree(number) { - // Replace this comment and the next line with your code console.log(number); } function sayFive(number) { - // Replace this comment and the next line with your code console.log(number); } +function threeFive(startIndex, stopIndex, threeCallback, fiveCallback) { + const numbers = []; + let numbersStart = startIndex; + const numbersEnd = stopIndex; + while (numbersStart <= numbersEnd) { + numbers.push(numbersStart); + numbersStart++; + } + for (let i = 0; i < numbers.length; i++) { + const number = numbers[i]; + if (number % 3 === 0) { + threeCallback(number); + } + if (number % 5 === 0) { + fiveCallback(number); + } + } +} + threeFive(10, 15, sayThree, sayFive); // Do not change or remove anything below this line diff --git a/Week3/homework/step2-3.js b/Week3/homework/step2-3.js index 00845c5eb..5d1b4c946 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,10 +16,11 @@ 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 counter = 0; + while (counter < num) { + result += str; + counter++; + } return result; } @@ -30,14 +30,17 @@ console.log('while', repeatStringNumTimesWithWhile('abc', 3)); function repeatStringNumTimesWithDoWhile(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; + if (num > 0) { + do { + result += str; + i++; + } while (i < num); + } return result; } -console.log('do-while', repeatStringNumTimesWithDoWhile('abc', 3)); +console.log('do-while', repeatStringNumTimesWithDoWhile('abc', 0)); // Do not change or remove anything below this line module.exports = { diff --git a/Week3/homework/step2-4.js b/Week3/homework/step2-4.js index b11b1dcb6..84dba14ec 100644 --- a/Week3/homework/step2-4.js +++ b/Week3/homework/step2-4.js @@ -1,7 +1,9 @@ 'use strict'; function Dog() { - // add your code here + this.name = 'Fido'; + this.color = 'white and brown'; + this.numLegs = 4; } const hound = new Dog(); diff --git a/Week3/homework/step2-5.js b/Week3/homework/step2-5.js index cbb54fa1d..36e926c99 100644 --- a/Week3/homework/step2-5.js +++ b/Week3/homework/step2-5.js @@ -4,8 +4,11 @@ function multiplyAll(arr) { // eslint-disable-next-line let product = 1; - // Replace this comment and the next line with your code - console.log(arr, product); + for (let i = 0; i < arr.length; i++) { + for (let j = 0; j < arr[i].length; j++) { + product = product * arr[i][j]; + } + } return product; } diff --git a/Week3/homework/step2-6.js b/Week3/homework/step2-6.js index ffe95b9f7..758c0ad5b 100644 --- a/Week3/homework/step2-6.js +++ b/Week3/homework/step2-6.js @@ -4,13 +4,25 @@ 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); + const newArray = []; + for (let i = 0; i < arr.length; i++) { + for (let j = 0; j < arr[i].length; j++) { + newArray.push(arr[i][j]); + } + } + return newArray.sort(); } function flattenArray3d(arr) { - // Replace this comment and the next line with your code - console.log(arr); + const arr3dim = []; + for (let i = 0; i < arr.length; i++) { + for (let j = 0; j < arr[i].length; j++) { + for (let k = 0; k < arr[i][j].length; k++) { + arr3dim.push(arr[i][j][k]); + } + } + } + return arr3dim; } console.log(flattenArray2d(arr2d)); // -> [1, 2, 3, 4, 5, 6] diff --git a/Week3/homework/step2-7.js b/Week3/homework/step2-7.js index 3e72e8551..c18ceaedf 100644 --- a/Week3/homework/step2-7.js +++ b/Week3/homework/step2-7.js @@ -20,4 +20,8 @@ f2(y); console.log(y); -// Add your explanation as a comment here +/* In the x-code, we are logging the value of x, which has not changed. If we want this code to return 10, +we need to console.log(f1(x)). In the y-code, y is an object. The properties of an object can be altered this way, +so the function changes the value of x to 10. No alteration has been done to the variable reference itself. If f2 +attempted to change the *value* of y (rather than an attribute of its object), it would yield results like the x-code. +For example, if the function is altered, val = { x: 10 }; return val;, it will return { x: 9 } */ diff --git a/Week3/homework/step3-bonus.js b/Week3/homework/step3-bonus.js index 917091d61..11d80a606 100644 --- a/Week3/homework/step3-bonus.js +++ b/Week3/homework/step3-bonus.js @@ -3,8 +3,10 @@ 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); + const newArray = arr.filter(function(index, current) { + return arr.indexOf(index) === current; + }); + return newArray; } const uniqueValues = makeUnique(values); diff --git a/Week3/homework/step3.js b/Week3/homework/step3.js index 292724bf4..a9f30e4de 100644 --- a/Week3/homework/step3.js +++ b/Week3/homework/step3.js @@ -1,14 +1,17 @@ 'use strict'; function createBase(base) { - // Replace this comment and the next line with your code - console.log(base); + return function(number) { + return number + base; + }; } const addSix = createBase(6); +const addSeven = createBase(7); console.log(addSix(10)); // returns 16 console.log(addSix(21)); // returns 27 +console.log(addSeven(21)); // returns 28 // Do not change or remove anything below this line module.exports = createBase; diff --git a/package-lock.json b/package-lock.json index e89e9916d..2b047f93a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2221,12 +2221,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -2241,17 +2243,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -2368,7 +2373,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -2380,6 +2386,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -2394,6 +2401,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -2401,12 +2409,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.2.4", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -2425,6 +2435,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -2505,7 +2516,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -2517,6 +2529,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -2638,6 +2651,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0",