diff --git a/Week3/MAKEME.md b/Week3/MAKEME.md index 82369403c..afc8f883f 100644 --- a/Week3/MAKEME.md +++ b/Week3/MAKEME.md @@ -15,11 +15,11 @@ Let's get familiar with basic Javascript concepts, with interactive exercises! C ## **2. JavaScript exercises** -> Inside of your `JavaScript2` fork, create a folder called `week3`. Inside of that folder, create a folder called `js-exercises`. For all the following exercises create a new `.js` file in that folder (5 files in total). Make sure the name of each file reflects its content: for example, the filename for exercise one could be `addSix.js`. +> Inside of your `JavaScript2` fork, navigate to the folder `Week3`. Then to the folder `js-exercises`. In this folder you will find separate files for each exercise. Please put your code in the correct file. **Exercise 1: Add six** -Declare a function called `createBase`. It should return a closure, that adds a number to the base number argument. +Declare a function called `createBase`. The function takes a number as a parameter and return a closure, that adds a number to the base number argument. Call the function three times. The return values should be: @@ -142,7 +142,7 @@ Happy learning! > Every week ends with a project you have to build on your own. Instead of getting clear-cut instructions, you'll get a list of criteria that your project needs to measure up to. -> Before you start, create a new folder called `project` that includes the files for the following app you'll be building. +> Important! Place your code in the folder `Week3 \ project`. In this week's project you'll be making a Tip Calculator! A user can fill in 3 things: @@ -167,6 +167,8 @@ Here are the requirements: - If there's only 1 person who shares the bill, output only the tip amount (omit the "each") - If any of the input fields are empty when the button is clicked, call an alert that says: "You need to fill in all the fields!" +See it in action [here](https://tipcalculator-sandbox.mxapps.io/). + Good luck! ## **SUBMIT YOUR HOMEWORK!** diff --git a/Week3/js-exercises/ex1-AddSix.js b/Week3/js-exercises/ex1-AddSix.js new file mode 100644 index 000000000..a801a72fd --- /dev/null +++ b/Week3/js-exercises/ex1-AddSix.js @@ -0,0 +1,20 @@ +/** + + ** Exercise 1: Add Six ** + +Declare a function called `createBase`.The function takes a number as a parameter and +return a closure, that adds a number to the base number argument. + +Call the function three times. The return values should be: + 15, 24, 36 + + */ + +function createBase( /* ???? */ ) { + // Put here your logic... +} + +const addSix = createBase(6); + +// Put here your function calls... +console.log(addSix()); \ No newline at end of file diff --git a/Week3/js-exercises/ex2-RemoveDuplicates.js b/Week3/js-exercises/ex2-RemoveDuplicates.js new file mode 100644 index 000000000..aa9d0d7d0 --- /dev/null +++ b/Week3/js-exercises/ex2-RemoveDuplicates.js @@ -0,0 +1,21 @@ +/** + + ** Exercise 2: The lottery machine ** + +Write a function called removeDuplicates. This function accept an array as an argument +does not return anything but removes any duplicate elements from the array. + + The function should remove duplicate elements.So the result should be: + + + */ + + +// WRITE YOUR FUNCTION HERE + +const letters = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c', 'b']; + +removeDuplicates(letter); + +if (letters === ['a', 'b', 'c', 'd', 'e', 'f']) + console.log("Hooray!") \ No newline at end of file diff --git a/Week3/js-exercises/ex3-GuessTheOutput.js b/Week3/js-exercises/ex3-GuessTheOutput.js new file mode 100644 index 000000000..7d783ceef --- /dev/null +++ b/Week3/js-exercises/ex3-GuessTheOutput.js @@ -0,0 +1,21 @@ +/** + +** Exercise 3: Guess the output ** + +Look at the bellow code snippet. +Can you guess the output? +Write out your reasoning in 50 words or less. + +*/ + + + +let a = 10; +const x = (function () { + a = 12; + return function () { + alert(a); + }; +})(); + +x(); \ No newline at end of file diff --git a/Week3/js-exercises/ex4-GuessMore.js b/Week3/js-exercises/ex4-GuessMore.js new file mode 100644 index 000000000..81a4ec273 --- /dev/null +++ b/Week3/js-exercises/ex4-GuessMore.js @@ -0,0 +1,29 @@ +/** + +** Exercise 4: Guess more ** + +Look at the bellow code snippet. +Can you guess the output? +Write out your reasoning in 50 words or less. + +*/ + +const x = 9; + +function f1(val) { + val = val + 1; + return val; +} +f1(x); +console.log(x); + +const y = { + x: 9 +}; + +function f2(val) { + val.x = val.x + 1; + return val; +} +f2(y); +console.log(y); \ No newline at end of file diff --git a/Week3/js-exercises/ex5-LotteryMachine.js b/Week3/js-exercises/ex5-LotteryMachine.js new file mode 100644 index 000000000..ad09b963c --- /dev/null +++ b/Week3/js-exercises/ex5-LotteryMachine.js @@ -0,0 +1,38 @@ +/** + + ** Exercise 5: The lottery machine ** + +Don't you just love the thrill of the lottery? What if I told you we can make our own lottery machine? Let' + s get started! + + Write a + function that takes 4 arguments. + + - A start value + - An end value + - A callback that executes if the number is divisible by 3 + - A callback that executes if the number is divisible by 5 + + The function should first generate an array containing values from start value to end value(inclusive). + + Then the function should take the newly created array and iterate over it, and calling the first callback + if the array value is divisible by 3. + + The function should call the second callback + if the array value is divisible by 5. + + Both functions should be called + if the array value is divisible by both 3 and 5. + +*/ + +function threeFive(startIndex, stopIndex, threeCallback, fiveCallback) { + const numbers = []; + // make array + // start at beginning of array and check if you should call threeCallback or fiveCallback or go on to next +} + +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/step2-1.js b/Week3/old-homework/step2-1.js similarity index 100% rename from Week3/homework/step2-1.js rename to Week3/old-homework/step2-1.js diff --git a/Week3/homework/step2-2.js b/Week3/old-homework/step2-2.js similarity index 100% rename from Week3/homework/step2-2.js rename to Week3/old-homework/step2-2.js diff --git a/Week3/homework/step2-3.js b/Week3/old-homework/step2-3.js similarity index 100% rename from Week3/homework/step2-3.js rename to Week3/old-homework/step2-3.js diff --git a/Week3/homework/step2-4.js b/Week3/old-homework/step2-4.js similarity index 100% rename from Week3/homework/step2-4.js rename to Week3/old-homework/step2-4.js diff --git a/Week3/homework/step2-5.js b/Week3/old-homework/step2-5.js similarity index 100% rename from Week3/homework/step2-5.js rename to Week3/old-homework/step2-5.js diff --git a/Week3/homework/step2-6.js b/Week3/old-homework/step2-6.js similarity index 100% rename from Week3/homework/step2-6.js rename to Week3/old-homework/step2-6.js diff --git a/Week3/homework/step2-7.js b/Week3/old-homework/step2-7.js similarity index 100% rename from Week3/homework/step2-7.js rename to Week3/old-homework/step2-7.js diff --git a/Week3/homework/step3-bonus.js b/Week3/old-homework/step3-bonus.js similarity index 100% rename from Week3/homework/step3-bonus.js rename to Week3/old-homework/step3-bonus.js diff --git a/Week3/homework/step3.js b/Week3/old-homework/step3.js similarity index 100% rename from Week3/homework/step3.js rename to Week3/old-homework/step3.js diff --git a/Week3/project/index.html b/Week3/project/index.html new file mode 100644 index 000000000..fac819b21 --- /dev/null +++ b/Week3/project/index.html @@ -0,0 +1,15 @@ + + + +
+ + +