A Night at the Movies : Delete


#1

I can't understand what is the matter with my syntax in the Delete portion of this exercise.
https://www.codecademy.com/en/courses/ruby-beginner-en-0i8v1/0/9?curriculum_id=5059f8619189a5000201fbcb#

Code:
movies = {
"to kill the mocking bird" => 4,
"of mice and men" => 4,
"me and my mom" => 2
}
puts "What would you like to do, add, update, display or delete?"

choice = gets.chomp.downcase
case choice
when "add"
title = gets.chomp
puts "what is your rating for this movie? (Pick # 0 - 4)"
rating = gets.chomp
movies[title.to_sym] = rating.to_i
if movies[title.to_sym].nil?
puts "#{title} has been added with #{rating} rating."
else
puts "That movie is already exists and its rating is #{rating}"
end
when "update"
title = gets.chomp
if movies[title].nil?
puts "This movie does not exist in the list"
else
puts "what is the new rating, (Pick # 0 - 4)"
rating = gets.chomp
movies[title.to_sym] = rating.to_i
puts "#{title} has been successfully added to your list, with #{rating} rating."
end

when "display"
title = gets.chomp
movies.each do |movie, rating|
puts "#{movie}: #{rating}"
end
when "delete"
title = gets.chomp
if movie[title].nil?
puts "This movie does not exist in the list."
else
movie.delete[title.to_sym]
puts "#{title} is already deleted!"
end
else
puts "Error"
end

This is what console is telling me:
What would you like to do, add, update, display or delete?
delete
to kill the mocking bird
undefined local variable or method `movie' for #

I think it might be something minor that I am not seeing in the code. If someone can kindly help me figuring this out that would be great.


#2

Did you try with,

if movies[title.to_sym].nil?

Note that the hash is called movies not movie.


#3

ok thank you. i did it again. yes both instances of movies were spelled movie!! silly
thank you. it worked after those adjustments.


#4

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