9/10 question - can't seem to figure out what's going wrong

Hey guys,

First time posting. Nice to meet you all! :slight_smile:

I’m attempting question 9/10 and seem to continuously get an error.

movies = {
  Parkland: 5,
  MI: 4,
  BG: 8,
  }
puts "What do you want to do?"
puts "---Add a movie?"
puts "---Update a rating"
puts "---View to view all movies."
puts "---delete to delete a movie"

choice = gets.chomp.downcase
case choice 
  when "add"
  puts "What is the name of the movie?"
  title = gets.chomp.to_sym
    if movies[title.to_sym] == nil
      puts "what rating do you give #{title}?"
  rating = gets.chomp.to_i
  movies[title] = rating
  puts "You have given #{title} a rating of #{rating}."
  else 
      puts "That movie already exists!"
  end
  
  when "update"
	  puts "Which movie do you wish to update?"
  title = gets.chomp.to_sym.downcase
  if movies[title.to_sym] == nil
    	puts "I don't think we have #{title} in our 						database."
  else 
    	puts "What rating do you wish to update 								#{title} with?"
    rating = gets.chomp.to_int
    movies[title] = rating
  end
  
  when "view"
  	movies.each do |movie, rating| puts "#{movie}: #{rating}" 
    end 
  
  when "delete"
  	puts "Which movie would you like to delete?"
  title = gets.chomp.to_sym.downcase
  if movies(title.to_sym) == nil 
    puts "I don't think we have that in our database."
  else 
    movies.delete(title)
    puts "Deleted!"
  end   
    else
  	puts "Error!"
end
  	

The error reads:

undefined method `movies' for #<Context:0x66fd78>

I would greatly appreciate your help!

Your error message suggests that you try to to call a method named movies
But you shouldn’t have any such method, therefore you should also not call a method by that name, and that is therefore what to change

Hey @ionatan,

thanks for the message getting back to me.

I’m a bit of a noob when it comes to this.

Would you be so kind to elaborate with regards to my code specifically?

I already spelled it out.
Don’t call movies. There’s no such method.

That means looking at your code and finding the place where you do that, you already have a lot of information to use to figure out where it is such as the name of that method and the input you used to cause the crash.

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