Bird
0
0

You want to assign a grade based on score using a ternary operator. Which code correctly assigns "Pass" if score is 50 or more, otherwise "Fail"?

hard📝 Application Q8 of 15
Ruby - Control Flow
You want to assign a grade based on score using a ternary operator. Which code correctly assigns "Pass" if score is 50 or more, otherwise "Fail"?
Agrade = score >= 50 ? "Pass" : "Fail"
Bgrade = score > 50 ? "Pass" : "Fail"
Cgrade = score >= 50 ? "Fail" : "Pass"
Dgrade = score ? >= 50 "Pass" : "Fail"
Step-by-Step Solution
Solution:
  1. Step 1: Understand the condition for passing

    Pass if score is 50 or more means condition is score >= 50.
  2. Step 2: Check ternary operator usage

    grade = score >= 50 ? "Pass" : "Fail" correctly uses score >= 50 ? "Pass" : "Fail". grade = score > 50 ? "Pass" : "Fail" excludes 50, C reverses values, D has syntax error.
  3. Final Answer:

    grade = score >= 50 ? "Pass" : "Fail" -> Option A
  4. Quick Check:

    Use correct comparison and order in ternary [OK]
Quick Trick: Use >= for inclusive conditions in ternary [OK]
Common Mistakes:
MISTAKES
  • Using > instead of >=
  • Swapping true/false values
  • Syntax errors in condition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes