A Night At the Movies (Delete problem?)


#1

Hello everyone,

For RUBY "A Night at the Movies," my code is below. (https://www.codecademy.com/en/courses/ruby-beginner-en-0i8v1/0/9?curriculum_id=5059f8619189a5000201fbcb#)

Can you please tell me why my code doesn't seem to work? Is it a problem with my 'delete' branch?

Thanks, in advance, for your help/suggestions.

movies = {
Lord_of_the_Rings: 5,
ET: 3.5,
Starwars: 4
}
puts "What would you like to do?"
puts "-- Type 'add' to add a new movie title."
puts "-- Type 'update' to update an existing movie title."
puts "-- Type 'display' to display movies."
puts "-- Type 'delete' to delete a movie."
choice = gets.chomp
case choice
when "add"
puts "What movie would you like to add?"
title = gets.chomp
if movies[title.to_sym].nil?
puts "How would you rate this movie? (on a scale from 0 to 5.)"
rating = gets.chomp

movies[title.to_sym] = rating.to_i
puts "#{title} has been added with a rating of #{rating}."
else 
    puts "That movie already exists! Its rating is #{movies[title.to_sym]}."
end

when "update"
puts "What movie do you want to update?"
title = gets.chomp
if movies[title.to_sym].nil?
puts "Movie not found!"
else
puts "What's the new rating? (from 0 to 5.)"
rating = gets.chomp
movies[title.to_sym] = rating.to_i
puts "#[title] has been updated with a new rating of #{rating}."
end
when "display"
movies.each do |movie, rating|
puts "#{movie}: #{rating}"
when "delete"
puts "What movie do you want to delete?"
title = gets.chomp
if movies[title.to_sym].nil?
puts "Movie not found!"
else
movies.delete(title.to_sym)
puts "#{title} has been removed."
end

end


#2

@ecchan13,

movies.each do |movie, rating|
 puts "#{movie}: #{rating}"
end

#3

I'd forgotten to use "end." Many thanks! :wink: