javascriptでじゃんけんゲームを作っています
ちゃんと組んだはずなのに全く表示されません
どこが違うのか教えてほしいです
追記
cssがなかったため再度cssを追加しました
html
<!DOCTYPE html> <html lang="ja"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link rel="stylesheet" href="jyan.css" media="all"> <title></title> <script> function janken(num){ let Myte = document.getElementsByName("te"); let My = document.getElementById("My"); let CPte = document.getElementById("Cte"); let ELT = document.getElementById("ELT"); let ote = ["グー", "チョキ", "パー"]; const Lan = Math.floor(3 * Math.random()); CPte.innerHTML = "<p>" + ote[Lan] + "</p>"; let SA = String(Lan) + String(num); if(Lan === num){ ELT.innerHTML = "<p>" + "あいこ" + "</p>"; My.removeAttribute("kumi"); CPte.removeAttribute("kumi"); }else{ if(SA === "02" || SA === "10" || SA === "21"){ My.setAttribute("class", "red"); CPte.setAttribute("class", "black"); ELT.innerHTML = ""; }else{ My.setAttribute("class", "black"); CPte.setAttribute("class", "red"); ELT.innerHTML = ""; } } } window.onload = function(){ let i_btn = document.getElementsByName("te"); for(let i = 0; i < i_btn.length; i++){ i_btn[i].addEventListener('mouseover', () => { i_btn[i].style.backgroundColor = "orange"; }); i_btn[i].addEventListener('mouseout', () => { i_btn[i].style.backgroundColor = ""; }); } i_btn[0].onclick = function(){ janken(0); }; i_btn[1].onclick = function(){ janken(1); }; i_btn[2].onclick = function(){ janken(2); }; }; </script> </head> <body> <h2>じゃんけんゲーム</h2> <div class="CO"> <div class="botan"> <div class="kei">computer</div> <div id="Cte" class="kuro"><p>pap</p></div> </div> <div id="ELT"></div> <div class="botan"> <div class="kei">you</div> <div id="My" class="aka"> <button type="button" name="te">グー</button><br> <button type="button" name="te">チョキ</button> <button type="button" name="te">パー</button><br> </div> </div> </div> </body></html>
css
@charset "utf-8"; button{ height: 25px; width: 80px; } .botan{ content: ""; display: block; visibility: hidden; clear: both; } .CO{ float: left; width: 310px; height:120px; display: flex; align-items: center; } #Cte{ width: 100px; height: 100px; border: 1px dotted blue; align-items: center; display: flex; align-items: center; } #Cte p{ width:100px; margin:0px; text-align: center; } #ELT{ float: left; width: 110px; height: 100px; padding-top: 20px; display: flex; align-items: center; } #ELT p{ width:100px; margin:0px; text-align: center; } #My{ border: 1px dotted blue; width: 100px; height: 85px; text-align: center; padding-top: 15px; } .aka{background-color: red;} .kuro{ background-color: black; color: blanchedalmond; font-weight: bold; } .kei{text-align: center;}
回答1件
あなたの回答
tips
プレビュー