Conditional Statements ======================= Sequential Execution: ===================== ==> Statement after the statement Ex: statement-1 statement-2 statement-3 Why conditional statements? =========================== to make execute the application based on the selection we can use "conditional statements". Types of Conditional Statements: ================================= ==> different types: 1) simple if statement 2) if-else statement 3) nested if else statement 4) if else if else ladder statement 5) switch statement here, all the above statements must be work according to the condition. condition ==> Relational operators (<, >, <=, >=, ==, !=) 1) simple if statement ====================== Syntax: if(condition) { // if-block statements statement-1; statement-2; } ==> if the condition is "true" then, the control can execute the statements in if-block. If the condition is "false", there is no output from the given program/application. ==> To overcome this, if we can define a statement after the if block: in this case: if the condition is "false" then, the control can execute the statement after the if block. But when the condition is "true" then, the control can execute the program as normal (sequential execution). Document ===================================== 2) if-else statement ==================== Syntax: if(condition) { // logic for if block } else{ //logic for else block } Document =========================================================== Document

XYZ Bank

===================================================== 3) nested if else statement =========================== Syntax: ====== if(condition1) { //if block // statements if(condition2) { //logic } else{ //logic } } else{ if(condition3) { //logic } else{ //logic } } a = 12 b = 21 c = 11 if(a > b){ if(a > c){ console.log("a is biggest."); } else{ console.log("c is biggest."); } } else{ if(b > c){ console.log("b is biggest."); } else{ console.log("c is biggest."); } } ================================================ 4) if else if else ladder statement ==================================== Syntax: if(condition1){ //logic } else if(condition2) { //logic } else if(condition3){ //logic } else{ //logic } Document Assignment: =========== 1) WAP IN JAVASCRIPT TO FIND THE BIGGEST NUMBER AMONG THE TWO NUMBERS. 2) WAP IN JAVASCRIPT TO FIND WHETHER THE GIVEN NUMBER IS POSITIVE OR NEGATIVE. 3) WAP IN JAVASCRIPT TO CHECK WHETHER THE GIVEN NUMBER IS EVEN OR ODD.