14.becoming more selective

movie_ratings = {
  memento: 3,
  primer: 3.5,
  the_matrix: 5,
  truman_show: 4,
  red_dawn: 1.5,
  skyfall: 4,
  alex_cross: 2,
  uhf: 1,
  lion_king: 3.5
# Add your code below!
good_movies = movie_ratings
good_movies.select {|k,v| v > 3}

Oops, try again. It looks like good_movies includes memento, but it shouldn’t.
i don’t understand why??
topic: selecting only movies with a rating strictly greater than 3

Hi 王憲文,

You need to combine your last two lines into one so they look like this;

good_movies = movie_ratings.select{ |k, v| v > 3 }

what’s different between this case?
i think both ok?!
is’t it?

@datasolver67653 As far as I could tell, they’re both the same, and they both work. I think the exercise was expecting the code to be like I showed you above, which is why it failed you.

I tested it in a Ruby IDE out of curiosity, and discovered that you actually have to do it the way codecademy makes you, otherwise it won’t work. who knows why?

@landotheman Maybe you would need to set good_movies equal to the value? Like this:

good_movies = movie_ratings
good_movies = good_movies.select {|k,v| v > 3}

Can any of you tell me why this doesn"t work:
good_movies=movie_ratings.select do |x,y| puts x,y>3 end
and then is says primer isn’t included but it is…

Never mind sorry the
...|x,y| puts x,y>3 end
throws it off. Follow up question who knows why?

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