14. Becoming more selective - why the error?


#1



https://www.codecademy.com/en/courses/ruby-beginner-en-Qn7Qw/2/4?curriculum_id=5059f8619189a5000201fbcb


The answer looks right but the error message says "Primer" is not included when I can see it. I am not sure what is wrong. After spending a few minutes staring at the screen, I DID find an alternative solution (basically copied the example given and changed some text) but the rejection here has left me scratching my head.


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.select do |m,r|
    if r>3
        puts m
    end
end


#2

Note that it doesn't say anything about what's printed, but about what's in good_movies


#3

I'm still not sure what I am missing with it unfortunately.

Why isn't line14 including "Primer" into the equation?


#4

Equations are something else. Not sure what you mean, I have to guess.

If you mean that you now agree that primer isn't included, then the thing to do next is consider why it would have been included. It would have been included because that's what Hash's select method does, therefore that isn't being done right. Next thing is to figure out how it's supposed to be used. To that end you can read documentation for Hash#select or have a look at ruby tutorials found by googling. Start with the docs.
https://ruby-doc.org/core-2.4.0/Hash.html#method-i-select


#5

Thanks for the link. I realised that I have some basic misunderstandings of what I "think" certain pieces of code should be doing, versus what they are actually doing. There have been a few times where I perhaps found the answer by chance as opposed to it being a sure thing. The code explanation on the link kind of confirmed it as I was left even more confused lol!

I am going to jump back a few lessons and review some of the core concepts. This should put things into better perspective (I hope!).

Thank you again for spending time helping out people like myself, it is really appreciated!


#6

Returns a new hash consisting of entries for which the block returns true.

There are three words there that you should already know, the rest is regular English

hash
block
returns

So if you're not clear on one of those, then you've identified the next thing to look up. Perhaps you need to look up more things while looking those up. Eventually you'll return to the select method with enough understanding.

^ That's what recursion is by the way. Repeat the same process for a smaller part of the problem, when it's solved, the bigger problem can be solved by using that information.


#7

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