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
}
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
}
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>
Top comments (0)