A Night At The Movies: Add (help with strings and symbols)


I need a bit of help refining my code. It allows me to pass the section and I've completed all the exercises, but I've found a problem I can't figure out.
When I add a movie and it has the same name as a movie with a space in it, the program doesn't register the movie being a match.

for example if I type add then try to add some movie with a rating of 3, my hash then has {:some_movie=>5, :movie=>1, :"some movie"=>3}

I have tried everything I can possibly think of to fix it including the code below and nothing seems to be working.

movies = { some_movie: 5,
    movie: 1,
puts "Would you like to add, update, display or delete movies?"
choice = gets.chomp.downcase

case choice
when "add"
    puts "What movie would you like to add?"
    title = gets.chomp.downcase.to_sym
    if movies[title].nil?
        puts "What is the rating for this movie?"
        rating = gets.chomp
        movies[title.to_sym] = rating.to_i
        puts "#{title} was added with a rating of #{rating}"
        puts "That movie already exists."


The error should be there.

It should be:

if movies[title.to_sym].nil?


Thank you for your reply. I've tried that as well and it still doesn't return an error. It just lets me add a second copy of the movie.



Please why the downcase.to_sym?

The input is going to be numeric there right?

title = gets.chomp should suffice.