Prompting: Redux!


#1



Hi, I'm totally stuck with this exercise. I can't understand what's wrong in my code...
Thanks in advance!!!

Oops, try again. It looks like you didn't add to the movies hash!


movie = {
    Gladiator: 5,
}
    puts "What's your favourite movie ?"
choice = gets.chomp
case choice
when "add"
    print "What movie do you want to add?"
    title = gets.chomp 
    print "What's rating do you give to that Movie?"
    rating = gets.chomp
    movies[title] = rating
    puts "A movie with the title #{title} was add with the rating of #{rating}"
 when "update"
    puts "Updated!"
when "display"
    puts "Movies!"
when "delete"
    puts "Deleted!"
else
    puts "Error!"
end


#2

Start by establishing what you mean by wrong and then consider why it would be behaving one way or the other and what part of the code is responsible for that. After that you can start observing what's going on there, for example by adding prints

When it's saying

Then you should confirm a bunch of things like:
are you adding to movies?
does movies exist?
is movies a hash?
what are you adding to movies?
what should be added to movies?
are all the value types what they should be?


#3

thanks, that's worked!


#4

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