This nested for adds up until i and j are both 3 currently. How can I reset the variables once they've capped so I can continue the loop?
Or is that not the correct thought process?
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've tried a while loop, but it's consistently crashing. I'm just a bit iffy on the logic of the problem.
What I'm trying to do:
If the user answers correctly at any point, the loop ends. But I don't want the math to add above 6. Once it hits 6 I'd preferably like it to reset back to for both i and j.
user_input != ans. If user answers wrong they get stuck inside that loop and with an overheating computer.. nothing else!