1. While we're at it WHy does the Variable line repeat twice?


var coinFace = Math.floor(Math.random() * 2);

while(coinFace === 0){
console.log("Heads! Flipping again...");
var coinFace = Math.floor(Math.random() * 2);
console.log("Tails! Done flipping.");

why does the variable line for "coinFace" repeat twice?


coinFace has two possible values: 0 and 1

0 represents the head side of a coin, 1 the tails side.

The code will repeat for as long till we have tails. So the loop could run any number of times, this can be twice, the next time it can be different


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.