Javascript Reference Card Page 3

ADVERTISEMENT

Example:
Example:
if
(score>=90)
{
switch (colorchoice)
{
grade=”A”;
case “red”:
}
document.bgColor=”red”;
else if
(score>=80)
{
break;
grade=”B”;
case “blue”:
}
document.bgColor=”blue”;
else if
(score>=70)
{
break;
grade=”C”;
default:
}
document.bgColor=”white”;
else if
(score>=65)
{
break;
grade=”D”;
}
}
LOOPS
else
{
grade=”F”;
Loops cause a segment of code to repeat until a stated
}
condition is met. You can use any loop format for any
type of code
SWITCH Statement: An alternative to the IF-ELSE IF
statement for handling multiple options. Compares the
FOR LOOP:
expression to the test values to find a match.
Format:
Format:
For (intialize; conditional test;
switch (expression or variable name)
{
increment/decrement)
{
Statements to execute;
case label:
}
statements if expression matches
Example:
this label;
For (var i=0; i<=10; i++)
{
break;
document.write (“This is line “ + i);
case label:
}
statements if expression matches
DO/WHILE LOOP:
this label;
Format:
break;
default:
do
{
Statements to execute;
statements if expression does not
}
match any label;
while (condition);
break;
Example:
}
var i=0;
do
{
document.write (“This is line “ + i);
i++;
}
while (i <=10);
3

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go
Page of 6