Click to See Complete Forum and Search --> : Help me fix js code!


donald d
04-23-2003, 12:03 PM
Im gonna pull my hair out!

Is there anyone out there that can change this code to do the following:

Insert a while loop that will stay there saying no until the user gets the right answer and then it will give the right answer and move on.

????????

thanks,
DD

AdamBrill
04-23-2003, 12:46 PM
Ok, try this:<HTML>
<HEAD>
<TITLE>Math Facts</TITLE>
</HEAD>
<BODY>
<H2>MATH FACTS 1..3</H2>
<SCRIPT LANGUAGE="JavaScript">
for (i=1; i<=3; i=i+1)
{
for (j=1; j<=3; j=j+1)
{
ans=i + j;
document.write(i + "+" + j + "=" + "<BR>");
keepgoing=true;
while(keepgoing){
var user_input = prompt("What is your answer?",0);
if (ans == user_input)
{
document.write("Yes, the answer is " + ans + "<BR>");
keepgoing=false;
break;
}
else
{
document.write("No...<BR>");
}
}
}
}
</SCRIPT>
</H3>
</BODY>
</HTML>Let me know if you need more help... ;)

donald d
04-23-2003, 03:25 PM
thanks adam!