6. Error! Error!


movies = {
'Fast and the Furious 5'=> 10
puts "do you want to add?"
choice = gets.chomp!
case choice
    when "add"
      puts "Add a movie"
      title = gets.chomp
      puts "Give a rating"
      if movies[title.to_sym].nil?
      rating = gets.chomp
      movies[title.to_sym] = rating.to_i
      puts "The Movie was added!"
    puts "Movie already added"

The code is sufficient enough to pass the lesson, but when I try and pass in a val that's already in the movies hash it doesn't resort to the else statement; which should display "The Movie was added".

Any suggestions?


You need to move your if statement above the 'puts "Give a rating"' so that if the title does exist, then the code will skip the 'give a rating' and go straight to the else statement.


The above isn't seen as a symbol so does not match the if condition. I played around and could only get one way to work:

:'Fast and the Furious 5' => 10

The position of your 'Give a rating' should be inside the if block, but that's not the issue.


thanks for the help @arrayrunner74711 and @mtf