Bird
0
0

You want to print "Good morning" only if the variable hour is less than 12 using inline modifier. Which code is correct?

hard📝 Application Q8 of 15
Ruby - Control Flow
You want to print "Good morning" only if the variable hour is less than 12 using inline modifier. Which code is correct?
Aputs 'Good morning' if hour < 12
Bputs 'Good morning' unless hour < 12
Cputs 'Good morning' if hour > 12
Dputs 'Good morning' unless hour > 12
Step-by-Step Solution
Solution:
  1. Step 1: Understand condition for printing

    We want to print only if hour is less than 12.
  2. Step 2: Match condition with inline modifier

    Using inline if with condition hour < 12 prints correctly.
  3. Final Answer:

    puts 'Good morning' if hour < 12 -> Option A
  4. Quick Check:

    Use inline if for positive condition [OK]
Quick Trick: Use inline if for positive conditions [OK]
Common Mistakes:
  • Using unless with positive condition
  • Reversing comparison operators
  • Confusing when to print

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes