you could store the question and answers in a multidimensional array like follows
// [question number, answer, question]
var qanda =[
[1,15,"Add 11 + 4"],
[2,7,"Add 4 + 3"],
[3,7,"Subtract 9 - 2"]
];
function getQuestion(n){
document.getElementById("disp_question").innerHTML = qanda[n][2];
document.getElementById("intp_div").style.display = "block";
}
function checkAnswer(n){
if(document.getElementById("intp_answer").value != undefined){
if(document.getElementById("intp_answer").value == qanda[n][1]){
alert("correct")
}else{
alert("incorrect")
}
}
}
And you could add this below your retry button
<div id="intp_div" style="display:none">
<h3 id="disp_question"></h3><input id="intp_answer" type="text" value=""><input type="button" value="Submit Answer" onclick="checkAnswer(2)" />
</div>`
this it just to hepl you get on your way Note:
onclick="checkAnswer(2)"
the “2” is the question your refferencing from the q and a array
3
solved exam with timer in javascript [closed]