DEV Community

swetha palani
swetha palani

Posted on

JavaScript in 3 Day – Conditional Statements

A condition statement (also called conditional statement) is used in programming to perform different actions based on different conditions.

if Statement
Use the if statement to specify a block of JavaScript code to be executed if a condition is true.

SYNTAX

if (condition) {
  //  block of code to be executed if the condition is true
} 
Enter fullscreen mode Exit fullscreen mode

else Statement

Use the else statement to specify a block of code to be executed if the condition is false.

SYNTAX

if (condition) {
  //  block of code to be executed if the condition is true
} else {
  //  block of code to be executed if the condition is false
}
Enter fullscreen mode Exit fullscreen mode

TASK 2

Vote eligibile

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <script>
        let i= 18;
        if(i>=10){
            console.log("He is eligibile for vote");
        }
        else{
             console.log("He is not eligibile for vote");
        }
    </script>
</head>
<body>

</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)