09/10 Delete Won't Delete!


#1

I am stuck on "Delete" Test #9. For some reason my delete function keeps coming up with the "else" statement message.


Replace this line with your code. 
Here is my code:

movies = {
    "Fight Club" => 5,
    "The Namesake" => 4.5,
    "Pest" => 3.5
}

puts "What would you like to do?"
puts "Add a movie:"
puts "Update a movie:"
puts "Display all movies:"
puts "Delete a movie:"
choice = gets.chomp
case choice
when "add"
puts "Name your new movie!"
title = gets.chomp
if movies[title.intern].nil?
    puts "Give it a rating from 0-5"
    rating = gets.chomp
    movies[title.intern] = rating.to_i
    puts "Okay! Your movie is added to the list!"
else
    puts {"#{title} already exists!"}
end
when "update"
puts "Which movie would you like to update?"
title = gets.chomp
if movies[title].nil?
    puts "The movie #{title} is not in our database. Try again."
else
    puts "What is the new rating for this movie?"
    rating = gets.chomp
    movies[rating.to_i]
    puts "Great we will alter the rating in the database for #{title} right now!"
end
when "display"
movies.each do |movie,rating|
    puts "#{movie}: #{rating}"
end
when "delete"
puts "Which title would you like removed from the database?"
title =  gets.chomp
if movies[title.to_sym].nil?
    puts "That movie is not in the database. Try another choice?"
else
    movies.delete[title.to_sym]
    puts "Okay. the movie #{title} has been removed from the database."
end
else
    puts "Error!"
end


#2

.delete() is a method.


#3

Thank you for that I'm dumb lol but the problem is it is still saying the (else) statement message that "the movie isn't in the database" even though it is.......


#4

What code do have now for,

    when "delete"

?


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.