14.becoming more selective


#1

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}

#2

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


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

#4

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


#5

@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.


#6

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?


#7

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

#9

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...


#10

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


#11

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