Error! Error!


Hi All,

I seem to be a bit stuck here and not sure exactly why... In the exercise Error! Error!, I have specifically added the movie already in the database, however, the code works and accepts that I can add it to the database (again), instead of 'This movie has already been added!' (which I was expecting).

Any advice would be much appreciated....

What is your favourite movie?
Which movie would you like to add?
Lock Stock
What is the rating of the movie?
Lock Stock has been added with the rating 4!

movies = {
    "Lock Stock" => 4.5
puts "What is your favourite movie?"
choice = gets.chomp

case choice 

when "add"
puts "Which movie would you like to add?"
title = gets.chomp.to_sym 

if movies[title.to_sym].nil?
    puts "What is the rating of the movie?"
rating = gets.chomp.to_i
movies[title] = rating
puts "#{title} has been added with the rating #{rating}!"

    puts "This movie has already been added!"

when "update"
puts "Updated!"
when "delete"
puts "Deleted!"
    puts "Error!"


That pinpoints the problem to your test of whether it's already known, so you would continue investigating that.


Thanks ionatan. It appears that I did not set "Lock Stock" as a symbol ( :"Lock Stock" ). Doing this, now means that the program recognises the initial input


right. same data, but different types and therefore not equal


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