Skip to content

Commit cdd5f45

Browse files
committed
Homework JavaScript2 week2
1 parent c9f42e1 commit cdd5f45

2 files changed

Lines changed: 66 additions & 59 deletions

File tree

Week2/homework/maartjes-work.js

Lines changed: 54 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,69 @@
11
'use strict';
22

3-
const monday = [
4-
{
5-
name: 'Write a summary HTML/CSS',
6-
duration: 180
7-
},
8-
{
9-
name: 'Some web development',
10-
duration: 120
11-
},
12-
{
13-
name: 'Fix homework for class10',
14-
duration: 20
15-
},
16-
{
17-
name: 'Talk to a lot of people',
18-
duration: 200
19-
}
3+
const monday = [{
4+
name: 'Write a summary HTML/CSS',
5+
duration: 180
6+
},
7+
{
8+
name: 'Some web development',
9+
duration: 120
10+
},
11+
{
12+
name: 'Fix homework for class10',
13+
duration: 20
14+
},
15+
{
16+
name: 'Talk to a lot of people',
17+
duration: 200
18+
}
2019
];
2120

22-
const tuesday = [
23-
{
24-
name: 'Keep writing summary',
25-
duration: 240
26-
},
27-
{
28-
name: 'Some more web development',
29-
duration: 180
30-
},
31-
{
32-
name: 'Staring out the window',
33-
duration: 10
34-
},
35-
{
36-
name: 'Talk to a lot of people',
37-
duration: 200
38-
},
39-
{
40-
name: 'Look at application assignments new students',
41-
duration: 40
42-
}
21+
const tuesday = [{
22+
name: 'Keep writing summary',
23+
duration: 240
24+
},
25+
{
26+
name: 'Some more web development',
27+
duration: 180
28+
},
29+
{
30+
name: 'Staring out the window',
31+
duration: 10
32+
},
33+
{
34+
name: 'Talk to a lot of people',
35+
duration: 200
36+
},
37+
{
38+
name: 'Look at application assignments new students',
39+
duration: 40
40+
}
4341
];
4442

4543
const maartjesTasks = monday.concat(tuesday);
4644
const maartjesHourlyRate = 20;
4745

48-
function computeEarnings(tasks, hourlyRate) {
49-
// Replace this comment and the next line with your code
50-
console.log(tasks, hourlyRate);
51-
}
46+
const durationInHours = maartjesTasks.map(inHours => inHours.duration / 60);
47+
console.log(durationInHours);
5248

53-
// eslint-disable-next-line no-unused-vars
54-
const earnings = computeEarnings(maartjesTasks, maartjesHourlyRate);
49+
const moreThanTweHours = durationInHours.filter(tweHours => tweHours >= 2);
50+
console.log(moreThanTweHours);
5551

56-
// add code to convert `earnings` to a string rounded to two decimals (euro cents)
52+
const computeEarnings = moreThanTweHours
53+
.map(manyPerHours => manyPerHours * maartjesHourlyRate)
54+
.reduce((total, manyPerHours) => total + manyPerHours, 0);
55+
console.log(computeEarnings);
56+
57+
58+
const currencyFormatter = new Intl.NumberFormat('NL', { style: 'currency', currency: 'EUR' });
59+
60+
const formattedCosts = currencyFormatter.format(computeEarnings);
61+
console.log("Maartje has earned " + formattedCosts);
5762

58-
console.log(`Maartje has earned €${'replace this string with the earnings rounded to euro cents'}`);
5963

6064
// Do not change or remove anything below this line
6165
module.exports = {
62-
maartjesTasks,
63-
maartjesHourlyRate,
64-
computeEarnings
65-
};
66+
maartjesTasks,
67+
maartjesHourlyRate,
68+
computeEarnings
69+
};

Week2/homework/map-filter.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
'use strict';
22

3-
function doubleOddNumbers(numbers) {
4-
// Replace this comment and the next line with your code
5-
console.log(numbers);
6-
}
7-
83
const myNumbers = [1, 2, 3, 4];
9-
console.log(doubleOddNumbers(myNumbers));
4+
5+
const doubleOddNumbers = myNumbers
6+
.filter(odd => odd % 2 !== 0)
7+
.map(odd => odd * 2);
8+
9+
console.log(doubleOddNumbers);
10+
11+
12+
1013

1114
// Do not change or remove anything below this line
1215
module.exports = {
13-
myNumbers,
14-
doubleOddNumbers
15-
};
16+
myNumbers,
17+
doubleOddNumbers
18+
};

0 commit comments

Comments
 (0)