switch case in java Script



This content originally appeared on DEV Community and was authored by SELVAKUMAR R

Switch case is the control flow statement it execute the different block of code based upon the expression

It is the alternative for the if-else statement

Ex:

let mark = prompt("Enter the mark");

switch(true){
case (mark>=90):
console.log("Your grade is A+");
break;

case (mark>=80):
console.log("Your grade is A");
break;

case (mark>=70):
console.log("Your grade is B+");
break;

case (mark>=60):
console.log("Your grade is B");
break;

case (mark >=50):
console.log("Your grade is C");
break;

Default:
console.log("Your are fail");
break;
}

Task:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>login checks</title>
    <script>
        const username = "selvakumar";
        const password = "1234";

        let InputUsername = prompt("Enter the Username");
        let InputPassword = prompt("Enter the password");

        if (InputUsername == username && InputPassword == password) {
            alert("login Successfully");
        } else{
            alert ("Invalid Login");
        }




        const option = prompt("welcome to dashbord \n 1 view profile \n 2 settings \n 3 logout");






    </script>
</head>

<body>

</body>

</html>


This content originally appeared on DEV Community and was authored by SELVAKUMAR R