Javascript: Creating A Programmable Web
Javascript: Creating A Programmable Web
JavaScript
OR
y = x--;
y = -x;
Assignment Operators 27
function function_name(parameters) {
JavaScript commands/statements
}
if (condition) {
JavaScript Commands
}
condition is an expression that is either true or
false
if the condition is true, the JavaScript Commands
in the command block are executed
if the condition is not true, then no action is taken
Comparison, Logical, and 38
Conditional Operators
To create a condition, you need one of three types
of operators:
a comparison operator compares the value of
one element with that of another, which creates
a Boolean expression that is either true or false
a logical operator connects two or more
Boolean expressions
a conditional operator tests whether a specific
condition is true and returns one value if the
condition is true and a different value if the
condition is false
An Example of 39
Boolean Expressions
x < 100;
if x is less than 100, this expression returns the value
true; however, if x is 100 or greater, the expression is
false
y == 20;
the y variable must have an exact value of 20 for the
expression to be true
comparison operator uses a double equal sign (==)
Comparison Operators 40
A Logical Operator 41
if (condition) {
JavaScript Commands if true
} else
JavaScript Commands if false
}
condition is an expression that is either true or
false, and one set of commands is run if the
expression is true, and another is run if the
expression is false
if...else Conditional Statement
document.write("Today is " + ThisMonth +
"/“+ThisDay+"/"+ThisYear+"<br />");
if (DaysLeft > 0) {
document.write("Only "+DaysLeft+
" days until Christmas");
} else {
document.write("Happy Holidays from
Nroth Pole Novelties");
}
Working with Dates 45
DayValue = DateObject.getDate()
Retrieving the Month Value 47
<head>
<script src="library2.js"
type="text/javascript"></script>
</head>
var MonthName=MonthTxt(ThisMonth);
Working with Program Loops 57