0
0
Rubyprogramming~15 mins

Logical operators (&&, ||, !) in Ruby - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Logical Operators in Ruby
📖 Scenario: You are helping a small shop decide if a customer qualifies for a special discount. The shop has simple rules based on the customer's age and membership status.
🎯 Goal: Build a Ruby program that uses logical operators && and || to check if a customer qualifies for a discount.
📋 What You'll Learn
Create variables with exact names and values as instructed
Use logical operators && and || exactly as shown
Print the exact output string as instructed
💡 Why This Matters
🌍 Real World
Stores and businesses often use simple rules to decide if customers get discounts or special offers based on their age or membership.
💼 Career
Understanding logical operators is essential for writing conditions in programs, which is a key skill for any software developer.
Progress0 / 4 steps
1
Create customer data variables
Create a variable called age and set it to 25. Create another variable called is_member and set it to true.
Ruby
Need a hint?

Use = to assign values. For is_member, use true without quotes.

2
Create discount eligibility rules
Create a variable called is_senior and set it to false. Create a variable called min_age and set it to 60.
Ruby
Need a hint?

Remember to use false without quotes for boolean false.

3
Use logical operators to check discount eligibility
Create a variable called qualifies_for_discount that is true if the customer is a member and their age is less than min_age, or if they are a senior. Use && and || operators exactly as shown.
Ruby
Need a hint?

Use parentheses to group conditions clearly. qualifies_for_discount should be true if either condition is met.

4
Print the discount eligibility result
Print the exact text "Discount eligibility: true" or "Discount eligibility: false" depending on the value of qualifies_for_discount. Use puts and string interpolation with #{}.
Ruby
Need a hint?

Use puts and "Discount eligibility: #{qualifies_for_discount}" to print the result.