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

Skip to content

Commit 271c521

Browse files
authored
Merge pull request HackYourFuture#525 from gajduk-mansystems/week3-homework-structure
Week3 homework structure
2 parents e2e658f + 1ac29a7 commit 271c521

17 files changed

+152
-3
lines changed

Week3/MAKEME.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ Let's get familiar with basic Javascript concepts, with interactive exercises! C
1515

1616
## **2. JavaScript exercises**
1717

18-
> 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`.
18+
> 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.
1919
2020
**Exercise 1: Add six**
2121

22-
Declare a function called `createBase`. It should return a closure, that adds a number to the base number argument.
22+
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.
2323

2424
Call the function three times. The return values should be:
2525

@@ -142,7 +142,7 @@ Happy learning!
142142

143143
> 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.
144144
145-
> Before you start, create a new folder called `project` that includes the files for the following app you'll be building.
145+
> Important! Place your code in the folder `Week3 \ project`.
146146
147147
In this week's project you'll be making a Tip Calculator! A user can fill in 3 things:
148148

@@ -167,6 +167,8 @@ Here are the requirements:
167167
- If there's only 1 person who shares the bill, output only the tip amount (omit the "each")
168168
- 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!"
169169

170+
See it in action [here](https://tipcalculator-sandbox.mxapps.io/).
171+
170172
Good luck!
171173

172174
## **SUBMIT YOUR HOMEWORK!**

Week3/js-exercises/ex1-AddSix.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
3+
** Exercise 1: Add Six **
4+
5+
Declare a function called `createBase`.The function takes a number as a parameter and
6+
return a closure, that adds a number to the base number argument.
7+
8+
Call the function three times. The return values should be:
9+
15, 24, 36
10+
11+
*/
12+
13+
function createBase( /* ???? */ ) {
14+
// Put here your logic...
15+
}
16+
17+
const addSix = createBase(6);
18+
19+
// Put here your function calls...
20+
console.log(addSix());
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
3+
** Exercise 2: The lottery machine **
4+
5+
Write a function called removeDuplicates. This function accept an array as an argument
6+
does not return anything but removes any duplicate elements from the array.
7+
8+
The function should remove duplicate elements.So the result should be:
9+
10+
11+
*/
12+
13+
14+
// WRITE YOUR FUNCTION HERE
15+
16+
const letters = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c', 'b'];
17+
18+
removeDuplicates(letter);
19+
20+
if (letters === ['a', 'b', 'c', 'd', 'e', 'f'])
21+
console.log("Hooray!")
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
3+
** Exercise 3: Guess the output **
4+
5+
Look at the bellow code snippet.
6+
Can you guess the output?
7+
Write out your reasoning in 50 words or less.
8+
9+
*/
10+
11+
12+
13+
let a = 10;
14+
const x = (function () {
15+
a = 12;
16+
return function () {
17+
alert(a);
18+
};
19+
})();
20+
21+
x();

Week3/js-exercises/ex4-GuessMore.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
3+
** Exercise 4: Guess more **
4+
5+
Look at the bellow code snippet.
6+
Can you guess the output?
7+
Write out your reasoning in 50 words or less.
8+
9+
*/
10+
11+
const x = 9;
12+
13+
function f1(val) {
14+
val = val + 1;
15+
return val;
16+
}
17+
f1(x);
18+
console.log(x);
19+
20+
const y = {
21+
x: 9
22+
};
23+
24+
function f2(val) {
25+
val.x = val.x + 1;
26+
return val;
27+
}
28+
f2(y);
29+
console.log(y);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
3+
** Exercise 5: The lottery machine **
4+
5+
Don't you just love the thrill of the lottery? What if I told you we can make our own lottery machine? Let'
6+
s get started!
7+
8+
Write a
9+
function that takes 4 arguments.
10+
11+
- A start value
12+
- An end value
13+
- A callback that executes if the number is divisible by 3
14+
- A callback that executes if the number is divisible by 5
15+
16+
The function should first generate an array containing values from start value to end value(inclusive).
17+
18+
Then the function should take the newly created array and iterate over it, and calling the first callback
19+
if the array value is divisible by 3.
20+
21+
The function should call the second callback
22+
if the array value is divisible by 5.
23+
24+
Both functions should be called
25+
if the array value is divisible by both 3 and 5.
26+
27+
*/
28+
29+
function threeFive(startIndex, stopIndex, threeCallback, fiveCallback) {
30+
const numbers = [];
31+
// make array
32+
// start at beginning of array and check if you should call threeCallback or fiveCallback or go on to next
33+
}
34+
35+
threeFive(10, 15, sayThree, sayFive);
36+
37+
// Should create an array [10,11,12,13,14,15]
38+
// 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.
File renamed without changes.

Week3/project/index.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Tip Calculator</title>
8+
</head>
9+
10+
<body>
11+
<div id="app"></div>
12+
<script src="index.js"></script>
13+
</body>
14+
15+
</html>

Week3/project/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Your code goes in here
2+
3+
document.querySelector("#app").innerText = "Tip Calculator";

0 commit comments

Comments
 (0)