I have come accross a problem in using the following code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Addition</title>
<script type="text/javascript">
var num1,
num2,
answer,
correctAnswer;
num1 = Math.round(Math.random()*20);
num2 = Math.round(Math.random()*20);
correctAnswer = num1 + num2;
function getAnswer(){
var value = parseInt(document.form.number.value);
if(comparingAnswer(value) == 1){
document.writeln("Correct! Well Done." + num1 + " + " + num2 + " = " + correctAnswer);
}
else{
document.writeln("Incorrect." + num1 + " + " + num2 + " = " + correctAnswer);
}
}
function comparingAnswer(answer){
if (answer == correctAnswer){
return 1;
}
else{
return 0;
}
}
document.writeln("<form name=\"form\">");
document.writeln("<table>");
document.writeln("<tr><td>" + num1 + " + " + num2 + " = " + "</td><td><input style = \"font-size:200%\" name = \"number\" type = \"text\" /></td></tr>");
document.writeln("</table>");
document.writeln("</form>");
</script>
</head>
<body onkeydown = "if(event.keyCode==13){document.getElementById(getAnswer()).click();}"
</body>
</html>
The code works fine, but what I am trying to do with this code is make it work as a loop.
What I want is when the user hits enter (answers the question) it will take you to another question (20 questions in total). Then after that, it will display what questions you got wrong and what questions you got right. When I tried to loop it before, it just gave me two questions instead of one and it wouldn't let you know if you were right or wrong. The loop never ended.
Plus, I want to make the text bigger. The text box I can make bigger no problem , but the actual sum I can only make it as big as +6.
Could someone please help me with this?