Error: "It looks like you didn't add to the movie hash"


#1

So this is my code:

`movies = {
Memento: 3,
Primer: 4,
Ishtar: 1
}

puts "What would you like 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 'delete' to delete a movie."

choice = gets.chomp.downcase!

case choice
when 'add'
puts "What moview do you want to add?"
title = gets.chomp
puts "What's the rating of the movie?"
rating = gets.chomp
movies[title.to_sym] = rating.to_i
puts movies
when 'update'
puts "Updated!"
when 'display'
puts "Movies!"
when 'delete'
puts "Deleted!"
else
puts "Error!"
end`

When I run the code, and type add it prints Error! as it to say that it didn't go through the "add" part of the block but rather it went straight to the last "else" case. Why?

The website displays the error "Oops, try again. It looks like you didn't add to the movies hash!"


#2

I'm having the same issue...

edit: figured it out. i need to use my initial input from earlier to select from the list of case/when statements.


#3

Try not downcasing the user input for choice.


#4

Can you be more specific about how you fixed this problem? I am having the same issue, but your answer is cryptic.


#5

It didn't tell you to change the puts for choice. You will answer "add" to the first question to get to the movie title being added. It wasn't obvious as my choice was "what is your favorite move" i kept putting the movie i wanted to add and got "Oops, try again. It looks like you didn't add to the movies hash!". Type add and it will progress.


#6

you need to add this line to add title and rating into your hash
movies[title]= rating

my code

movies={ spiderman: 5,
captain: 4}
puts "What would you like 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 'delete' to delete a movie."
choice = gets.chomp.downcase

> case choice
> when "add"
> puts "Add your movies here"
> title = gets.chomp
> puts "Add your rating here"
> rating = gets.chomp
> movies[title]= rating
> puts " your movie and rating #{title}: #{rating}"
> when "updated"
> puts "Updated!"
> when "display"
> puts "Movies!"
> when "delete" 
> puts "Deleted!"
> else
>     puts "Error!"
> end