8. display


Hi I’m having trouble with this lesson. Here is my code:
movies = { Madagasgar_3: 4, Home: 3, Shaun_The_Sheep_The_Movie: 2 } puts "Night at the movies" choice = gets.chomp case choice when "add" puts "Enter a Title" title.to_sym = gets.chomp movies[title.to_sym].nil = movies when "rating" puts"Enter a rating" rating.to_i = gets.chomp movies = {} movies[title.to_sym].nil = rating.to_i when "update" puts "Enter a title" title = get.chomp if movies[title].nil puts "error" else movies[title.to_sym] end when "display" movies.each puts {movie}: #{rating} when "delete" puts "Deleted!" else puts”Error!" end



Instead of doing this to check if the title of the movie is already in the hash, you can do it with an if statement:

if movie[title.to_sym].nil?
    #if it does not exist, we prompt the user for the rating and enter the new movie in movies hash
    #we tell the user the movie is already in the hash

Remove the .nil we do not need to test if the user’s output is already in the hash since we already did it.

Do not put rating because this is referring to the switch statement. We only want the user to input Add, Delete or Update not rating. Beside, this part of code should be inside your if statement.