9. Accessing Hash Values problems


#1

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.)


#2

@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


#3

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"
}


#4

@naid0512,

lunch_order.each do |x, y|
# x is the KEY and y the =associated= VALUE
puts "#{x}: #{y}"
end


#5

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!


#6

@naid0512,
Have you read
http://discuss.codecademy.com/t/9-accessing-hash-values-problems/26787/2?u=leonhard.wettengmx.n


#7

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


#8

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