Conditional Statements: ======================= Simple If if else nested if else if else if else ladder nested if else ============== Syntax: if(condition-1) { if-block if(condition-2) { block-2 } else { block-3 } } else { else block if(condition-3) { block-4 } else { block-5 } } // defining three numbers var a = 121,b = 201,c = 191; var big = 0; // defining the logic to find biggest among three numbers if(a > b) // checking the first number with remaining for finding the biggest { if(a > c) { big = a; } else { big = c; } } else { if(b > c) { big = b; } else { big = c; } } console.log("The Biggest number is = "+big); =========================================================== if else if else ladder ====================== Syntax: if(condition-1) { block-1 } else if(condition-2) { block-2 } else if(condition-3) { block-3 } ... else { block-n } // WAP TO FIND THE SMALLEST NUMBER AMONG FIVE NUMBERS. var a = 11,b = 91,c = -1,d = 0,e = 22; var small = 0; if(a < b && a < c && a < d && a < e) { small = a; } else if(b < c && b < d && b < e) { small = b; } else if(c < d && c < e) { small = c; } else if(d < e) { small = d; } else { small = e; } console.log("The Smallest number = "+small); ================================= WAP TO CHECK THE TYPE OF THE TRIANGLE. Equilateral Isosceles Scalene ================================================== Iterative Statements: ==================== ==> also called as "Looping Statements". ==> when we need to execute the certain block of code for several times repeatedly. ==> three types: 1) while 2) do-while 3) for ==> to work with these: we required three things: 1) Initialization 2) Update 3) Condition ex: 1 to 10 start = 1 log(start); start = start + 1; log(start) start = start + 1; log(start) while loop statement: ===================== Syntax: initialization with loop variable; while(condition_with_loop_variable) { while loop body update } // WAP TO PRINT NUMBERS FROM 1 TO 10 USING WHILE LOOP. var start = 1; while(start < 11) { console.log(start); ++start; // start++ or start += 1 or start = start + 1 } ==================== // WAP TO PRINT NUMBERS FROM 100 TO 1 WITH THE DIFFERENCE OF 8. var start = 100; while(start >= 1) { console.log(start+"\t"); start-=8; } ===================== floor(): ======= Math.floor(1.234) ==> 1 // WAP IN JAVASCRIPT TO FIND THE SUM OF INDIVIDUAL DIGITS OF A NUMBER. var n = 12345; var s = 0; var start = n; while(start > 0) { ind_dig = start % 10; // 5 4 3 2 1 s = s + ind_dig; // 5 9 12 14 15 start = Math.floor(start / 10);// floor(1234.5) = 1234 ==> floor(123.4) = 123 } console.log("Sum of Digits = "+s); ======================================== Assignments: ============ 1) WAP IN JS TO COUNT THE NUMBER OF DIGITS OF A NUMBER. 2) WAP IN JS TO REVERSE THE NUMBER.