Iterating Over Hashes


#1



I've gone over this a million times and have compared it to other's work, but it still doesn't work, what am I doing wrong?


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

secret_idententies.each do |super, not|
    puts "#{super}: #{not}"
end
  


(ruby):7: syntax error, unexpected keyword_super, expecting '|'
secret_idententies.each do |super, not|
                                 ^


#2

Check the spelling of your variables.
secret_identities != secret_idententies.each


#3

Apart from the mentioned spelling error, the code is using two reserved words for variable names. We should never use keywords as variable names.

secret_identities.each do |key, value|
    puts "#{key}: #{value}"
end

#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.