Bird
0
0

Find the error in this Ruby code snippet:

medium📝 Debug Q7 of 15
Ruby - Hashes
Find the error in this Ruby code snippet:
h = {x: 10, y: 20}
h[:z] = 30
puts h.z
AAssigning new key-value pair is not allowed
BUsing dot notation to access hash key
CMissing colon in hash key
Dputs cannot print hash values
Step-by-Step Solution
Solution:
  1. Step 1: Understand hash access methods

    Ruby hashes do not support dot notation for key access.
  2. Step 2: Identify incorrect access

    puts h.z is invalid; correct is puts h[:z].
  3. Final Answer:

    Using dot notation to access hash key -> Option B
  4. Quick Check:

    Hash keys accessed with brackets, not dot [OK]
Quick Trick: Access hash keys with brackets, not dot notation [OK]
Common Mistakes:
MISTAKES
  • Using dot notation for hashes
  • Thinking new keys cannot be added
  • Confusing hash syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes