<html> <head> <meta http-equiv="Content-Script-Type" content="text/javascript"> <meta http-equiv="Content-type" content="text/html; charset=UTF-8"> <title>正負の計算(和)</title> <script type="text/javascript"> <!-- function getRandom() { return Math.floor(Math.random() * 9+1); } // --> </script> </head> <body bgcolor="#ffffff"> <h2>正負の計算(和)</h2> <hr> <script type="text/javascript"> <!-- //質問の数 var n = 5; var a, b; var correct = 0;
//出題する for (var i = 1; i < n+1; i++) { a = getRandom()-5; b = getRandom()-5;
while(a==0){ a = getRandom()-5; }
if(a>0 && b>0) msg = a+"+"+b+"="; if(a>0 && b<0) msg = a+"+("+b+")="; if(a<0 && b>0) msg = "("+a+")+"+b+"="; if(a<0 && b<0) msg = "("+a+")+"+"("+b+")=";
ans = prompt(msg,"");
if (ans == a+b) { document.write('('+i+') 正解!<br>') correct++; } else{ document.write('('+i+') 残念!<br>') } }
//正解率を表示する document.write('<HR>'); document.write("<h2>正解率:", Math.round(correct/n *100), "%</h2>"); document.write("<p>", n, "問中", correct, "問正解", "</p>"); // --></script> <a href="seifu-wa.html">もう一度やる</a><br> <a href="JHSmath.html">終わる</a><br> </body> </html>
|