A night at the movies


#1


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

My code for this isn't picking up the else statement and I don't know why. If I try to delete a film that isn't present it says it has been deleted rather than printing "error". Is there something wrong with the if movies[title.to_sym].nil? bit? I don't really get the .nil? part so any explanation would be appreciated. I know it gives false if the object is not nil itself but can't understand why it isn't working. Thank you


when "delete"
puts "which one?"
title = gets.chomp
if movies[title.to_sym].nil?
    movies.delete(title)
    puts "#{title} has been deleted"
else
    puts "error"
end


#2

This means not found

if movies[title.to_sym].nil?
    puts "Not found"
else
    movies.delete(title)
    puts "#{title} has been deleted"
end

#3

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