7.Update


#1



OK, so I am a little stuck here. It appears that I am doing everything correctly and the data is interpreted on the console as expected, however it does not show that I have completed the task, it only shows an error message at the end...

Any help would be much appreciated..? Thanks

Error message;

Oops, try again. It looks like Lock Stock wasn't updated with a new rating of 3.

Console output;

What would you like to do?
-- Type 'add' to add a Movie.
-- Type 'update' to update a Movie.
-- Type 'display' to display a Movie.
-- Type 'delete' to delete a Movie.
update
What movie would you like to update?
Lock Stock
What is the new rating? (Type a number 0 - 4).
3
Lock Stock has been updated with the rating 3.
nil


movies = {
    :"Lock Stock" => 4.5
}
puts "What would you like to do?"
puts "-- Type 'add' to add a Movie."
puts "-- Type 'update' to update a Movie."
puts "-- Type 'display' to display a Movie."
puts "-- Type 'delete' to delete a Movie."


choice = gets.chomp.downcase
case choice 

#Add a new movie here...

when "add"
puts "Which movie would you like to add?"
title = gets.chomp.to_sym 
if movies[title.to_sym].nil?
    puts "What is the rating of the movie?"
rating = gets.chomp.to_i
movies[title] = rating
puts "#{title} has been added with the rating #{rating}!"
else 
    puts "This movie has already been added"
end

#Update a movie here...

when "update"
puts "What movie would you like to update?"
title = gets.chomp
if movies[title.to_sym].nil?
    puts "Movie not found!"
else 
    puts "What is the new rating? (Type a number 0 - 4)."
    rating = gets.chomp
    movies[title] = rating.to_i
    puts "#{title} has been updated with the rating #{rating}."
end


#2

Print the hash and see if your code did to it what it should have
It isn't being updated, you're adding another key


#3

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