Bird
0
0

Identify the error in this Ruby hash creation:

medium📝 Debug Q14 of 15
Ruby - Hashes
Identify the error in this Ruby hash creation:
data = { :city => "Paris", country: "France", "population" => 2148327, state } 
AHash keys cannot mix symbols and strings
BIncorrect symbol syntax for :city
CMissing value for key 'state'
DString keys must use colon syntax
Step-by-Step Solution
Solution:
  1. Step 1: Check each key-value pair

    Keys :city, country, and "population" have values. The key 'state' is written without a value, which is invalid.
  2. Step 2: Identify syntax error

    Every key in a hash must have a corresponding value. Missing value for 'state' causes syntax error.
  3. Final Answer:

    Missing value for key 'state' -> Option C
  4. Quick Check:

    All keys need values in hash = Missing value for key 'state' [OK]
Quick Trick: Every key must have a value; check for missing pairs [OK]
Common Mistakes:
  • Leaving keys without values
  • Confusing symbol and string key syntax
  • Assuming mixed keys cause errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes