First page Back Continue Last page Image
- Let’s write code to simulate the values of a die
- var newNum = Math.random() * 6;
- Let’s start by multiplying whatever the random number is by 6 (the number of dots on a die)
- window.onload = initAll;
- function initAll() {
- do{
- var ans = prompt("Want to roll again (y or n)","");
- var newNumber = Math.random() * 6;
- alert("You rolled a " + newNumber );
- }
- while(ans == "y");
- }
- Better, but we need an integer