Tutorial 8: Programming with JavaScript
Creating a Programmable Web Page for North Pole Novelties
Additional Topics
JavaScript Resources on the Web
If you want more information on using JavaScript, here are some resources on the Web:
- DevEdge Javascript Reference
- JavaScript FAQ Knowledge Base (irt.org)
- JavaScript Forum
- The JavaScript Planet
- JavaScript Resources
- JavaScript: Stupid Web Tricks Revisited (from C|Net)
- JavaScript WebRing
- Netscape's JavaScript Developer Central
- ProjectCool: JavaScript Zone
Interrupting Loops
If you are creating a loop, you can use the break and continue commands to alter the loop's operation.
The break command halts the loop, even if the conditions to end the loop have not been met. For example, if you want to create a loop that prompts students to answer a question, and give them three chances to answer that question, you can use the following JavaScript program:
for (i=1;i<=3;i++) {
answer=prompt("In what year did
the Civil War begin?","");
if (answer=="1861") {
alert();
break;
}<
}
In this example, if the answer variable is equal to "1861" (the correct answer) the loop stops with the break command. If the student answers the question incorrectly, the loop continues for 3 iterations or until the question is answered correctly. Note that you can learn more about the alert() and prompt() methods in Tutorial 8. To see this JavaScript program in action, click the button below: