My case statement isn't fully working 'Unexpected when?statement


books = {spiderman: 5}

puts "Choose what you would like to do with your books! (add) (update) (delete) "
choice = gets.chomp

loop do
case choice

when "add","ADD","Add"
puts "Add your book!"
adbook = gets.chomp
puts "Add rating please!"
rating = gets.chomp
puts rating == nil ? books[adbook.to_sym] = 0 : books[adbook.to_sym] = rating.to_i # < This is a Ternary operator i created weeee
puts "Add another? "
answer = gets.chomp
puts books
break if answer == "No"

when "update"
puts "Choose a title to update!"
title = gets.chomp
if books[title.to_sym] = nil
puts "Error that book is not in the hash"
puts "What is the new rating?"
rate = gets.chomp
books[title.to_sym] = rate
puts "You changed the rating of #{title} to #{rate} "
puts "Here his the updated list of books: #{books} "

So basically the case statement i created is set to trigger whenever one of the following choices are typed in. The one i need help with is the update string. It is telling me on the command prompt and unexpected when "update". Can someone tell me what this means?

Replace this line with your code.


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