Ruby - Operators and ExpressionsWhich of these is a valid use of the ternary operator in Ruby?Aresult = score > 50 ? 'Pass' : 'Fail'Bif score > 50 then 'Pass' else 'Fail' endCscore > 50 ? 'Pass' and 'Fail'Dresult = score > 50 : 'Pass' ? 'Fail'Check Answer
Step-by-Step SolutionSolution:Step 1: Check the syntax of each optionresult = score > 50 ? 'Pass' : 'Fail' uses the correct ternary format: condition ? true_value : false_value. if score > 50 then 'Pass' else 'Fail' end is an if-else statement, not ternary. score > 50 ? 'Pass' and 'Fail' uses 'and' incorrectly. result = score > 50 : 'Pass' ? 'Fail' mixes symbols wrongly.Step 2: Confirm the correct ternary syntaxOnly result = score > 50 ? 'Pass' : 'Fail' correctly assigns 'Pass' or 'Fail' based on the condition using the ternary operator.Final Answer:result = score > 50 ? 'Pass' : 'Fail' -> Option AQuick Check:Valid ternary syntax = result = score > 50 ? 'Pass' : 'Fail' [OK]Quick Trick: Ternary uses ? and : in order [OK]Common Mistakes:Using 'and' instead of ':'Swapping '?' and ':'Writing if-else instead of ternary
Master "Operators and Expressions" in Ruby9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Ruby Quizzes Arrays - Array modification (push, pop, shift, unshift) - Quiz 1easy Hashes - Default values for missing keys - Quiz 7medium Loops and Iteration - Break, next, and redo behavior - Quiz 12easy Methods - Method naming conventions (? and ! suffixes) - Quiz 13medium Methods - Method declaration with def - Quiz 7medium Methods - Bang methods (ending with !) - Quiz 10hard Methods - Why methods always return a value in Ruby - Quiz 8hard String Operations - Heredoc syntax for multiline strings - Quiz 8hard Variables and Data Types - Dynamic typing vs strong typing - Quiz 9hard Variables and Data Types - String creation (single and double quotes) - Quiz 10hard