Skip to content

Instantly share code, notes, and snippets.

@harrisgca
Created November 26, 2013 05:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harrisgca/7653790 to your computer and use it in GitHub Desktop.
Save harrisgca/7653790 to your computer and use it in GitHub Desktop.
"Night at the movies!" exercise from codecademy. I think this exercise was really useful and helpful. I felt like a real developer for about 10 minutes :-)
movies = {traffic:4, babe:1, memento:2}
#movies = Hash[:traffic, 4, :babe, 1, :memento, 2]
puts "Welcome to your Movie Database!"
puts "---What would you like to do?"
puts "---To add a movie type 'add'"
puts "---To update a movie type 'update'"
puts "-- Type 'display' to display all movies."
puts "---To delete a movie type 'delete'"
choice = gets.chomp.downcase
case choice
when"add"
puts "Please enter the name of the movie:"
title = gets.chomp.downcase.to_sym
if movies[title].nil?
puts "Please enter the rating (1 to 5)"
rating = gets.chomp.to_i
movies[title] = rating
else
puts "That movie already exists!"
end
when "update"
puts "Please enter the name of the movie:"
title = gets.chomp.downcase.to_sym
if movies[title].nil?
puts "That movie doesn't exist!"
else
puts "Please enter the rating (1 to 5)"
rating = gets.chomp.to_i
movies[title] = rating
end
when "delete"
puts "Please enter the name of the movie:"
title = gets.chomp.downcase.to_sym
if movies[title].nil?
puts "That movie doesn't exist!"
else
movies.delete(title)
puts "Movie deleted!"
end
when "display"
movies.each do |x,y|
puts "#{x}: #{y}"
end
else
puts "Error!"
end
movies.each do |x,y|
puts #{x}: #{y}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment