Lesson 6: error! error! help


#1

I don't know why my code isn't working, please help!

movies={lionking:4}
puts "Movie base central: what can I help you with today? (Options: add a movie please!)"
choice = gets.chomp

case choice
    when "add" 
    puts "What movie would you like to add?"
    title = gets.chomp
      if movies[title.to_sym]==nil?
        puts "What rating do you give it?"
        rating = gets.chomp
        movies[title.to_sym] = rating.to_i
        puts "Thank you, movie and rating added :)"
        else
            puts "That movie already exists!"
        end
        
    when "update" 
    puts "Updated!"
    when "display" 
    puts "Movies!"
    when "delete" 
    puts "Deleted!"
else  
puts "try again!" 
end

i also need help understanding what nil? means? i'm totally lost on it. does it mean it returns things if nil is true? thank you for help in advance!


#2

Hi @aasaleem92,

Please give exercise link and also state what error you are getting. Thanks!


#3

nil? is a method. It basically asks "is this nil?" and returns true or false. If the thing is nil, it returns true. If it is not nil, it returns false.

I think you would write it more like

if movies[title.to_sym].nil?
    blah blah blah...
else
    blah
end

I know this is kind of old, and I can't help with why the code isn't working, but I thought I this might help in case someone else was curious about nil?