First page Back Continue Last page Image
- Random With A Purpose Part 2
- var newNum = Math.floor(Math.random() * 6);
- On page 54 of your book we see that the JavaScript math library has a "floor" option that gives us an integer
- Better again but now we have an issue if it rounds to 0
- window.onload = initAll;
- function initAll() {
- do{
- var ans = prompt("Want to roll again (y or n)","");
- var newNumber = Math.floor(Math.random() * 6);
- alert("You rolled a " + newNumber );
- }
- while(ans == "y");
- }