Accessing Hash Value problems


This is my code

pets =
pets = {
"Stevie" => "cat",
"Bowser" => "hamster",
"Kevin Sorbo" => "fish"
puts pets ["Stevie"]

Despite doing what the computer says and getting the desired name on screen, I get a wrong notation.

I get the following message: "Oops, try again. It looks like you didn't print out the value of each of the keys stored in your hash." Despite clearly getting the name typed.

Can anyone help?



It says to print each key doesn't it?


Well, with this code it doesn't help either

puts pets ["Stevie", "Bowser", "Kevin Sorbo"]


Wouldn't it be better to tell ruby to print each one than to list them yourself? What if there was a million of them, would you really do it that way? Or what if it changed every few milliseconds?


And how do you do that?


The second exercise of the category has an example of that:
But that doesn't look like where you are, no idea where you are or what the instructions ask for. The error message says to print each one, I suspect they explain how they want that done in that exercise?


I got it, thanks for helping me out!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.