Prompting Redux (4/10) Code Won't Work


#1

Hi. I've reviewed the Q&A Forums on this topic, reset my code, retyped, cleared my cache, restarted my computer, etc etc. Nothing works. I continue to get the "Oops, try again. It looks like you didn't add to the movies hash!" error.

Here is my code? Am I missing something? I've been staring at this too long. Thanks.

movies = {
"Ponyo" => 4
}

puts "What is your movie?"
choice = gets.chomp

case choice
when "add"
puts "What is your movie?"
title = gets.chomp
puts "What is the movie's rating?"
rating = gets.chomp
movies[title] = rating
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

Arrgh. Realized my mistake. It's at the very top where I didn't specify whether to "add", etc. I changed the top lines to the following and now it works.

movies = {
"Ponyo" => 4
}

puts "What would you like to do?"
choice = gets.chomp


#3
movies = {
"Ponyo" => 4
}

puts "What is your movie?"
choice = gets.chomp

case choice 
    when "add"
        puts "What is your movie?"
        title = gets.chomp
        puts "What is the movie's rating?"
        rating = gets.chomp
        movies[title] = rating
        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

It works for me. Maybe you should change the text of the choice prompt, because maybe you are telling the movie's title instead because of that confused print statement (say something like "Choice?").


#4

Thanks for posting your solution. This helped me.

Code only works when the word "add" is typed in as the first entry, so it makes sense for the first question to be "What would you like to do - (Add, Update, Delete, Display)?"


#5

Good hawk eye @nakosar . I kept looking at the code under "add" without thinking of how the prompts before it were affecting the flow.