Hashes and Symbols


#1

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

I used this piece of code:
good_movies = movie_ratings.select {|m,r| r > 3}

good_movies = movie_ratings.select do |m,r|
if r > 3
puts m
end
end
to finish this lesson, but it gave me an error, saying that "good_movies don't include prime"

so i did this, i puted +1 after the letter m
good_movies = movie_ratings.select {|m,r| r > 3}

good_movies = movie_ratings.select do |m,r|
if r > 3
puts m + 1
end
end
and give me an error on console but let me go to next lesson, can someone please help me?


#2

@josephstalion,
Try it with

good_movies = movie_ratings.select {|m,r| r > 4}
puts good_movies
puts "==========="
movie_ratings.select do |m,r|
 if r > 3
 puts m
 end
end

#3

Thanks Sir it works! If you could explain to me why does the program accept the plus "m + 1" to finish the course but dont accept the other code, it would make me understand a bit more.


#4

@josephstalion,

How it is that you surpassed the code-checker by using m+1 i do not know....

What i do know is that the code-checker expects good_movies to be an Array

good_movies = movie_ratings.select {|m,r| r > 4}
puts good_movies.instance_of? Array

#5

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