簡単なJavascript数学プログラムがあります。方程式に答えることができ、答えをチェックすると、正解か不正解かを警告します。
追加のコードは次のとおりです。
function randomAdd()
{
var x=document.getElementById("AddN1");
x.value=Math.floor((Math.random()*12)+1);
var y=document.getElementById("AddN2");
y.value=Math.floor((Math.random()*12)+1);
}
function checkAdd()
{
var z=document.getElementById("AddA2");
z.value= parseInt(document.getElementById("AddN1").value) + parseInt(document.getElementById("AddN2").value);
if(parseInt(document.getElementById("AddA1").value)==z.value)
{
score=score+1;
alert("Addition: Correct");
}
else
{
alert("Addition: Incorrect");
}
}
<form name="Addition">
<table>
<tr>
<th>Addition</th> <th></th> <th></th> <th></th> <th></th> <th></th>
</tr>
<tr>
<th>Number 1</th> <th></th> <th>Number 2</th> <th></th> <th>Type Your Answer</th> <th>Correct Answer</th>
</tr>
<tr>
<td><input type="text" name="AddN1" id="AddN1"></td> <td>+</td> <td><input type="text" name="AddN2" id="AddN2"></td> <td>=</td> <td><input type="text" name="AddA1" id="AddA1"></td> <td><input type="text" name="AddA2" id="AddA2"></td>
</tr>
<tr>
<td><input type="button" value="Get Numbers" onclick="randomAdd();"> <td></td> <td></td> <td></td> <td><input type="button" value="Check Answer" onclick="checkAdd();"> <th></th>
</tr>
</table>
</form>
コードは私の大学から提供されました。ユーザーが取得したすべての正解をカウントする単純なカウンターと、カウンターをゼロにリセットするリセットボタンを保持したいですか?
これが本当に基本的なことのように聞こえたら申し訳ありませんが、私はJavascriptの経験がありません。
ありがとう。