Skip to content

Instantly share code, notes, and snippets.

@ArtBears
Created May 10, 2013 05:36
Show Gist options
  • Save ArtBears/5552598 to your computer and use it in GitHub Desktop.
Save ArtBears/5552598 to your computer and use it in GitHub Desktop.
Movie ratings practice for codecademy
movies = { Pocahontus: 4,
The_Lion_King: 3,
Grinch: 2,
Jumper: 1
}
puts "What would you like to do?"
choice = gets.chomp
case choice
when "add"
puts "What movie would you like to add?"
title = gets.chomp
if movies[title.to_sym].nil?
puts "What rating do you want to give the movie(from 0 to 4)"
rating = gets.chomp
movies[title.to_sym] = rating.to_i
else
puts "That movie already exists!"
end
when "update"
puts "What title would you like to update?"
title = gets.chomp
if movies[title.to_sym].nil?
puts "That movie doesn't exist!"
else
puts "What rating do you want to change #{title} to?"
rating = gets.chomp
movies[title.to_sym] = rating.to_i
puts "#{title.to_sym}'s rating has been changed to #{rating.to_i}"
end
when "display"
movies.each do |movie, rating|
puts "#{movie}: #{rating}"
end
when "delete"
puts "What movie would you like to delete?"
title = gets.chomp
if movies[title.to_sym].nil?
puts "That movie doesn't exist!"
else
movies.delete(title)
movies.each do |movie, rating|
puts "#{movie}: #{rating}"
end
end
else puts "Error!"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment