JavaScript If Statement
JavaScript If Statement
• If statement in JavaScript
• if did not match with any condition, then it will execute Statement or set of statement
statement that are written inside the else block at the }
end else {
Syntax
Statement or set of statement
if (expression/condition) {
}
Statement or set of statement
}
else if (expression/condition) {
If-else if statement Example
Example }
var marks =60; else if (marks > 60) {
if( marks > 90 ) document.write(“You are qualified for 60%
scholarship ");
{
}
document.write(“You are qualified for full
scholarship"); else {
} document.write(“Sorry! We cannot provide any
scholarship on this base");
else if (marks > 80) {
}
document.write(“You are qualified for 80%
scholarship ");
}
else if (marks > 70) {
document.write(“You are qualified for 70%
scholarship ");
Problem: If-else if statement in JS
->Write A JavaScript Program To Display Grade Of Student On The Basis Of Student Marks
According To Following Criteria:
• If condition is matched with any case, then statement or set of statement of that case will execute.
• Break statement: It will break the execution of the statements. It will break the control to execute more
• Default statement: If condition is not match with any case, then statement in side the default statement
will execute
Switch Problem in JS
Write A JS Program To Get A Character From User To Check It Is Vowel Or
Consonant
Switch Problem Solution in JS
Var char = ‘A’ break;
switch(‘A’) { case ‘O’:
case ‘A’: case ‘o’:
case ‘a’: document.write(“It is vowel”);
document.write(“It is vowel”); break;
break; case ‘U’:
case ‘E’: case ‘u’:
case ‘e’: document.write(“It is vowel”);
document.write(“It is vowel”); break;
break; default:
case ‘I’: document.write(“It is consonant”);
case ‘i’: }
document.write(“It is vowel”);