1 回答
TA贡献1776条经验 获得超12个赞
这是你想要的吗?
var firstx = ["X", "O", "L", "L"];
var secondx = ["X", "O", "L", "L"];
var thirdx = ["X", "O", "L", "L"];
function randIndex() {
var randIndex1 = Math.floor(Math.random() * 4);
var randIndex2 = Math.floor(Math.random() * 4);
var randIndex3 = Math.floor(Math.random() * 4);
var first = firstx[randIndex1];
var second = secondx[randIndex2];
var third = thirdx[randIndex3];
var btn = document.getElementById("btn");
var sent = document.getElementById("sent");
var result = first + " " + second + " " + third;
if (result == "X X X") {
alert("CONGRATULATIONS! YOU WIN!");
}
sent.innerHTML ="<li>" + result + "</li>";
btn.innerText = "Roll Again";
}
font-family: helvetica;
text-align: center;
-webkit-text-fill-color: black;
}
body {
background-color: lightcoral;
}
<!DOCTYPE html>
<html>
<head>
<title>Slot Machine</title>
<meta charset="UTF-8" />
</head>
<body>
<h1>Slot Machine</h1>
<p>
Welcome to the slot machine! To play, click the "Roll" button. If you get
three X's, YOU WIN! Have fun and Enjoy your new gambling addiction!
</p>
<br />
<button id="btn" onclick="randIndex();">
Roll
</button>
<ul id="sent"></ul>
<br /><br />
<hr />
<br /><br />
</body>
</html>
- 1 回答
- 0 关注
- 85 浏览
添加回答
举报