diff --git a/.DS_Store b/.DS_Store index 19f35c2d4..abe5d4347 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/Week3/homework/js-exercises/ex1-AddSix.js b/Week3/homework/js-exercises/ex1-AddSix.js new file mode 100644 index 000000000..62a979912 --- /dev/null +++ b/Week3/homework/js-exercises/ex1-AddSix.js @@ -0,0 +1,16 @@ +'use strict'; + +function createBase(baseNum) { + + function sum(num) { + console.log(baseNum + num); + } + return sum; //function createBase returns a closure that adds num to baseNum + +} + +const addSix = createBase(6); + +addSix(9); +addSix(18); +addSix(30); \ No newline at end of file diff --git a/Week3/homework/js-exercises/ex2-RemoveDuplicates.js b/Week3/homework/js-exercises/ex2-RemoveDuplicates.js new file mode 100644 index 000000000..764631591 --- /dev/null +++ b/Week3/homework/js-exercises/ex2-RemoveDuplicates.js @@ -0,0 +1,7 @@ +'use strict'; + + +const letters = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c', 'b']; +const removeDuplicates = arr => [...new Set(arr)]; + +console.log(removeDuplicates(letters)); \ No newline at end of file diff --git a/Week3/homework/js-exercises/ex3-GuessTheOutput.js b/Week3/homework/js-exercises/ex3-GuessTheOutput.js new file mode 100644 index 000000000..5f7237f74 --- /dev/null +++ b/Week3/homework/js-exercises/ex3-GuessTheOutput.js @@ -0,0 +1,13 @@ +'use strict'; + +//the output would be 12. The returning function will be returned as closure. So it will use the 'variable a' from its outer function which has been assigned a new value(12). + +let a = 10; +const x = (function () { + a = 12; + return function () { + alert(a); + }; +})(); + +x(); \ No newline at end of file diff --git a/Week3/homework/js-exercises/ex4-GuessMore.js b/Week3/homework/js-exercises/ex4-GuessMore.js new file mode 100644 index 000000000..b2207df4c --- /dev/null +++ b/Week3/homework/js-exercises/ex4-GuessMore.js @@ -0,0 +1,20 @@ +'use strict'; +const x = 9; + +function f1(val) { + val = val + 1; + return val; +} +f1(x); +console.log(x); //prints 9, because x is assigned a new value in the function(local) not in global scope + +const y = { + x: 9 +}; + +function f2(val) { + val.x = val.x + 1; + return val; +} +f2(y); +console.log(y); //prints {x:10}, due to its an object; the changes on variable y will affect the y in global scope \ No newline at end of file diff --git a/Week3/homework/js-exercises/ex5-LotteryMachine.js b/Week3/homework/js-exercises/ex5-LotteryMachine.js new file mode 100644 index 000000000..eda513141 --- /dev/null +++ b/Week3/homework/js-exercises/ex5-LotteryMachine.js @@ -0,0 +1,38 @@ +'use strict'; + +function threeFive(startIndex, stopIndex, threeCallback, fiveCallback) { + const numbers = []; + for (let indis = startIndex; indis <= stopIndex; indis++) { + numbers.push(indis); + } + console.log(numbers); + numbers.forEach(function (indis) { + if (indis % 15 === 0) { + // console.log('five and three'); + // console.log(indis); + threeCallback(); + fiveCallback(); + } else if (indis % 5 === 0) { + // console.log(indis); + // console.log('only five'); + fiveCallback(); + + } else if (indis % 3 === 0) { + // console.log(indis); + // console.log('only three') + threeCallback(); + } + }); + +} +const sayThree = function () { + console.log('sayThree callback called'); +} + +const sayFive = function () { + console.log('sayFive callback called'); +} +threeFive(10, 15, sayThree, sayFive); + +// Should create an array [10,11,12,13,14,15] +// and call sayFive, sayThree, sayThree, sayFive \ No newline at end of file diff --git a/Week3/homework/project/app.js b/Week3/homework/project/app.js new file mode 100644 index 000000000..a726efc43 --- /dev/null +++ b/Week3/homework/project/app.js @@ -0,0 +1 @@ +'use strict'; \ No newline at end of file diff --git a/Week3/homework/project/index.html b/Week3/homework/project/index.html new file mode 100644 index 000000000..67ddea3a6 --- /dev/null +++ b/Week3/homework/project/index.html @@ -0,0 +1,41 @@ + + + + + + + Document + + + + +
+

TIP CALCULATOR

+
+
+
+
+
+
+
+ +
+

TIP AMOUNT

+

+

each

+
+ + + + + + + + \ No newline at end of file diff --git a/Week3/homework/project/style.css b/Week3/homework/project/style.css new file mode 100644 index 000000000..9fb91198c --- /dev/null +++ b/Week3/homework/project/style.css @@ -0,0 +1,23 @@ +* { + margin: 0; + padding: 0; +} + +body { + background-color: #68150B; + display: flex; + align-items: center; + justify-content: center; + height: 100%; +} + +.main-container { + text-align: left; + padding: 3%; + width: 30%; + height: 70%; + margin: auto; + background-color: white; + font-size: 1.3em; + border-radius: 25px; +} \ No newline at end of file