Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Week3 homework structure #525

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Week3/MAKEME.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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:

Expand All @@ -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!**
Expand Down
20 changes: 20 additions & 0 deletions Week3/js-exercises/ex1-AddSix.js
Original file line number Diff line number Diff line change
@@ -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());
21 changes: 21 additions & 0 deletions Week3/js-exercises/ex2-RemoveDuplicates.js
Original file line number Diff line number Diff line change
@@ -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!")
21 changes: 21 additions & 0 deletions Week3/js-exercises/ex3-GuessTheOutput.js
Original file line number Diff line number Diff line change
@@ -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();
29 changes: 29 additions & 0 deletions Week3/js-exercises/ex4-GuessMore.js
Original file line number Diff line number Diff line change
@@ -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);
38 changes: 38 additions & 0 deletions Week3/js-exercises/ex5-LotteryMachine.js
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions Week3/project/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tip Calculator</title>
</head>

<body>
<div id="app"></div>
<script src="index.js"></script>
</body>

</html>
3 changes: 3 additions & 0 deletions Week3/project/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Your code goes in here

document.querySelector("#app").innerText = "Tip Calculator";