以下のコードを実行していただければわかると思いますが
数字を小さい順にタップしていくゲームです
ですがスタートボタンを押したときに0~9の数字が書かれているボタンと10~15まで書かれているボタンでズレが起きてしまいます。
これはどうすれば解決しますか?
<!doctype html> <html> <head> <meta charset="utf-8"> </head> <body>lang
1コード
</body> </html><h1>小さい数字からタッチ!</h1> <div id="iro"><b><p>Time: <span id ="time">0.0</span> sec. </p></b></div> <div id="board"> <input type="button" id="button_0" value="?" onclick="touched(0);"> <input type="button" id="button_1" value="?" onclick="touched(1);"> <input type="button" id="button_2" value="?" onclick="touched(2);"> <input type="button" id="button_3" value="?" onclick="touched(3);"><br> <input type="button" id="button_4" value="?" onclick="touched(4);"> <input type="button" id="button_5" value="?" onclick="touched(5);"> <input type="button" id="button_6" value="?" onclick="touched(6);"> <input type="button" id="button_7" value="?" onclick="touched(7);"><br> <input type="button" id="button_8" value="?" onclick="touched(8);"> <input type="button" id="button_9" value="?" onclick="touched(9);"> <input type="button" id="button_10" value="?" onclick="touched(10);"> <input type="button" id="button_11" value="?" onclick="touched(11);"><br> <input type="button" id="button_12" value="?" onclick="touched(12);"> <input type="button" id="button_13" value="?" onclick="touched(13);"> <input type="button" id="button_14" value="?" onclick="touched(14);"> <input type="button" id="button_15" value="?" onclick="touched(15);"><br> </div> <br> <p><input id="st" type="button" value="start!" onclick="timerStart();"></p> <script> var currentNum; var timet; var startTime; var isPlaying = false; function timerStart() { initBoard(); currentNum = 0; startTime = (new Date()).getTime(); if (!isPlaying) { isPlaying = true; runTimer(); } } function initBoard() { var nums = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]; var num; var btn; for (var i=0; i<16; i++) { num = nums.splice(Math.floor(Math.random() * nums.length), 1); btn = document.getElementById('button_' + i); btn.value = num[0]; btn.disabled = false; } } function touched(n) { var btn = document.getElementById('button_' + n) if (btn.value == currentNum) { btn.disabled = true; currentNum++; } if (currentNum == 16){ clearTimeout(timer); isPlaying = false; alert('Your Score: ' + document.getElementById('time').innerHTML); document.location = "result.html"; } } function runTimer() { document.getElementById('time').innerHTML = (((new Date()).getTime() - startTime) / 1000).toFixed(1); timer = setTimeout(function() { runTimer() ; }, 100); } </script>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/07/05 11:21
2015/07/05 11:25