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 - Operators and Expressions
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

    Passing means score is 50 or more, so condition should be score >= 50.
  2. Step 2: Check ternary syntax and values

    grade = score >= 50 ? "Pass" : "Fail" uses correct condition and assigns "Pass" if true, "Fail" if false. Others have wrong conditions or syntax.
  3. Final Answer:

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

    Correct condition and syntax assign grade properly [OK]
Quick Trick: Use >= for inclusive conditions in ternary [OK]
Common Mistakes:
  • Using > instead of >=
  • Swapping true/false values
  • Incorrect ternary syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes