Skip to content

Commit 51d08b1

Browse files
author
obada othman
committed
Finished ex3 to ex5
1 parent 708cc74 commit 51d08b1

6 files changed

Lines changed: 52 additions & 31 deletions

File tree

Week2/js-exercises/ex3-lemonAllergy.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
1212
*/
1313

14-
1514
function takeOutLemons(basket) {
16-
// your code goes in here. The output is a string
15+
// your code goes in here. The output is a string
16+
// returns an array that doesn't contain 'lemon' or 'Lemon'
17+
const lemonlessBasket = basket.filter((fruit) => fruit != 'Lemon' && fruit != 'lemon');
18+
return `My mom bought me a fruit basket, containing [${lemonlessBasket}]`;
1719
}
1820

1921
const fruitBasket = ['Apple', 'Lemon', 'Grapefruit', 'Lemon', 'Banana', 'Watermelon', 'Lemon'];
2022

21-
console.log(takeOutLemons(fruitBasket));
23+
console.log(takeOutLemons(fruitBasket)); //My mom bought me a fruit basket, containing [Apple,Grapefruit,Banana,Watermelon]

Week2/js-exercises/ex4-collectiveAge.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,30 @@
1010

1111
function collectiveAge(people) {
1212
// return the sum of age for all the people
13+
const individualAges = people.map((person) => person.age);
14+
return individualAges.reduce((total, individualAge) => total + individualAge, 0);
15+
}
16+
function collectiveMembers(hackYourFutureMembers) {
17+
return collectiveAge(hackYourFutureMembers);
1318
}
1419

15-
const hackYourFutureMembers = [{
20+
const hackYourFutureMembers = [
21+
{
1622
name: 'Wouter',
17-
age: 33
23+
age: 33,
1824
},
1925
{
2026
name: 'Federico',
21-
age: 32
27+
age: 32,
2228
},
2329
{
2430
name: 'Noer',
25-
age: 27
31+
age: 27,
2632
},
2733
{
2834
name: 'Tjebbe',
29-
age: 22
35+
age: 22,
3036
},
3137
];
3238

33-
console.log("The collective age of the HYF team is: " + collectiveMembers(hackYourFutureMembers));
39+
console.log('The collective age of the HYF team is: ' + collectiveMembers(hackYourFutureMembers));
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
<html>
2-
3-
<!-- your html code goes in here -->
4-
5-
</html>
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<!-- your html code goes in here -->
4+
<head>
5+
<meta charset="UTF-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Document</title>
8+
</head>
9+
<body>
10+
<script src="ex5-myFavoriteHobbies.js"></script>
11+
</body>
12+
</html>

Week2/js-exercises/ex5-myFavoriteHobbies.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010

1111
function createHTMLList(arr) {
1212
// your code goes in here
13+
const body = document.querySelector('body');
14+
const ul = document.createElement('ul');
15+
body.appendChild(ul);
16+
arr.map((hobby) => {
17+
const li = document.createElement('li');
18+
li.innerHTML = hobby;
19+
ul.appendChild(li);
20+
});
1321
}
1422

1523
const myHobbies = [
@@ -18,4 +26,6 @@ const myHobbies = [
1826
'Programming',
1927
'Hanging out with friends',
2028
'Going to the gym',
21-
];
29+
];
30+
31+
createHTMLList(myHobbies);

Week2/project/index.html

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
<!DOCTYPE html>
22
<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>Pomodoro Clock</title>
8-
</head>
9-
10-
<body>
11-
<div id="app">
12-
13-
</div>
14-
<script src="index.js"></script>
15-
</body>
16-
17-
</html>
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Pomodoro Clock</title>
7+
</head>
8+
9+
<body>
10+
<div id="app"></div>
11+
<script src="index.js"></script>
12+
</body>
13+
</html>

Week2/project/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
Display minutes and seconds
88
If the timer finishes the timer should be replaced by the message: Time 's up!
99
*
10-
*/
10+
*/

0 commit comments

Comments
 (0)