FAQ: A Night at the Movies - Display

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

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!

I think the test is broken because it is working as expected but the error I get tell me it is not…
Output: Cloud Atlas: 5
It looks like your ‘puts’ doesn’t include Cloud Atlas: 5.

movies = {
  "Cloud Atlas": 5
}

puts "Type 'add' to add a movie."
puts "Type 'update' to update a movie's rating."
puts "Type 'display' to display the list of the movies."
puts "Type 'delete' to delete a movie."
print "Enter your choice: "
choice = gets.chomp
case choice
  when "add"
    print "Please, enter the title: "
    title = gets.chomp.to_sym
    if movies[title].nil?
      print "Please, enter the rating: "
      rating = gets.chomp.to_i
      movies[title] = rating
      puts "The movie has been added."
    else
      puts "The movies is already stored."
    end
  when "update"
    print "Please, enter the title: "
    title = gets.chomp.to_sym
    if movies[title].nil?
      puts "The movies is not stored."
    else
      print "Please, enter a new rating: "
      rating = gets.chomp.to_i
      movies[title] = rating
      puts "The movie has been updated"
    end
  when "display"
    movies.each {|movie, rating| puts "#{movie}: #{rating}"}
  when "delete"
    puts "Deleted"
  else
    puts "Error!"
end
3 Likes

The below works for me finally:

movies.each do |movie, rating|

puts “#{movie}: #{rating}”

end

Im struggling a bit here as it i get error code stating that it doesnt include a movie and rating when it does.

Help please

1 Like

and when i asked for solution it gave me the exact same code

It seems to me that the tester is hard-coded and expects the output to be in a specific line. After I added a new blank line

puts ""

it passed the test

What does the error code mean “make sure to test your programme by choosing “display””? For example

Unfortunately the input issue is not going away anytime soon. It’s been an issue for the past couple of years, at least. There are two options…

  • manually supply a value to your variable then run the code to see the process unfold. Problem here is, more input required.
  • Take the code over to REPL.IT and run it there to see it implemented. Do the best you can to follow the instructions exactly. When your code runs to satisfaction, paste it back into the LE.

Oh, and the third possibility is to just get the solution. Be sure you understand the exercise, which is why I suggest doing it in repl.it.

Hi everyone.

I’m testing the display branch of my code and can’t figure out why it’s not working. Can anyone help please?

If you are using curly braces for the each block, then the puts needs to be inside the curly braces.
If you use do…end syntax, then the puts needs to be between the two keywords. Both forms below will work:

# Curly Braces
movies.each { |title, rating| puts "#{title}: #{rating}"}

# do...end
movies.each do |title, rating|
    puts "#{title}: #{rating}"
end
1 Like

My display block is not working correctly. Like others have posted about on here, it is telling me my first movie is not included in the puts even though it is clearly being printed on the console. I have tried with using a symbol for the key as well as using a string for the key with the same results. I looked at the solution and I have the same exact code as the solution. I even copy pasted the solution code into my code just in case I wasn’t seeing some small difference and I’m still getting the error. I suspect it is an issue with the website and not my code. Was anyone able to solve this issue?

EDIT
I was able to figure it out. You must use puts instead of print on the initial request for user prompt - line 5 in my code. If you use print, the program will not recognize it properly and think your display is not working properly. Change it to puts and you should get the green checkmark. You can change it back to print after the checkmark if you don’t like the way it looks.