Coin flipping 400 times

Hello

Variables declaration :
i : number of toss
result : result of the coin toss; Head is value 1
Tail is value 2.
head : an array that store the value 1
tail : store the value 2

Functions :
disableLimits function is to prevent to stop if the number of loop is above 500.
pickRandom function chooses the values 1 or 2.
Probability ( ) calculates in percentage, the result of Toss, Head or Tail. The value 400 is the number of time the toss is repeated. Multiply by 100 to find the the percentage.
Coin ( head or tail ) is an argument.

The First For Loop for : toss the coin 400 times and store the valus to the array “result” by push method.

The Second For Loop store the number of head ( 1 )and tails ( 2 ) in the arrays.

The length key is used to count the item in each array.

Toss a coin.

1 Like