javascriptで以下のようなゲームを作っているのですがタイマーが終了した後にクリックした回数(clicknum)とポイント(point)の表示のさせ方がわからなかったので教えていただきたいです。
clearIntervat(setTimer);の下にdocument.writeで表示させようとしたのですがダメでした。
ゲームの内容
・スタートボタンと5つのスイッチを配置する.
・スタートボタンを押した後,残りチャレンジ回数は1秒ごとに1ずつ減少する.
・各スイッチに対して1~100までの乱数を割り当てる.各スイッチの値は一定時間(1秒)ごとにランダムに変化する.
・5つ数のうち最大数がクリックされると,その数だけポイントを加算する.(ポイントの初期値0)
・最大数以外がクリックされた場合,その数だけポイントから減算する.
・一定時間内に同じスイッチに対する有効なクリックは1回までとする.
・残りチャレンジ回数が0になった時点でゲームを終了する.
・ゲーム終了後,最大数をクリックした回数と取得したポイントを表示する
<html> <head> <script type="text/javascript"> var counter=5; var setTimer; function startTimer(){ setTimer=setInterval(changenum,1000); } function changenum(){ document.g_switch.gs_1.value = Math.floor (Math.random ( ) * 100)+1; document.g_switch.gs_2.value = Math.floor (Math.random ( ) * 100)+1; document.g_switch.gs_3.value = Math.floor (Math.random ( ) * 100)+1; document.g_switch.gs_4.value = Math.floor (Math.random ( ) * 100)+1; document.g_switch.gs_5.value = Math.floor (Math.random ( ) * 100)+1; document.g_switch.timer.value = counter; counter -= 1; if(counter<0){ endscreen(); } } var clicknum; function point(i){ var point=0; var max = Math.max(document.g_switch.gs_1.value,document.g_switch.gs_2.value,document.g_switch.gs_3.value,document.g_switch.gs_4.value,document.g_switch.gs_5.value); if(document.g_switch.gs_i.value==max){ point += document.g_switch.gs_i.value; clicknum += 1; }else if(document.g_switch.gs_i.value!=max){ point -= document.g_switch.gs_i.value; } } function endscreen(){ clearInterval(setTimer); document.getElementById("show").innerHTML = clicknum; } </script> </head> <body> <form name="g_switch"> <input type="button" name="timer" value="start" onclick="startTimer()" style="widht:50px; height: 50px; font-size:20px;"> <p> <input type="button" name="gs_1" value="SW1" onclick="point(1)" style="widht:50px; height: 50px; font-size:20px;"> <input type="button" name="gs_2" value="SW2" onclick="point(2)" style="widht:50px; height: 50px; font-size:20px;"> <input type="button" name="gs_3" value="SW3" onclick="point(3)" style="widht:50px; height: 50px; font-size:20px;"> <input type="button" name="gs_4" value="SW4" onclick="point(4)" style="widht:50px; height: 50px; font-size:20px;"> <input type="button" name="gs_5" value="SW5" onclick="point(5)" style="widht:50px; height: 50px; font-size:20px;"> <p id="show"></p> </form> </body> </html> コード