DEV Community

SELVAKUMAR R
SELVAKUMAR R

Posted on

switch case in java Script

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;
}
Enter fullscreen mode Exit fullscreen mode

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>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)