Javascript Reference Card Page 2

ADVERTISEMENT

IF-ELSE Statement: A conditional branching statement
INITIALIZING VARIABLES
that includes a path to follow if the condition is TRUE and
Use the declaration statement to assign a value to the vari-
a path to follow if the condition is FALSE.
able. The value is on the right of the equal sign; the variable
Format:
is on the left.
Format:
if
(condition)
{
statements if condition is TRUE;
var
variable_name = value
}
Examples:
else
{
var
myHouseColor = “yellow”
statements if condition is FALSE;
[literal string value yellow assigned to variable
}
myHouseColor]
Example:
var
myAddress = 473
if
(score >= 65) {
[numeric value 473 assigned to variable myAddress]
grade = “Pass”;
var
bookTitle = “Time Capsule”, cost =
message = “Congratulations”;
28.95, publisher = “Tucker Bay”
}
[multiple variables can be assigned in one statement]
else
{
grade = “Fail”
message = “Try again”;
DECISION MAKING AND
}
CONTROL STRUCTURES
IF-ELSE IF Statement: A conditional branching statement
Definition: Statements and structures used to change the
that allows for more than two possible paths. The first time
order in which computer operations will occur.
a true condition is encountered, the statement is executed
Types:
and the remaining conditions will not be tested.
Conditional Branching IF , IF-ELSE, IF-ELSE IF , SWITCH,
Format:
WHILE, DO, FOR
if
(condition) {
Statements if condition is TRUE;
CONDITIONALS
}
IF Statement: A conditional branching statement used to
else if (condition)
{
determine whether a stated condition is TRUE.
Statements if condition is TRUE;
}
Format:
else
{
if
(condition)
{
Statements if no prior condition is
statements if condition is TRUE
true;
}
}
Example:
if
(score >= 65”)
{
grade = “Pass”;
message = “Congratulations”;
}
2

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go
Page of 6