13. Iterating over hashes


#1

hey guys, I think I'm doing this right, here is my code:

secret_identities = {
"The Batman" => "Bruce Wayne",
"Superman" => "Clark Kent",
"Wonder Woman" => "Diana Prince",
"Freakazoid" => "Dexter Douglas"
}
secret_identities.each do |costume, person|
puts " #{costume}: #{person} "
end

Here is the error I'm getting:
It looks like you aren't printing each colon-separated key-value pair on its own line. Check the hint if you need help!


#2

Extra spaces maybe? (I haven't done the exercise or tried this, but I'm guessing they aren't asking for those spaces)


#3

Under your code
puts " #{costume}: #{person} "
you need to erase the spaces right after and before the "s

secret_identities = {
"The Batman" => "Bruce Wayne",
"Superman" => "Clark Kent",
"Wonder Woman" => "Diana Prince",
"Freakazoid" => "Dexter Douglas"
}
secret_identities.each do |costume, person|
puts "#{costume}: #{person}"
end


#4

I was having the same problem when I tried to mirror the sample code. When I looked at my notes for Hash items I tried the following code and it worked. I am still confused why there is not a better description for this item.

secret_identities = {
"The Batman" => "Bruce Wayne",
"Superman" => "Clark Kent",
"Wonder Woman" => "Diana Prince",
"Freakazoid" => "Dexter Douglas"
}

secret_identities.each { |x, y| puts "#{x}: #{y}" }