Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5826029 commit 5362819Copy full SHA for 5362819
Week1/practice-exercises/5-who-wants-a-drink.js
@@ -11,11 +11,28 @@
11
const drinkTypes = ['cola', 'lemonade', 'water'];
12
13
let drinkTray = [];
14
-const loops = 5;
+let loops = 5;
15
16
-while(loops < 5){
17
- let drinkType = drinkTypes[Math.floor(Math.random()*3)];
18
- // not completed yet
19
- loops.unshift(drinkType);
20
- loops++;
+while(loops > 0){
+ const drinkType = drinkTypes[Math.floor(Math.random()*3)];
+ const maxNumOfDrinkType = 2;
+
+ const countDrinkType = drinkTray.filter(function(drink) {
21
+ return drink === drinkType;
22
+ }).length;
23
24
+ if(countDrinkType === maxNumOfDrinkType){
25
+ continue;
26
+ } else{
27
+ drinkTray.unshift(drinkType);
28
+ loops--;
29
+ }
30
+}
31
32
+if(!drinkTray.length){
33
+ console.log("I didn't brought drinks.");
34
+}else{
35
+ console.log(`Hey guys I brought ${drinkTray.join(', ')}`);
36
}
37
38
0 commit comments