FAQ: A Night at the Movies - Not My Type

This community-built FAQ covers the “Not My Type” exercise from the lesson “A Night at the Movies”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Ruby

FAQs on the exercise Not My Type

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

So the following is the code I’m using for this section of the exercise:

  	puts "What movie would you like to add?"
  	title = gets.chomp
  	puts "What is your rating for the movie? (Use 1-4)"
  	rating = gets.chomp
        movies[title.to_sym] = rating.to_i
    	puts "Your movie was added!"

My problem is this adds the key to hash as a symbol with quotation marks. For example: :“The Waterboy”. Is there a way to get the program to not add those quotation marks?

It involves changing all the space chararacters to an underscore. That will require more logic since we will ultimately need to search our database on normal titles. If our hash contains, say,

"A Night to Remember": 2

we can query the data for an exact match on the quoted string. If we use the quoted string and have the symbol written as,


will the query return a match?

Our logic will need to examine all user inputs, run a conversion method on them, store them in the hash as symbols if not already there, or retrieve the symbol and its data, and convert back to a normal string so it can be matched to the input.

For now, one suggests leave the strings as they are presently converted. Once you finish the project, the more complex logic can be written into your code. It should be able to return 2 for a query on "A Night to Remember", even if the hash key is written as a snakecase symbol.

1 Like

I’m getting an error again when using the bang method on downcase. When I remove the bang it works fine. The bang method also only works when any of the letters I type are uppercase.

Or, any uppercase. That was going to be our next discovery. What have you concluded?

to not use the bang method? :upside_down_face:

To know when to use the bang method.

1 Like

How would I change it so that no matter how the input was put in (uppercase/lower or mixed) it would still work? I’m lost… In the previous post you responded to me saying we have to use the bang method.

Use assignment from CHOMP and there will be no problems. Bang methods are best used inside blocks where things are more predictable.

a = gets.chomp.downcase

When I run the code, it prompts me "What would you like to do? " and when I type add, it puts "What movie would you like to add?
What rating does the movie have? " at the same time. It doesn’t give me a chance to type in what movie I want to add. I thought it was a problem with my code, but when I clicked get help, and ‘get code solution’ and run that code, this error still happens. Doesn’t seem like anyone else is having this problem? Is this a bug or am I missing something?

1 Like

It’s an old course in an old environment that is not supported any longer. The workaround is to not get user input, but assign literal values to the variables so you can see the program run through its paces. I know that is not much to offer, but it does see one across the line.

1 Like

same for me :confused: I will have to run the solution to keep going

Why do we have to convert the movie title to a symbol anyway? Can we not use the title string as a hash key?

Learn How to Blog and Build Websites for Profit!

I ran the following code and I got the green check that it was correct, however the movie didn’t exist in the hash and the result said “That movie already exists”. So what did I do wrong?

movies = {
StarWars: 4.8,
Divergent: 4.7

puts "What would you like to do? "

choice = gets.chomp

case choice
when “add”
puts "What movie would you like to add? "
title = gets.chomp.to_sym
puts "What rating does the movie have? "
rating = gets.chomp.to_i

if movies[title.to_sym] = nil
movies[title] = rating
puts “That movie already exists!”


What would you like to do?
What movie would you like to add?
What rating does the movie have?
That movie already exists!

The = is used for assignment. If you wish to check for equality, you should use ==

if movies[title.to_sym] = nil
should be edited to:
if movies[title.to_sym] == nil

Oh ok that makes sense, thank you!

1 case choice
2 when “add”
3 puts "What movie would you like to add? "
4 title = gets.chomp.to_sym
5 puts "What rating does the movie have? "
6 rating = gets.chomp.to_i
7 movies[title] = rating

I am having a hard time understanding what is the purpose of line 7. I do not understand it. It somehow tells me that the title of movies is now rating? is [title] a temporary holder? Please explain.

movies.each do |title, rating|
puts “#{title}: #{rating}”

the above code snippet parses ok. Why is the below code snippet NOT accepted?

movies.each { |title,rating| puts “#{title}: #{rating}”}

title is now a symbol.

rating is an integer

movies is the hash identifier, title is the key, rating is the value associated with that key.

 identifier[key] = value
|         hash          |
1 Like