Javascript Chp 5 If statements in JS

 <!DOCTYPE html>

<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
    </head>
    <body>
        <script>
              // No.1 -  The if-else statements
              let age = 16;
        if(age>=18) {
            console.log("He's an adult","Because the age is greater than or equal than 18");
        } else{
            console.log("Babua hamaar !!", "Because the age is not greater than 18");    
        }
       
        // No.2 -  The if statements
       
        let yy = 33;
        if(yy % 2 === 0){
            console.log("The is even my friend")
        }
        if(yy % 2 !== 0){
            console.log("The is not even my friend")
        }
       
        // No.3-  The else-if statements
        const x = -50;
       
        if (x > 0) { console.log("Positive.");}
       
        else if (x < 0) {console.log("Negative.");}        
       
        else {console.log("Zero.");}

       
        // No.4  The Nested if statements
        // JavaScript program to illustrate nested-if statement
        let i = 10;
       
        if (i == 10) {  // First if statement
        if (i < 15) {
        console.log("i is smaller than 15");
        // Will only be executed if statement above
        // it is true
        if (i < 12)
            console.log("i is smaller than 12 too");
        else
        console.log("i is greater than 15");
    }
}
        // No.5  The if else ladder statements
        // JavaScript program to illustrate nested-if statement
        {
        let i = 20;

        if (i == 10)
           console.log("i is 10");
        else if (i == 15)
          console.log("i is 15");
        else if (i == 20)
          console.log("i is 20");
        else
          console.log("i is not present");
        }
    </script>
    </body>
</html>

Comments

Popular posts from this blog

HTML FORMS

FORM STYLING IN CSS