9/16 Accessing Hash Values

Hello. Thanks to help me about this.
I type my code like:
pets = {
“Stevie” => “cat”,
“Bowser” => “hamster”,
“Kevin Sorbo” => “fish”,
}

puts pets[“Stevie”]

But it kept showing me:
Oops, try again. It looks like you didn’t print out the value of each of the keys stored in your hash.
I don’t know what’s happend.
Please help me.
Thank you.

According to the error message you are supposed to print to the console all values from your hash array.

Try to use each method:

pets.each { |x, y| puts y }
3 Likes

Thank you very much!!
It works!

You’re very welcome :slight_smile:

why is there not each. method of the introduction, the introduction code is here:
my_hash = { “name” => “Eric”,
“age” => 26,
“hungry?” => true
}

puts my_hash[“name”]
puts my_hash[“age”]
puts my_hash[“hungry?”]

but we have to add each. method?