JAVASCRIPT CONDITIONAL STATEMENT
JAVASCRIPT CONDITIONAL STATEMENT
- By Mohammad --
- Monday, 31 May, 2021
JAVASCRIPT CONDITIONAL STATEMENT
CONDITIONAL STATEMENTS
Types of Conditional Statement
1. IF
EXAMPLE : let x=8;
if (x>15) {
Document.write ("AMD");
}
2. IF-ELSE
EXAMPLE : let x=8;
if (x>15) {
Document.write ("AMD");
} else {
Document.write ("2AMD2");
}
3. IF-ELSE IF-ELSE
EXAMPLE :
<html>
<head>
</head>
<body>
SCRIPT
let marks="32";
if (marks > 60) {
Document.write ('First');
} else if (marks>=45 && marks<=60) {
Document.write ('Second Class');
} else {
Document.write ('Fail');
}
/SCRIPT
</body>
</head>
</html>
4. SWITCH-CASE
EXAMPLE
<html>
<head>
</head>
<body>
SCRIPT
let age=55;
TP=600;
DO=400;
DM=100;
DS=200;
switch(true) {
case age>65:
TP=TP-DO;
[removed] (TP);
break;
case age<8>
TP=TP-DS;
[removed] (TP);
break;
case age>=45 && age<=60:
TP=TP-DM;
[removed] (TP);
break;
default:
[removed] ('SORRY');
}
/SCRIPT
</body>
</html>
5. TERNARY OPERATOR
EXAMPLE :
<html>
<head>
</head>
SCRIPT
let x=10;
let result=(x>15)?"Happy":"Sad";
[removed] (result);
/SCRIPT
</body>
</html>
These are the Conditional Statements in Javascript with Example Programs.