Reputation: 31
<script>
function myfunction () {
var x = Math.random();
if (x > 0.5) {
document.write("Heads!");
} else {
document.write("Tails!");
}
}
</script>
The following code is supposed to print either Heads! or Tails! as if a coin was being flipped. However, it does not seem to work.
Upvotes: 2
Views: 87
Reputation: 28404
You are not calling the function:
function myfunction () {
var x = (Math.random());
if (x > 0.5) {
document.write("Heads!");
}else {
document.write("Tails!");
}
}
myfunction(); //add this
Upvotes: 1