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

Skip to content

Commit d5f1e02

Browse files
committed
Solved this exercise with random drink from the drinkTypes array
1 parent 7354932 commit d5f1e02

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Week1/practice-exercises/5-who-wants-a-drink.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,14 @@
88
*/
99

1010
// There are 3 different types of drinks:
11-
const drinkTypes = ['cola', 'lemonade', 'water'];
11+
const drinkTypes = ['cola', 'lemonade', 'water'];
12+
let drinkTray = [];
13+
for (let i = 0; i < 5; i++) {
14+
let item = drinkTypes[Math.floor(Math.random()*drinkTypes.length)];
15+
drinkTray.push(item);
16+
if (drinkTray.filter(x => x==item).length > 2) {
17+
drinkTray.pop();
18+
i--;
19+
}
20+
}
21+
console.log(`Hey guys, I brought a ${drinkTray.join(", ")}!`);

0 commit comments

Comments
 (0)