Delete! (My code won't work!)


So, here's my code. For some reason it keeps saying that there isn't an "end" on line 30 (between the display prompt and delete) when there is. And before you say to eliminate all of the "end"'s between each "when"'s, I tried and my code won't work. It asks me to put them back in.

So what am I missing? Or doing wrong here?

movies = {
    "Iron Man" => 4
puts "what would you like to do?"
choice = gets.chomp.downcase
case choice
when "add" 
puts "What would you like to add?"
title = gets.chomp
title = title.to_sym
if movies[title.to_sym].nil?
puts "What its rating? (enter 1-4)"
rating = gets.chomp
movies[title.to_sym] = rating.to_i
puts "#{title} has been added with a rating of #{rating}"
else puts "#{title} already exists. Its rating is #{movies[title.to_sym]}!" 
when "update"
puts "What title would you like to update?"
title = gets.chomp
    if movies[title].nil?
        puts "This movie does not exist."
        puts "What is the new rating?"
        movies[title.to_sym] = rating.to_i
when "display"
movies.each { |movie,rating| puts "#{movie}: #{rating}" }
when "delete"
puts "Which title would you like to delete?"
title = gets.chomp
if movies[title.to_sym].nil?
    puts "This movie does not exist"
    puts "#{title} has been removed"


The end in the above may be removed since you are using a block, rather than a do..end. Try that and report back, please.


It worked only if I added more end's at the end...
Which is strange because I tried that the first time around and it didn't work.


This should be written in symbol form. If you try to add 'Iron Man' it will let you since it doesn't find the symbol in your hash.

    :'Iron Man' => 4


Which exercise should we test your code in? Please post a link. Thank you.