5.Not My Type


#1

When I type in 'add,' it says "Error!".
What's going on?
Here's my code:

movies = {
    'The Maze Runner' => 10
}    

puts "Please select 'add', 'update', 'display', or 'delete'"
answer = gets.chomp

case movies
when "add"
   puts "What movie do you want to add?"
   title = gets.chomp
   puts "What rating do you want to have?"
   rating = gets.chomp
   title.to_sym = rating.to_i
   puts "The movie, #{title}, has a rating of #{rating}."
when "update"
  puts "Updated!"
when "display"  
  puts "Movies!"
when "delete"  
  puts "Deleted!"
else
  puts "Error!"
end

#2

Okay. First I changed 'case movies' to 'case answer'.
The code worked but it says 'Oops, try again. Did you call .to_sym on title and .to_i on rating before adding them to the hash?'.
What did I do wrong?


#3

I was so stupid.
I forgot to put 'movies[title.to_sym] = rating.to_i '.
Sorry...


#5

I figure out how to fix it.....
just type add when you submit your code...... I did spend more than hour in this :confused:


#6

When I used update after it gave me the thumbs up, it said: undefined method `to_sym' for nil:NilClass
Did it just want me to use add, or does the code for movies[title.to_sym] = rating.to_i have a problem?


#7

When I used update after it gave me the thumbs up, it said: undefined method `to_sym' for nil:NilClass
Did it just want me to use add, or does the code for movies[title.to_sym] = rating.to_i have a problem?
What do you want to do? (add, update, display, delete)
What movies do you won't to watch?
add --------> This while use add ("Superman3" => 5.5 )
What is your choice
superman3
What's the rating?
5.5
The movie superman3 has a rating of 5.5.
nil
https://www.codecademy.com/en/courses/ruby-beginner-en-0i8v1/0/4?curriculum_id=5059f8619189a5000201fbcb

This from 4/10 Prompting: Redux!


#8

even if i type in add when i hit submit it says

Oops, try again. Make sure to test your program by choosing 'add'.

why is it saying that even knowing i type in add?