Using the Ternary Operator in JavaScript
📖 Scenario: You are creating a simple program to check if a person is old enough to vote. Voting age is 18 years or older.
🎯 Goal: Build a program that uses the ternary operator to decide if a person can vote based on their age.
📋 What You'll Learn
Create a variable called
age with a specific number value.Create a variable called
votingAge and set it to 18.Use the ternary operator with
age and votingAge to create a variable canVote that holds the string 'Yes' or 'No'.Print the value of
canVote.💡 Why This Matters
🌍 Real World
Checking age eligibility is common in many apps like voting, driving licenses, or age-restricted content.
💼 Career
Understanding the ternary operator helps write clean and concise code, a useful skill for any developer.
Progress0 / 4 steps