Bird
0
0

Find the error in this Ruby code:

medium📝 Debug Q7 of 15
Ruby - Hashes
Find the error in this Ruby code:
h = { name: "Anna" "age" => 22 }
AInvalid symbol key syntax
BHash keys must be unique
CString keys cannot be used
DMissing comma between key-value pairs
Step-by-Step Solution
Solution:
  1. Step 1: Check separation of pairs

    The hash pairs are not separated by a comma between "Anna" and "age".
  2. Step 2: Confirm other syntax

    Symbol key syntax and string keys are valid, and keys can be mixed.
  3. Final Answer:

    Missing comma between key-value pairs -> Option D
  4. Quick Check:

    Commas separate hash pairs [OK]
Quick Trick: Always put commas between hash pairs [OK]
Common Mistakes:
MISTAKES
  • Omitting commas between pairs
  • Confusing symbol and string key syntax
  • Assuming keys must be all symbols or all strings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes