10. Nice Work! Fun add-on to increase functionality

My code worked great, but I wanted to add the ability to add and update more than one movie. I decided to add a while loop then have the user input whether they wanted to go back to the menu after completing each action. This made it much more useful!

Let me know what you think, or if you’ve added any other cool features to your code


movies = {
    Star_Fall: 4
}

continue = true

while continue do

puts "What would you like to do?"
puts "--Type 'add' to add a movie."
puts "--Type 'update' to update an existing entry."
puts "--Type 'display' to display your current ratings."
puts "--Type 'delete' to remove a movie entry. "

choice = gets.chomp
choice.downcase!

case choice 
when "add"
    puts "Enter movie title:"
    title = gets.chomp
    title = title.to_sym
    puts "Enter movie rating:"
    rating = gets.chomp
    if movies[title] == nil 
        movies[title] = rating.to_i
    else puts "The movie you entered already exists"
    end
    puts "New movie added: #{title} with rating: #{rating}"
    
when "update"
    puts "Enter movie title:"
    title = gets.chomp
    title = title.to_sym
    if movies[title].nil? == true
        puts "That movie has not been added."
    else
        puts "Enter new movie rating:"
        rating = gets.chomp
        movies[title]= rating.to_i
        puts "#{title} has been updated with a rating of #{rating}."
    end
   
    
when "display"
    movies.each {|name, rating| puts "#{name}: #{rating}"}
    
when "delete"
    puts "Enter movie title to be erased:"
    title = gets.chomp
    title = title.to_sym
    if movies[title].nil? == true
        puts "That movie has not been added."
    else movies.delete(title)
        puts "The movie '#{title}' has been deleted."
    end
    
else
    puts "I don't understand that command."
end

puts "Type 'continue' if you would like to return to main menu. Type 'end' to end your session."
continue = gets.chomp.downcase
if continue == 'continue'
    continue = true
else continue = false
end

end




2 Likes

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