7/10 Code run, but it can't find the movie


#1

I've tried something so I can update one of the movie but it'll display an output of "Movie not found"
This is my code:
movies = {
"Ironman" => 2,
"Avengers" => 2,
"Man of Steel" => 1,
"How to train your Dragon" => 2
}

puts "What would you like want to do?"
puts "--Type 'add' to add a movie."
puts "--Type 'update' to update a movie."
puts "--Type 'display' to display all movies."
puts "--Type 'remove' to remove a movie from the list."
choice = gets.chomp

case choice
when 'add'
puts "What movie do you want to add?"
title = gets.chomp
if movies[title.to_sym].nil?
puts "What's the rating? (Type number 1 to 5)"
rating = gets.chomp
movies[title.to_sym] = rating.to_i
puts "#{title} has been added to the movie list 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 upadate?"
title = gets.chomp
if movies[title.to_sym].nil?
puts "Movie not found."
else
puts "What's the new rating? (Type number 1 to 5)"
rating = gets.chomp
movies[title.to_sym] = rating.to_i
puts "#{title} has been updated with the rating of #{rating}"
end

when 'display'
puts "Movies"

when 'delete'
puts "Deleted"

else
puts "Error!"
end

I also tried to change the;
"Ironman" => 2 to ironman: 2
the code work, but when I try the others it'll give me lots of error.
Any explanation for this please. Thanks a lot :smile:


#2

I'm getting the same error, although the lesson still passes. Does this have to do with the fact that our key:value pairs are not outlined, or is the "title" part of the code come from our gets.chomp and search the hash for any related key/value?

My hash table only has one key:value pair, but I don't know why that would make a difference.

The only function that seems to be able to find the hash keys is the "display" part of the code.