I'm currently working on a project that involves adding up the random rolls of a pair of dice for n
rolls as specified by the user. Take a look at the code below:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="dice.css">
<script>
//this function is meant to generate 2 random numbers
function roll() {
var x = Math.floor(Math.random() * ((6 - 1) + 1) + 1);
var y = Math.floor(Math.random() * ((6 - 1) + 1) + 1);
var Total = x + y;
}
//prompts user to input how many times they wish to roll the two dice
function myinput() {
var NumRoll = prompt("Please enter the number of times you wish to roll");
if (NumRoll <= 0 )
document.getElementById("wrong").innerHTML = "You entered an invalid number, please enter a value between 1-100";
else if ( NumRoll >100 )
document.getElementById("wrong").innerHTML = "You entered an invalid number, please enter a value between 1-100";
else
document.getElementById("right").innerHTML = "Rolling the dice " + NumRoll + " times";
}
</script>
</head>
<body>
<p id="wrong"> </p>
<p1 id="right"></p1>
<p>Click to roll the dice!</p>
<button onclick="myinput(); roll()">Press to Roll</button>
</body>
</html>