6. Error! Error!


#1



6. Error! Error!


So I cannot for the life of me get this to work...
I am punching in movies that are in my hash... and its not recognizing it at all.

I even changed if movies[title].nil? to if movies[title] == nil like some other solutions found... but thats not working either... Can someone please help me? I do not want to continue unless I know what I'm doing.


movies = {
    :"Terminator 2" => 5,
    :"The Matrix" => 5,
    :"Kung Fury" => 4,
    :"The Notebook" => 1,
}

puts "Input please (add, update, display or delete)!!"
choice = gets.chomp


case choice
when "add" 
puts "Name of movie?"
title = gets.chomp
title.to_sym
if movies[title].nil?
    then 
    puts "Movie Rating (1-5)?"
    rating = gets.chomp
    movies[title.to_sym] = rating.to_i
    else
        print "Already exists in database"
    
end

when "update" then puts "Updated!"

when "display"then puts "Movies!"

when "delete"then puts "Deleted!"

else
    puts "Error!"
end

puts movies


#2

You easily could have looked at the exercise on "What you will be building" to take a cue. However,

It should be: if movies[title.to_sym].nil? as used later on here:

Also, you've got these, unnecessary I would say, then before your puts.


#4

Updated block :

case choice
when "add"
puts "Name of movie?"
title = gets.chomp
if movies[title.to_sym].nil?
puts "Movie Rating (1-5)?"
rating = gets.chomp
movies[title.to_sym] = rating.to_i
else
print "Already exists in database"

end

Worked like a charm. Thank You.


#5

You're welcome.

Way to go! Have fun coding. :slight_smile: