Iterating Over Hashes


#1

Hey so I am confused as to why this isn't working my code is as follows

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

error i get is

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

the interpreter says this

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

The error says thats its not being put on its own line but obviously is, so I'm confused. Can someone explain why this is not working thanks.


#2

okay so answering my own question the there is no space after the } in the puts block.


#3

I think it's a punctuation issue here, they want key: value, not key : value.

They should be more flexible in their error check in my opinion, especially when so many people are not native English speakers.

EDIT: great, good luck for the rest of the course.


#4

haha i am a native english speaker lol, I don't know why it gets us on the punctuation when a space in the code in that instance would have worked just as well. haha.


#5

Yeah, I meant users in general ^^. I guess just a space would do.


#6

I've got the same error no matter whether I put spaces or not.

I simply didn't read instructions carefully. In this case it hasn't expected iteration, just simple access like this puts pets["Stevie"] one by one.


#7

do not put a space between #{x} and :