|
<SCRIPT>
// define variables for the rest of the
script
var question = "What is 10 + 10?"; //
create the question
var answer = 20;
var correct = '<IMG SRC="correct.gif">'; //
"correct" gif for the answer is correct
var incorrec = '<IMG SRC="incorrec.gif">'; //
"incorrec" gif for the answer is wrong
// ask the question
var response = prompt(question, "0");
// "return" the
"correct" gif if the person gets the answer right else
// "return" the
"incorrec" gif if the person gets the answer wrong
// output
is a global variable that is available to the entire page
var output = (response == answer) ?
correct : incorrec;
</SCRIPT>
<BODY>
<SCRIPT>
// output the results - either the
correct.gif or incorrec.gif
document.write(output);
</SCRIPT>
Remember - everything gets evaluated from top to bottom. Steps:
- Create the variables
- Ask the question
- Evaluate the result
- Assign the result to output
- Write out the output
|