Error! Error! Not adding my movie, or showing "movie already exists"


#1

So the code actually works. My movie is properly added with a rating. However, the code doesn't add the movie to the hash.

But if I change the code in line 10 from if movies[title.to_sym] == nil to if movies[title.to_sym] = nil? then whatever movie I add shows to already exist. Can someone point me to what I'm doing wrong?

movies = { The_Matrix: 8 }
puts "What do you wish to do?"
choice = gets.chomp

choice = case

when "add"
puts "What is the title of your movie?"
title = gets.chomp
if movies[title.to_sym] == nil
puts "What is the rating of your movie?"
rating = gets.chomp
movies[title.intern] = rating.to_i
puts "#{title} has been added with a rating of #{rating}!"
else puts "This movie already exists"

end

when "update"
puts "Updated!"
whe "display"
puts "Movies!"
when "delete"
puts "Deleted!"
else
puts "Error!"
end


#2

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