15. More Methods, More Solutions


#1

hello guys im having trouble to this .

here is my code and obviously seems not working pls help

# Add your code below!
movie_ratings = { one: 1, two: 2, three: 3 }

movie_ratings.each_key { |k| print k, " " }
# ==> one two three

movie_ratings.each_value { |v| print v, " " }
# ==> 1 2 3

15. More Methods, more Solutions
#2

Hi, you are not supposed to delete the original code for movie_ratings.


#3

yeah i just figure it out :slightly_smiling: thanks


#4

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
}
movie_ratings_puts = { one: 1, two: 2, three: 3 }

movie_ratings.each_key { |k| print k, " " }

movie_ratings.each_value { |v| print v, " " }

Could someone tell me what is wrong with my code?

Oops, try again. It looks like you didn't print out memento using puts.

Thanks in advance...


#5

First,
this exercise asks you to puts in the iterator not to print it.

Second,
it asks you to puts out the titles, of which refers as the keys into the movie_ratings hash's.

At last,
you'll only need a single line of code to end this one.


#6

change all print to puts


#7

movie_ratings.select {|k,v| puts k}

This works. Simple, effective.