I got to the end and everything works but I seem to need to add a final comma to my hash when i create it at the beginning.
In the movies hash, when I add a comma after the Ishtar rating, everything works fine; but when I remove it, the program seems to run right through to the else in the case and prints the error.
I thought you weren’t supposed to include that last comma in the hash. The initial example doesn’t have this comma. I even copied it exactly from the example and it still didn’t work. Am I wrong?
movies = {
Memento: 3,
Primer: 4,
Ishtar: 1, # <= Only works if I have this comma
}
puts "To add a movie rating, type 'add'."
puts "To update a movie rating, type 'update'."
puts "To display all movies in the list, type 'display'."
puts "To delete a movie from the list, type 'delete'"
puts "What would you like to do?"
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 would you like to give it?"
rating = gets.chomp
movies[title.to_sym] = rating.to_i
puts "Movie has been added!"
else
puts "That movie already exists!"
end
when "update"
puts "What movie would you like to add?"
title = gets.chomp
if movies[title.to_sym].nil? == false
puts "This movie is not in the list."
else
puts "What rating would you like to give it?"
rating = gets.chomp
movies[title.to_sym] = rating.to_i
end
when "display"
movies.each do |movie, rating|
puts "#{movie}: #{rating}"
end
when "delete"
puts "Which title would you like to delete?"
title = gets.chomp
if movies[title.to_sym].nil?
puts "That movie is not in the list"
else
movies.delete(title.to_sym)
puts "Title had been deleted!"
end
else
puts "Error! Did you type in the right command?"
end