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 7b10a49 commit b8946d4Copy full SHA for b8946d4
Repetition Problems/While Loop/FlipCoin.js
@@ -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