If else condition

 

Mastering JavaScript: Unleashing the Power of If-Else Conditions for Web Development:

In JavaScript, an if-else statement allows you to make decisions and execute different blocks of code based on a condition. It follows a simple structure:

if (condition) {
  // Code to execute if the condition is true
} else {
  // Code to execute if the condition is false
}

The condition is a logical expression that evaluates to either true or false. If the condition is true, the code within the first block will run. Otherwise, the code within the else block will execute.





If you have multiple conditions to check, you can use else-if statements:

        if (condition1) {
  // Code to execute if condition1 is true
} else if (condition2) {
  // Code to execute if condition1 is false and condition2 is true
} else {
  // Code to execute if both condition1 and condition2 are false
}


By utilizing if-else statements and conditions, you can create dynamic and responsive JavaScript code that performs different actions based on specific criteria.

 file Name: TUT51IFELSE.HTML
<!DOCTYPE html>
<html lang="en">

<head>
    //1. DIFF B/W 'let', 'var' & 'const'.
    //2. IF ELSE CONDITION
    //3. SWITCH CUPS CASES
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>scope, and conditions</title>

</head>

<body>
    <!-- div>ul>li{item-$}*7 -->
    <div>
        <ul>
            <li>item-1</li>
            <li>item-2</li>
        </ul>
    </div>
    <script>
//1. DIFF B/W 'let', 'var' & 'const'.

        /*var string1= 'this is  string1';
        var string1= 'this is  string2';
        var string1='this is string3';
         console.log(string1);*/

        /* let a= "U";
          //let a= "sk"; shows error - we can't take variable 'a' again if we use 'let'
           console.log(a);
         // for use variable 'a' again we must use under {} braces as below.
             { let a = "U8";
               console.log(a);}  */

        /*const a ='This cannot be changed';
     // a = "I want to change this . This cannot be changed.";
        console.log(a);    */

//2. IF ELSE CONDITION
        let age = 5;
        if (age >= 18) {
            console.log("YOU'RE ELIGIBLE FOR VOTING");
        }
        else {
            console.log("SORRY, YOU'RE NOT ELIGIBLE FOR VOTING");
        }

        /*      let age= 5;
              if(age>18){
                console.log("you should drink water");
              }
              else if(age==5){
                 console.log("You're eligible so, you can play in water");
             }
             else{
                  console.log("you can drink cold water");
             }               */

//3. SWITCH CUPS CASES
        //  break nhi lagane par ye value ke bad bale sare cases ko run kr dega
        /*         const cups =42;
         switch (cups) {
             case 41:
                 console.log("The value of cups is 41");
                  break;
             case 42:
                 console.log("The value of cups is 42");
                  break;
             case 47:
                 console.log("The value of cups is 47");
                  break;
             case 44:
                 console.log("The value of cups is 44");
                 break;
       
             default:
                 console.log(" Sorry, The value of cups is none of 41,42,47,44.");
                  break;
         }           */

    </script>
</body>

</html>

OUTPUT:
SORRY, YOU'RE NOT ELIGIBLE FOR VOTING


👉see in detail

Comments

Popular posts from this blog

Knapasack

Data types & Operators

COMPLETE WEB DEVELOPMENT BOOTCAMP:practice.html