7- Update


#1

Help! Ok, for the life of me I can't figure out what is wrong with my code the error is telling me the syntax doesn't
look right with the error: (ruby):23: syntax error, unexpected tFID, expecting keyword_then or ';' or '\n'
(ruby):32: syntax error, unexpected keyword_when, expecting $end
when 'display'
^

my code is:

movies = {
"divergent" => 8,
"inception" => 8
}
puts "What would you like to do with these movie listings?"
choice = gets.chomp

case choice
when 'add'
puts "Which movie title?"
title = gets.chomp.to_sym
puts "How high you rate this movie?"
rating = gets.chomp.to_i
if movies[title.to_sym].nil?
movies[title.to_sym] = rating.to_i
puts "#{title} has been added with a rating of #{rating}."
else puts "This title is already exist in the listing."
end

when 'update'
puts "Which movie would you like to update?"
title = gets.chomp
if movies[title.to_sym]nil?
puts "This movie is not on the list."
else
puts "What is the new rating of this movie?"
rating = gets.chomp
movies[title.to_sym] = rating.to_i
puts "#{title} has beed updating with a rating of #{rating}"
end

when 'display'
puts "Movies!"
when 'delete'
puts "Deleted!"
else
puts "Error!"
end


#3

Here is my code that worked without error:

movies = {
Zombieland: 4
}

puts "What shall we do?"
choice = gets.chomp

case choice
when "add"
puts "What is the title?"
title = gets.chomp
title = title.intern
puts "What is the rating?"
rating = gets.chomp
rating = rating.to_i
if movies[title].nil?
movies[title] = rating
end
when "update"
puts "What is your movie to update?"
title = gets.chomp
if movies[title.to_sym].nil?
puts "Error: Movie non-existent."
else
puts "What is your new rating?"
rating = gets.chomp
movies[title.to_sym] = rating.to_i
end
when "display"
puts "Movies!"
when "delete"
puts "Deleted!"
else
puts "Error!"
end


#4

I noticed in your code: if movies[title.to_sym]nil? should be if movies[title.to_sym].nil? Yours was missing the . after the closed bracket. Does that fix the issue? I'm new to this, but i noticed the missing . so I thought i'd let you know.