Javascript Math random() roll a die

Introduction

Let's look at how you would mimic the roll of a single die.

let diceThrow; // ww w.  j  a v  a 2s. c  om
for (let throwCount = 0; throwCount < 10; throwCount++) { 
    diceThrow = (Math.floor(Math.random() * 6) + 1); 
    console.log(diceThrow); 
} 



PreviousNext

Related