if (Test condition)
//If the condition is TRUE then these statements will be executed
//If the condition is FALSE then these statements will be executed
If the test condition present in the above structure is true then True statements will be executed, if the condition is false then False statements will be executed.
Let us see the flow chart for better understanding.
If the test condition is true then STATEMENT 1 is executed followed by STATEMENT N. If the condition is False then STATEMENT 2 is executed followed by STATEMENT N is executed because it is out of the if else condition block and it has nothing to do with the condition result.
In this program we are going to place four different statements. If the condition is true we will display two different statements, if the condition is false we will display another two statements.
var marks = 60;
if( marks >= 50 )
document.write("<b> Congratulations </b>"); //s1
document.write("<br\> You Passed the subject" ); //s2
document.write("<b> You Failed </b>"); //s3
document.write("<br\> Better Luck Next Time" ); //s4
OUTPUT 1: Here marks is 60 and the Condition is TRUE that’s why, statements inside the If Statement is displayed as Browser output
OUTPUT 2: Here we changed the marks variable to 30. It means the Condition is FALSE that’s why, statements inside the Else Statement is displayed as Browser output
Thank You for Visiting Our Blog