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

Skip to content

Commit 22790e4

Browse files
author
Noer Paanakker
committed
rewrote exercises week 3
1 parent accf7f3 commit 22790e4

File tree

5 files changed

+44
-31
lines changed

5 files changed

+44
-31
lines changed

Week3/MAKEME.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,24 +101,23 @@ console.log(y);
101101

102102
Don't you just love the thrill of the lottery? What if I told you we can make our own lottery machine?
103103

104-
1. Write a function that takes 4 arguments.
104+
1. Write a function, called `generateNumbers` that takes 4 arguments.
105105
- A start value
106106
- An end value
107107
- A callback that executes if the number is divisible by 3
108108
- A callback that executes if the number is divisible by 5
109+
2. `generateNumbers` generates an array containing values from start value to end value (inclusive).
109110

110-
The function should first generate an array containing values from start value to end value (inclusive).
111+
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 callback should simply return the string "The number [i] is divisible by 3!"
111112

112-
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.
113+
If the iterated value is divisible by 5, execute the second callback. The callback should simply return the string "The number [i] is divisible by 5!"
113114

114-
The function should call the second callback if the array value is divisible by 5.
115-
116-
Both functions should be called if the array value is divisible by both 3 and 5.
115+
Both callbacks should be executed if the array value is divisible by both 3 and 5.
117116

118117
Here is a starter template:
119118

120119
```js
121-
function threeFive(startIndex, stopIndex, threeCallback, fiveCallback) {
120+
function generateNumbers(startIndex, stopIndex, threeCallback, fiveCallback) {
122121
const numbers = [];
123122
// make array
124123
// start at beginning of array and check if you should call threeCallback or fiveCallback or go on to next
@@ -148,10 +147,10 @@ Happy learning!
148147
149148
> Important! Place your code in the folder `Week3 \ project`.
150149
151-
In this week's project you'll be making a Tip Calculator! A user can fill in 3 things:
150+
In this week's project you'll be making a Tip Calculator! In the webpage there's a form. A user can fill in the following:
152151

153152
1. The amount of the bill
154-
2. How good the service was
153+
2. Rate how good the service was
155154
3. How many people will share the bill
156155

157156
When the button is clicked a calculation is made and the user can read the tip amount underneath.

Week3/js-exercises/ex1-AddSix.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@
22
33
** Exercise 1: Add Six **
44
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
5+
1. Declare a function called `createBase`.
6+
- It takes 1 argument: a number
7+
- Returns a closure, that adds a number to the number argument.
8+
2. Call the function three times. The return values should be:
9+
a) 15
10+
b) 24
11+
c) 36
1012
1113
*/
1214

13-
function createBase( /* ???? */ ) {
15+
function createBase(/* ???? */) {
1416
// Put here your logic...
1517
}
1618

1719
const addSix = createBase(6);
1820

1921
// Put here your function calls...
20-
console.log(addSix());
22+
console.log(addSix());

Week3/js-exercises/ex2-RemoveDuplicates.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
33
** Exercise 2: The lottery machine **
44
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.
5+
1. Write a function called `removeDuplicates`
6+
2. It takes one argument: the following array:
77
8-
The function should remove duplicate elements.So the result should be:
8+
const letters = ['a', 'b', 'b', 'c', 'd', 'a', 'e', 'f', 'f', 'c', 'b'];
99
10+
3. Write logic that looks into the array and removes duplicates
11+
4. Return the modified array without the duplicates
1012
1113
*/
1214

13-
1415
// WRITE YOUR FUNCTION HERE
1516

1617
const letters = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c', 'b'];
1718

1819
removeDuplicates(letter);
1920

20-
if (letters === ['a', 'b', 'c', 'd', 'e', 'f'])
21-
console.log("Hooray!")
21+
if (letters === ['a', 'b', 'c', 'd', 'e', 'f']) console.log('Hooray!');

Week3/js-exercises/ex3-GuessTheOutput.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,23 @@
44
55
Look at the bellow code snippet.
66
Can you guess the output?
7-
Write out your reasoning in 50 words or less.
7+
Write out your reasoning in 100 words or less.
88
99
*/
1010

11-
12-
1311
let a = 10;
14-
const x = (function () {
12+
const x = (function() {
1513
a = 12;
16-
return function () {
14+
return function() {
1715
alert(a);
1816
};
1917
})();
2018

21-
x();
19+
x();
20+
21+
/*
22+
Write out your reasoning here (100 words or less):
23+
24+
25+
26+
*/

Week3/js-exercises/ex4-GuessMore.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
Look at the bellow code snippet.
66
Can you guess the output?
7-
Write out your reasoning in 50 words or less.
7+
Write out your reasoning in 100 words or less.
88
99
*/
1010

@@ -18,12 +18,19 @@ f1(x);
1818
console.log(x);
1919

2020
const y = {
21-
x: 9
21+
x: 9,
2222
};
2323

2424
function f2(val) {
2525
val.x = val.x + 1;
2626
return val;
2727
}
2828
f2(y);
29-
console.log(y);
29+
console.log(y);
30+
31+
/*
32+
Write out your reasoning here (100 words or less):
33+
34+
35+
36+
*/

0 commit comments

Comments
 (0)