If Statement Basics in JavaScript
📖 Scenario: You are creating a simple program to check if a person is old enough to vote. In many countries, the voting age is 18 years.
🎯 Goal: Build a program that uses an if statement to check if a person's age is 18 or older and print a message accordingly.
📋 What You'll Learn
Create a variable called
age with a specific number value.Create a variable called
votingAge set to 18.Use an
if statement to check if age is greater than or equal to votingAge.Print
'You are old enough to vote.' if the condition is true.Print
'You are not old enough to vote.' if the condition is false.💡 Why This Matters
🌍 Real World
Checking conditions like age limits is common in websites and apps, for example, to allow access to age-restricted content.
💼 Career
Understanding if statements is a basic skill for any programming job, as it helps make decisions in code.
Progress0 / 4 steps