Conditional Statements in Java Script
Conditional statements are used to perform different actions based on different conditions. In JavaScript, you can use if, else if, and else statements to create these conditions.
Here's an example of an if statement that checks whether a variable is equal to a specific value:
javascript
var age = 18;
if (age < 18) {
console.log("You are too young to vote.");
} else if (age >= 18 && age < 21) {
console.log("You can vote but not drink.");
} else {
console.log("You can vote and drink.");
}
No comments:
Post a Comment