Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to Write a program that simulates a coin toss using random method of Javascript Math class

var head = 1;
var tail = 2;

var toss = Math.random() * 2;
var floor = Math.floor(toss)
if(floor === 0){
    document.write("0 <br> Random Coin Value: Head")
} else if(floor === 1)
{
    document.write("1 <br> Random Coin Value: Tails")
}
 
PREVIOUS NEXT
Tagged: #Write #program #simulates #coin #toss #random #method #Javascript #Math #class
ADD COMMENT
Topic
Name
3+5 =