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 d8cc04e commit 7b10a49Copy full SHA for 7b10a49
Repetition Problems/While Loop/Gambling.js
@@ -0,0 +1,23 @@
1
+/*
2
+ Write a Program where a gambler starts with Rs 100 and places Re 1 bet
3
+ until he/she goes broke i.e. no more money to gamble or reaches the
4
+ goal of Rs 200. Keeps track of number of times won and number of bets made
5
+*/
6
+
7
+var money = 100;
8
+let numOfBet = 0;
9
+let numOfWin = 0;
10
11
+console.log("\n Gambling till money reaches 0 or 200")
12
13
+do {
14
+ numOfBet++;
15
+ let gamble = Math.random();
16
+ if (gamble <= 0.5) {
17
+ money += 1;
18
+ numOfWin++;
19
+ } else {
20
+ money -= 1;
21
+ }
22
+} while (0 < money && money < 200);
23
+console.log("\n Num of Bets : " + numOfBet + "\n Num of Wins : " + numOfWin + "\n");
0 commit comments