<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>겜블링 게임</title>
<style>
table {
border: 1px solid violet;
border-collapse: collapse;
}
td {
width: 50px;
height: 50px;
padding: 0px;
font: italic 50px consolas, sans-serif;
color: blue;
text-align: center;
background: linen;
}
div#msg {
font: italic 18px consolas, sans-serif;
color: magenta;
margin-top: 10px;
}
</style>
<script>
// to do
var gameon = true;
var gameArray = [0, 0, 0]
function gen(event) {
if (gameon == false) {
return;
}
// generation 0~2
// to do
else if (gameon == true) {
document.getElementById("first").innerHTML = Math.floor(Math.random() * 3);
gameArray[0] = document.getElementById("first").innerHTML;
document.getElementById("second").innerHTML = Math.floor(Math.random() * 3);
gameArray[1] = document.getElementById("second").innerHTML;
document.getElementById("third").innerHTML = Math.floor(Math.random() * 3);
gameArray[2] = document.getElementById("third").innerHTML;
if (gameArray[0] == gameArray[1] && gameArray[1] == gameArray[2]) {
document.getElementById("msg").innerHTML = "Success(click here to do again)";
gameon = false;
}
else {
document.getElementById("msg").innerHTML = "fail(click here to do again)";
}
}
}
function reset() {
for (var i = 0; i < gameArray.length; i++)
gameArray[i] = 0;
document.getElementById("first").innerHTML = 0;
document.getElementById("second").innerHTML = 0;
document.getElementById("third").innerHTML = 0;
gameon = true;
}
</script>
</head>
<body>
<h3>갬블링 게임</h3>
<hr>
<table>
<tr>
<td id="first" onclick="gen(event)">0</td>
<td id="second" onclick="gen(event)">0</td>
<td id="third" onclick="gen(event)">0</td>
</tr>
</table>
<div id="msg" onclick="reset()"></div>
</body>
</html>
Each number changes to a random number from 0 to 2. If everyone gets the same number, they win. I want to modify the (else if) part so that if I click on a number, that number will change. The current method is that when you click, all the numbers change. The part needs to be solved without modification. //What should I do to modify only the bottom part of the //to do?