ใใใใใใทใใใใใใใใฆใฟใพใใใ
janken.html
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>ใใใใใ</title>
</head>
<body>
<div id="message1" >
<h3>CPUใฎๆ: ใชใซใใชใ</h3>
</div>
<div id="message2" >
<h3>็ตๆ: ใปใฌใฏใใใใฏในใใ้ธๆใใฆๆฑบๅฎใใฟใณใๆผใใฆใใ ใใใ</h3>
</div>
<form>
<select id="janken">
<option>ใใผ</option>
<option>ใกใใ</option>
<option>ใฑใผ</option>
</select>
<input type="button" value="ใใใงใใใใถ" onclick="myGame()">
</form>
<script>
function myGame() {
// ่ชๅใ้ธๆใใใใใใใใฎๆ
var myte = document.getElementById("janken").selectedIndex;
// CPUใฎใใใใใใฎๆใฎ็ชๅท
var cpunum = Math.floor(Math.random()*3);
// CPUใฎใใใใใใฎๆ
var cpuhand;
// ๅคๅฎ
var judge;
if(cpunum == 0) {
cpuhand = "ใใผ";
} else if(cpunum == 1) {
cpuhand = "ใกใใ";
} else if(cpunum == 2) {
cpuhand = "ใฑใผ";
}
if(myte == 0 && cpunum == 1) {
judge = "ใใชใใฎๅใก";
} else if(myte == 1 && cpunum == 2) {
judge = "ใใชใใฎๅใก";
} else if(myte == 2 && cpunum == 0) {
judge = "ใใชใใฎๅใก";
} else if(myte == cpunum) {
judge = "ใฒใใใ";
} else {
judge = "ใใชใใฎ่ฒ ใ";
}
document.getElementById("message1").innerHTML = "<h3>CPUใฎๆ: " + cpuhand + "</h3>";
document.getElementById("message2").innerHTML = "<h3>็ตๆ: " + judge + "</h3>";
}
</script>
</body>
</html>