#9 not recognizing the movie in the hash...possible bug?


#1

Hey guys...when I tested out the delete part of the case statement by typing in Inception, I am given the if part of the message: "That movie was never added." But its strange because the movie Inception is in the hash...and I decided to peek into the first lesson's example and it is exactly the same. Anybody else encountering this issue?Here's my code:

movies = {
    "Inception" => "4",
}

puts "Would you like to add, update, display or delete a movie and the rating?"
choice = gets.chomp.downcase

case choice

when "add"
    puts "What is the name of the movie?"
    title = gets.chomp
    if movies[title.to_sym].nil?
        puts "Great. Now what rating do you want to give it?"
        rating = gets.chomp
        movies[title.to_sym] = rating.to_i
        puts "Added."
    else
        puts "That movie and its rating was already added."
    end

when "update"
    puts "What's the name of the movie?"
    title = gets.chomp
    if movies[title].nil?
        puts "This movie is not yet added."
    else
        puts "What is the rating?"
        rating = gets.chomp
        movies[title.to_sym] = rating.to_i
        puts "Updated."
    end

when "display"
    movies.each { |movie, rating| puts "#{movie}: #{rating}" }
    
when "delete"
    puts "What movie would you like to delete?"
    title = gets.chomp
    if movies[title.to_sym].nil?
        puts "That movie was never added."
    else
        movies.delete(title.to_sym)
        puts "Deleted!"
    end
else
    puts "Wrong choice. Try again."
end

#2

Hint:
In the delete case,

if movies[title.to_sym].nil?

you are checking if the symbol form of the title doesn't exist in the movies, whereas you have stored a string form in the hash:

movies = {
    "Inception" => "4",
}

Hope it helps! :smiley:


#3

That did the trick. I guess I got confused with that. Thanks.