Iterating Over Hashes


#1



This is my error when I click on Submit and save button.

=>

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!


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



Output=

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


#2

Remove the . after end. Also add a space between "#{si1}: and #{si2}" just for visual improvement. hope that helps

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

secret_identities.each do |si1,si2|
puts" #{si1}: #{si2} "
end


#3

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