I have a simple Javascript Math program. It lets you answer equations and when it checks your answer it alerts whether you answered correctly or wrongly.
Here is the code for addition:
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>
The code was provided to me by my college. I would like to keep a simple counter that will count all the correct answers the user gets and also a reset button that would reset the counter back to zero?
Sorry if this sounds really basic but I have no experience with Javascript.
Thanks.