13. Iterating Over Hashes


<Below this line, add a link to the EXACT exercise that you are stuck at.>
13. Iterating Over Hashes

<In what way does your code behave incorrectly? Include ALL error messages.>
While performing this exercise, I first attempted to use “alias” as ‘x’ and “name” as ‘y’ but after running the code it didn’t work. When I replaced these with just ‘x’ and ‘y’ it worked. How come? I thought that by entering any label for each in |x, y| the puts line would be able to discern this and run the code as long as the labels match up. Please assist.


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

secret_identities.each do |alias, name|
puts “#{alias}: #{name}”

<do not remove the three backticks above>

Have you read the error messages?

jsims.rb:8: syntax error, unexpected keyword_alias, expecting '|'
secret_identities.each do |alias, name|

The error messages confuse me. haha.

Sure, but have you read it? Or are you not reading it because at a glance it looks confusing?

Which part is confusing? Let’s start at the first part, jsims.rb:8:, what might that mean? I think that looks like a file name and a line number, that was pretty straight-forward. Then move on to the next part of the message.

If you avoid reading it then you will not be able to find what it means to say. Read it and identify what stops you from understanding it, and then consider how you can approach that obstacle, for example if there is a phrase in it that you don’t understand, then googling that phrase is very likely to produce an answer to what it means.


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