Conditional statements:
◼️ The
if statement executes a statement if a specified condition is truthy. If the condition is falsy, another statement can be executed.
◼️ Multiple
if...else statements can be nested to create an else if clause. Note that there is no elseif (in one word) keyword in JavaScript.
Example:
var WhoIsHere ='teacher'
if (WhoIsHere =='teacher') { //change the value(user) to check futher conditon
if (WhoIsHere =='teacher') { //change the value(user) to check futher conditon
console.log('Welcome teacher')
console.log('Allow access to view all courses')
}else if(WhoIsHere =='user'){
console.log('Welcome ')
console.log('Allow access to view his courses')
}
else{
console.log('MESSAGE:Plz verify your email')
}
switch statement evaluates an expression, matching the expression's value to a case clause, and executes statements associated with that case, as well as statements in cases that follow the matching case.
var day = 2
switch (day) {
case 1:
console.log("Sunday");
break;
case 2:
console.log("Monday");
break;
case 3:
console.log("Tuesday");
break;
case 4:
console.log("Wednesday");
break;
case 5:
console.log("Thrusday");
break;
case 6:
console.log("Friday");
break;
case 7:
console.log("saturday");
break;
default:
console.log("Enter Number Between 1 to 7");
break;
}


0 Comments