4. Prompting: Help!


#1



https://www.codecademy.com/en/courses/ruby-beginner-en-0i8v1/0/4?curriculum_id=5059f8619189a5000201fbcb


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!"
  end


#2

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

choice.downcase!

Don't store to choice


#3

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


#4

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


#5

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}."
else
puts "That movie already exists! Its rating is #{movies[title.to_sym]}."
end


#6

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