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 () 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 () below!
Agree with a comment or answer? Like () to up-vote the contribution!
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
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.
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
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.