Vote count:
0
Currently in the midst of my 2nd assignment, a simple maths quiz according to my lecturer. Been searching through the site for answers. Totally new to programming. Similar to my last problem, I'm not allowed to edit the html file. I have to call functions via an external .js script file.
HTML file:
<tr>
<td><div id="number1">1</div></td>
<td><div>+</div></td>
<td><div id="number2">2</div></td>
<td><div>=</div></td>
<td><input type="text"></input></td>
<td><input type="button" value="Check"></input></td>
</tr>
1.User should be able to enter his desired answer.
2.Upon pressing the “check” button, an alert box informs the user if the answer is correct or wrong
3. When the user dismisses the alert box, the application generates a new random set of numbers
4. The math operands (i.e., the two numbers) are randomly generated and contain integer values from 1 to 10.
The external js file that I have came up with is
$(document).ready(function() {
$('.Check').click(function(){
var answer=document.getElementById(":text").value;
var num1=document.getElementById("number1").value;
var num2=document.getElementById("number2").value;
rnum1=Math.floor(Math.random() * 11);
rnum2=Math.floor(Math.random() * 11);
num1.innerHTML=rnum1;
num2.innerHTML=rnum2;
var total = num1 + num2;
if(answer==="")
{
alert("Please enter an answer");
}
else if(answer===total)
{
alert("Correct");
}
else
{
alert("Incorrect!");
}
});
});
Can't get it to work. I know I need to replace the numbers and randomise but can't find the right code to append the text. Appreciate your assistance.
Maths Quiz Problems
Aucun commentaire:
Enregistrer un commentaire