FAQ: A Night at the Movies - What You'll Be Building

This community-built FAQ covers the “What You’ll Be Building” 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 What You’ll Be Building

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!

Is there a way of continuing to ask the user for input? So for example in this exercise, once you’ve finished writing the code and you test it, if you write ‘display’, it displays all the movies. But what if you wanted to then add a book as well? How would you continue to get user input?

It seems when you have movie titles with more than one word it requires an adjustment in the code :

“medium thing”.gsub(/\s+/,"_").downcase.to_sym => :medium_thing

title = title.gsub(/\s+/,"_")

if movies[title.to_sym].nil?

Films are generally given proper names, and many have more than one word in the title. All we need to do is let Ruby convert them.

your command: 
Movie title: 
A Night At The Movies
Movie rating: 
A Night At The Movies added with rating 4.

puts movies

{:Crash=>4, :Babel=>4, :"A Night to Remember"=>2, :"A Night At The Movies"=>4}

Arbitrarily altering the inputs affects natural search. Ruby can handle multiple word names.

Would you say this is the most concise and effective solution?

i don’t really have an opinion other that already stated. If the user inputs a proper name, we should endeavor to preserve it as inputted without alteration. string.to_sym is something we can convert back to the original string. If we alter it, then we lose the naturalness of the input, and cannot feasibly convert back to what it was initially, especially if the case is changed.

Are you saying there is a way to use .to_sym? Yes or no? I did not gather that from your initial response
If so how would you go about doing so?

Yes, there is.

puts # prompt
title = gets.chomp
if movies[title.to_sym].nil?
    puts # prompt
    rating = gets.chomp
    movies[title.to_sym] = rating.to_i

The above preserves the case and word count of the user input.

See the above hash for how Ruby converts multi-word strings to symbol.

Whenever I used this code the program did not recognize the title as already in the hash unless I included the underscore between each word of the title as it was written in symbol

That would suggest the hard coded values were snake_case. Use the symbol pattern shown above when hard coding the hash.

:"A Night at the Movies" => 4
1 Like