As of now, this nested for loop continues until both i and j reach 3. How can I reset the variables once they have reached their maximum value so that the loop can continue running?
Alternatively, is my current approach incorrect?
for (i=1; i<=3; i=i+1)
{
for (j=1; j<=3; j=j+1)
{
ans=i + j;
document.write(i + "+" + j + "=" + "<br />");
var user_input = prompt("What is your answer?",0);
while (user_input != ans) {
if (ans == user_input)
{
document.write("Yes, the answer is " + ans + "<br />");
}
else
{
document.write("No, the answer is " + ans + "<br />");
}
}
}
}
I attempted to use a while loop, but it keeps crashing. I am struggling with the logic behind the problem.
My goal is:
If the user answers correctly at any point, the loop should end. However, I want to ensure that the sum does not exceed 6. Once it reaches 6, I would like both i and j to reset.