Skip to content

Commit 97ef941

Browse files
committed
Week2 Finished
1 parent 75aeb9d commit 97ef941

20 files changed

Lines changed: 278 additions & 7 deletions

Week2/Homework/js-exercises/readingList.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@ readList.forEach(x => {
2323
readList.forEach(x => {
2424
console.log(`${x.title} by ${x.author}`);
2525

26+
})
27+
//Conditional statements
28+
readList.forEach(x => {
29+
console.log(x.alreadyRead === true ? `You already read "${x.title}"` : `You still need to read "${x.title}"`)
2630
})
Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1+
//Variables
12
const drinkTypes = ["cola", "lemonade", "water"];
23
let drinkTray = [];
3-
4-
drinkTypes.forEach(x => {
5-
for (i = 0; i < 5; i++) {
6-
drinkTray.push(x);
7-
return drinkTray;
4+
let index = 0;
5+
//Function to check if the drink is repeated
6+
function isRepeated(drink) {
7+
return drink === drinkTypes[index]
8+
}
9+
//Loop iterating through the array
10+
for (let i = 0; i < 5; i++) {
11+
drinkTray.push(drinkTypes[index]);
12+
if (drinkTray.filter(isRepeated).length === 2) {
13+
index += 1;
814
}
9-
})
10-
15+
}
16+
//Final console.log
17+
console.log(`Hey guys, I brought a ${drinkTray.join(", ")}!`);
1118

Lines changed: 10 additions & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 4 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)