Web page Special effects if...else use of statements
If ' is evaluated in parentheses, the declaration is really executed; otherwise, the declaration is skipped.
If two or more lines of code are executed, the curly braces {} must be used to specify what code belongs to the if declaration.
Other keyword extensions to the basic functionality of the If Declaration are provided by other options.
if (expression)
Statement1;
Else
Statement2;
Instance
<script language= ' JavaScript '
<!--
var VarA = 2 ;
var varb = 5;
if (VarA = 0)
document.write ("VarA = 0");
& nbsp else {
if ((VarA * 2) >= Varb)
document.write ("(VarA * 2) >= Varb");
Else
document.write (VarA * 2) < Varb ");
document.write (Varb);
}
//-->
</script>
If else
if (statement) {
; Code;
}else (statement) {
code;
}
A specific case in which a If...else statement is logically stated.
If statements are satisfactory, their statements are executed.
else, the other statements were evaluated.
When the statement is to be true, the code is executed.
<script lanuguage= "JavaScript" >
<!--
var temp = 1;
if (temp = = True) {
document.write ("Statement is true");
} else{
document.write ("Statement is false");
}
-->
</script>
If ElseIf
<title>if...then...else...if</title>
<script type= "Text/javascript" >
var statecode = ' MO ';
if (statecode = = ' OR ') {
Taxpercentage = 3.5;
else if (statecode = = ' CA ') {
Taxpercentage = 5.0;
else if (statecode = = ' MO ') {
Taxpercentage = 1.0;
} else {
Taxpercentage = 2.0;
}
document.write (Taxpercentage);
</script>
<body>
</body>