6. Error! Error!


#1

movies = {
"Interstellar" => 10,
"Harry Potter" => 8,
"The Revenant" => 9,
}

puts "Would you like to add, update, delete, or display a movie?"

choice = gets.chomp.downcase
case choice
when "add"
puts "What movie would you like to add?"
title = gets.chomp.capitalize
if movies[title.to_sym] = nil
puts "What is the rating? (Number from 0 to 10)"
rating = gets.chomp
movies[title.to_sym] = rating.to_i
puts "#{title} with a rating of #{rating} has been added to the list!"
else
puts "#{title} is already in the list!"
end

I have been trying to get this for about an hour and I still can't get it. The problem is that no matter what movie I type in for the "What movie would you like to add", whether it is in the list or not, it says the else statement.


#2

@adamg703,

http://ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/syntax.html

================================================

movies = {
"Interstellar" => 10,
"Harry Potter" => 8,
"The Revenant" => 9,
}
puts movies
#puts "Would you like to add, update, delete, or display a movie?"

#choice = gets.chomp.downcase
#choice = "add"
choice = "display"
#choice = "ddd"
case choice
when "add"
  puts "What movie would you like to add?"
  #title = gets.chomp.capitalize
  title = "Test"
  if movies[title.to_sym] == nil
     puts "What is the rating? (Number from 0 to 10)"
     #rating = gets.chomp
     rating = 1
     movies[title] = rating
     puts "#{title} with a rating of #{rating} has been added to the list!" 
  else
     puts "#{title} is already in the list!"
  end
  puts (movies)
  movies.each_pair { |name, value| puts name + " " + String(value) }
when "display"
     puts "ask title and then display title & score"
else
  puts "Can not process as =choice= is not implemented."
end

#3

ok thanks I got it.:grinning: