-2
我的工作增加了對骰子爲n
輥的隨機輥一起由用戶所定義的。下面是代碼:Java腳本:添加兩個骰子的隨機輥爲「n」個輥
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="dice.css">
<script>
//supposed to give 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;
}
// ask for user to put how many times they want 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 enter number between 1-100";
else if (NumRoll >100)
document.getElementById("wrong").innerHTML = "You enter an invalid number enter number 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 dice</p>
<button onclick="myinput(); roll()">Press</button>
</body>
</html>
的的jsfiddle因此用戶要求擲骰子23次,骰子將推出23倍addingall的它捲起來的數字我不surehow連接兩個 – Michele