Skip to content

Commit 7b10a49

Browse files
committed
[Shreyash]: Added code to perform gambling till money becomes 0 or 200
1 parent d8cc04e commit 7b10a49

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)