FAQ: A Night at the Movies - Nice Work!


#1

This community-built FAQ covers the “Nice Work!” 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 Nice Work!

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!


#3

I added a menu which included an exit because I wrapped the whole thing in a loop for more fun. I also used .downcase! on choice just in case.
Fun exercise. :grinning:


#4

Hi I’m trying to add a block of code to this movie library ruby project that picks a movie at radom but keep getting this error: undefined method `sample’ for nil:NilClass

Code below. Bold area is the code that generates the error.

movies = {
memento: 3,
toy_story: 3,
gladiator: 4,
avengers: 4
}

puts “What would you like to do?”

choice = gets.chomp

case choice

when “add”
puts “Movie to be added?”
title = gets.chomp
if movies[title.to_sym].nil?
puts “Add a rating (0 to 4)”
rating = gets.chomp
movies[title.to_sym] = rating.to_i
puts “#{title.capitalize}” " has been added with a rating of" " #{rating}"
else
puts “#{title.capitalize}” " already exists. It has a rating of"" #{rating}."
end

when "update"

puts “Which movie do you want to update?”
title = gets.chomp
if movies[title.intern].nil?
puts “Sorry,” " #{title.capitalize}" " wasn’t found!"
else
puts “Please add a new rating (0 to 4) for” " #{title.capitalize}."
rating = gets.chomp
movies[title.intern] = rating.to_i
puts “#{title.capitalize}” " has been updated with a new rating of" " #{rating}."
end

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

when “delete”
puts “Which movie do you want to delete?”
title = gets.chomp
if movies[title.intern].nil?
puts “Sorry, that movie wasn’t found!”
else
movies.delete(title.intern)
puts “#{title.capitalize}” " deleted!"
end

when "random"
** if movies.nil?**
** puts “Nothing to see here!”**
** else**
** puts “#{title.sample}: #{rating}”**
** end**

else
puts “Error!”
end


#5

Is sample defined anywhere?