8. Error Error


#1

I pass the exercise but I still get this error message in the monitor:

"Give me some input!
add
Which movie would you like to add?
Waking Life
can't convert nil into String"

below is my code :

movies = {}
key = "Waking Life"

movies[key.to_sym] = 5

puts "Give me some input!"

choice = gets.chomp

case choice

when "add"
puts "Which movie would you like to add?"
title = gets.chomp
if movies[title.to_sym].nil?
puts "How much would you rate it?"
rating = gets.chomp
movies[title.to_sym]=rating.to_i
puts title + " was added to the list with a rating of " + rating
else
puts title + " is already in the list with a rating of " + movies[title]
end

when "update"
puts "Updated!"

when "display"
puts "Movies!"

when "delete"
puts "Deleted!"

else
puts "Error!"
end


#2

movies = {
Incredibles: 4.0
}
puts "What would you like to do?"
puts "--Type 'add' to add a movie."
puts "--Type 'update' to update an already rated movie."
puts "--Type 'display' to display all movies."
puts "--Type 'delete' to delete a movie."
choice = gets.chomp
case choice
when "add"
puts "What movie would you like to add?"
title = gets.chomp
if movies[title.to_sym].nil?
puts "What's the rating? (Type a number 1 to 10.)"
rating = gets.chomp
movies[title.to_sym] = rating.to_i
puts "#{title} has been added with a rating of #{rating}!"
else
"That movie already exhists! Its rating is #{movies[title.to_sym]}."
end
when "update"
puts "What movie would you like to update?"
title = gets.chomp
if movies[title.to_sym].nil?
puts "That movie was not found in our database. Error! Error!"
else
puts "What's the new rating? (Type a number 1 to 10.)"
rating = gets.chomp
movies[title.to_sym] = rating.to_i
end
when "display"
movies.each do |movie, rating|
puts "#{movie}: #{rating}"
end
when "delete"
puts "Deleted!"
else
puts "Error!"
end