Hashes and symbols exercise 15 more methods more solutions


here is the page:

here is my code:
movie_ratings = {
memento: 3,
primer: 3.5,
the_matrix: 3,
truman_show: 4,
red_dawn: 1.5,
skyfall: 4,
alex_cross: 2,
uhf: 1,
lion_king: 3.5

Add your code below!

movie_ratings.each_key { |k| print k, " " }
movie_ratings.each_value { |v| print v, " " }
puts k, movie_ratings[k]


here is the error i am getting:
Oops, try again. Your syntax doesn't look quite right. Check the examples in the instructions if you need help!

here is what appears in the console:
memento primer the_matrix truman_show red_dawn skyfall alex_cross uhf lion_king 3 3.5 3 4 1.5 4 2 1 3.5 undefined local variable or method `k' for #

what am i doing wrong?
thank you


This scope does not have a k variable. It is a different scope than the block where k occurs.

To iterate both key and value, use .each:

movie_ratings.each { |movie, rating| puts "#{movie}: #{rating}" }


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