Iterating Over Hashes

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

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.

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

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.

1 Like

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.

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

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.

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