DiceToss Function

by AnnaGerber

HTML

<div id="result"></div>

JavaScript

function rollDice() {
    var diceToss = Math.floor(Math.random() * 6 + 1);
    if (diceToss == 6) {
        //console.log("You won!");
        return true;
    } else {
        //console.log("Sorry, try again");
        return false;
    }
}
var myDiceRoll = false;
var counter = 0;
while(!myDiceRoll){
    myDiceRoll = rollDice();
    counter++;
}
document.getElementById("result").innerHTML = 
 "You got a 6! It took " + counter + " rolls";