|
<SCRIPT>
var question = "What is 10 + 10?";
var answer = 20;
var correct = '<IMG SRC="images/correct.gif">';
var incorrec = '<IMG SRC="images/incorrec.gif">';
// ask the Question
var response = prompt(question,
"0");
// making sure that there was an answer
if (response != null) {
// check the first
answer
if (response != answer) { //
the answer was wrong: offer a second chance
if (confirm("Wrong!
Press OK for a second chance."))
response = prompt(question, "0");
else
// if the user didn't want a second chance
incorrec = "<H1>Good Bye</H1>";
}
else { // the
answer was right: offer a second Question
if (confirm("Correct! Press OK
for a second question.")) {
question = "What is 10 * 10?";
answer = 100;
response = prompt(question,
"0");
}
else
// if the user didn't want a second chance
correct = "<H1>Good Bye</H1>";
}
}
else { // if the user cancelled out
incorrec = "<H1>Good
Bye</H1>";
}
// check the answer
var output = (response == answer) ? correct : incorrec;
</SCRIPT>
<BODY>
<SCRIPT>
document.write("<CENTER>"
+ output + "</CENTER>");
</SCRIPT> |