Update


#1



I am at the section to develop the "update version." Tested the update option, and it seems like it works and is updated in the movies{}. However, the code returns an error message "Oops, try again. Make sure to test your program by choosing 'update'." Can you please help check what could trigger this? Thanks!


movies ={
    Suicide_squad: 3 ,
    Batman_begins: 4,
    }

puts "What would you like to do?"
puts "add - to add a movie"
puts "update - to update a movie"
puts "display - to display movies"
puts "delete - to delete movies"
#puts "else - for others"

options=gets.chomp.downcase

case options
    when "add"
        puts "Which title would you like to add?"
        title=gets.chomp
        if movies[title.intern].nil?
            puts "rating?"
            rating=gets.chomp
            title={}                            #adding a hash
            movies[title.intern]=rating.to_i    #what does this mean?
            puts "#{title}, with a #{rating} added"
        else
            puts "the movie already exists"
        end
    when "update"
        puts"Which title would you like to update?"
        title=gets.chomp
        if movies[title.intern].nil?
            puts "the movie doesn't exist"
        else 
            puts "What's the new rating?"
            rating=gets.chomp
            movies[title.intern]=rating.to_i
            puts "#{title}, with an updated rating of #{rating}"
            print movies
        end 
    when "display"
        puts "Movies!"
    when "delete"
        puts "Deleted!"
    else
        puts "Error!"
end


Attaching a screenshot here:


#2

It expects the variable choice to refer to the value 'update'


#3

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