Using the Ternary Operator in Ruby
📖 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 Ruby 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 integer value.Create a variable called
voting_age set to 18.Use the ternary operator to create a variable
can_vote that holds the string "Yes" if age is greater than or equal to voting_age, otherwise "No".Print the value of
can_vote.💡 Why This Matters
🌍 Real World
Checking conditions quickly is common in programs, like deciding if someone can access a service based on age.
💼 Career
Understanding the ternary operator helps write concise and readable code, a skill valued in many programming jobs.
Progress0 / 4 steps