9/16 Accessing Hash Values


#1

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.


#2

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

Thank you very much!!
It works!


#4

You're very welcome :smile:


#5

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?


#6