9. Accessing Hash Values problems

Hi guys. I used this specific hash for “pets”:pets=Hash.new

pets[“Kayla”]=“dog”
pets[“colour”]=“brown and white”
pets = {
“Kayla” => “dog”,
“colour” => “brown and white”
}
pets.each do |x, y|
puts “#{x}: #{y}”
end

And although it copies pretty much fine onto the console, the error message keeps on saying, “Oops, try again. It looks like you didn’t print out the value of each of the keys stored in your hash.” But the key values were printed out onto the console. Am I doing something wrong? (I used the each method because the other one, as given in the example, doesn’t work either.)

@microslayer00982,
Have you tried using

puts "#{y}"

as with #{x} you would also have a key output,
but they are asking for the associated-Value

1 Like

Hey, There i am trying to print the hash values?
But it’s not printing!

lunch_order = {
“Ryan” => “wonton soup”,
“Eric” => “hamburger”,
“Jimmy” => “sandwich”,
“Sasha” => “salad”,
“Cole” => “taco”
}

@naid0512,

lunch_order.each do |x, y|

x is the KEY and y the =associated= VALUE

puts “#{x}: #{y}”
end

My code looks like this, but it still says Oopss!
lunch_order = {
“Ryan” => “wonton soup”,
“Eric” => “hamburger”,
“Jimmy” => “sandwich”,
“Sasha” => “salad”,
“Cole” => “taco”
}

lunch_order.each do |x, y|
puts “#{x}: #{y}”
end

Oops, try again. It looks like you aren’t printing the value part of each key-value pair on its own line. Check the hint if you need help!

@naid0512,
Have you read
9. Accessing Hash Values problems

Oh thank you, but i got that problem already. I will read it though for information!

Just tried it. I don’t understand how, but it works. Thank you so much :slight_smile: