Skip to content

Commit b8946d4

Browse files
committed
[Shreyash]: Added code to extend flip coin program till we get either head or tail 11 times
1 parent 7b10a49 commit b8946d4

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
Extend the Flip Coin problem till either Heads or Tails wins 11 times.
3+
*/
4+
5+
console.log("\n Fliping the coin \n")
6+
let win = 0;
7+
let headCount = 0;
8+
let tailCount = 0;
9+
while (win != 11) {
10+
let flipCoin = Math.random();
11+
if (flipCoin <= 0.5) {
12+
headCount++;
13+
console.log(" Head -", headCount);
14+
if (headCount == 11) {
15+
console.log("\n HEAD Wins!!! \n")
16+
win = headCount;
17+
}
18+
}
19+
else {
20+
tailCount++;
21+
console.log(" Tail -", tailCount);
22+
if (tailCount == 11) {
23+
console.log("\n TAIL Wins!!! \n")
24+
win = tailCount;
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)