Ruby - Variables and Data TypesIdentify the error in the following Ruby code: str = 'It's a sunny day'ASyntaxError due to missing double quotesBNo error, string is validCSyntaxError due to unescaped single quote inside single-quoted stringDRuntime error due to invalid stringCheck Answer
Step-by-Step SolutionSolution:Step 1: Check string delimiters and contentThe string uses single quotes outside and contains an unescaped single quote inside (It's), which breaks syntax.Step 2: Understand how to fix the errorTo fix, either escape the inner single quote as \' or use double quotes outside.Final Answer:SyntaxError due to unescaped single quote inside single-quoted string -> Option CQuick Check:Escape inner quotes or use double quotes [OK]Quick Trick: Escape inner quotes or use double quotes [OK]Common Mistakes:Ignoring the need to escape inner single quotesAssuming single quotes allow unescaped inner single quotesConfusing syntax and runtime errors
Master "Variables and Data Types" in Ruby9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Ruby Quizzes Hashes - Merge and update methods - Quiz 4medium Hashes - Hash creation with symbols and strings - Quiz 13medium Methods - Explicit return statement - Quiz 12easy Operators and Expressions - Logical operators (&&, ||, !) - Quiz 10hard Operators and Expressions - Spaceship operator (<=>) - Quiz 14medium Ruby Basics and Runtime - Running scripts with ruby command - Quiz 10hard Ruby Basics and Runtime - Comments and documentation - Quiz 12easy Ruby Basics and Runtime - What is Ruby - Quiz 8hard Variables and Data Types - Local variables and naming conventions - Quiz 13medium Variables and Data Types - Symbol type and immutability - Quiz 6medium