4. Prompting: Help!



Hi there, I'm almost certain that I still need to work with the movies hash but I can't figure out why it won't return anything other than "Error!" regardless of my input. Maybe I'm trying to execute too soon but I can't see the reason behind it.

Here's the error message:
Oops, try again. It looks like you didn't add to the movies hash!

movies = {rubber: 10, lego: 10, batman: 10}
puts "Welcome to your movie database. What would you like to do? Options: add, update, display, or delete"
choice = gets.chomp.downcase!

case choice
    when 'add' 
        puts "What movie would you like to add?"
        title = gets.chomp.downcase!
        puts "What would you rate #{title}? (From 1-10)"
        rating = gets.chomp.downcase!
        movies.push = {title => rating}
    when 'update' 
        puts "Updated!"
    when 'display' 
        puts "Movies!"
    when 'delete'
        puts "Deleted!"
    else puts "Error!"


choice = gets.chomp.downcase!

remove the ! .because it'll return Nil if no changes were made.if you type a string that is already downcase then it'll return Nil.
or do the following


Don't store to choice


OH! Thank you! I've been dumbfounded for so long; I'm still working on memorizing the order of things. Greatly appreciated!


I had the same problem, did the same thing. No help.


here's the solution:

case choice
when "add"
puts "What movie would you like to add?"
title = gets.chomp
if movies[title.to_sym].nil?
puts "What's the rating? (Type a number 0 to 4.)"
rating = gets.chomp
movies[title] = title
movies[rating] = rating
puts "#{title} has been added with a rating of #{rating}."
puts "That movie already exists! Its rating is #{movies[title.to_sym]}."


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