movies = {
Lord_of_the_Rings: 4,
Harry_Potter: 4,
Jurassic_Park: 3
}
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 all movies.”
puts “-- Type ‘delete’ to delete a movie.”
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’s the movie rating? (Type a number 0 to 4.)”
rating = gets.chomp
movies[title.to_sym] = rating.to_i
puts “#{title} has been added with a rating of #{rating}.”
else
puts “That movie already exists! Its rating is #{movies[title.to_sym]}.”
end
when “update”
puts “Which movie would you like to update?”
title = gets.chomp
if movies[title]==nil?
puts “#{title} is not stored in the hash.”
else
puts “Please type in the new rating for #{title}:”
new_rating = gets.chomp
movies[title.to_sym] = new_rating.to_i
end
when “display”
movies.each { |movie,rating| puts " #{movie}: #{rating}. "}
when “delete”
puts “Deleted!”
else
puts “Error!”
end
I’m having a similar problem.
when ‘display’
movies.each do |movie, rating|
puts “#{movie}: #{rating}”
end
Even though it displays all the titles, I keep getting a message saying . It looks like your ‘puts’ doesn’t include back to the future: 10. (which is my first movie). Not sure where to go from here. I think my code is right?
movies = {
point_break: 4,
}
puts “What do you want to do?”
choice = gets.chomp
case choice
when “add”
puts “Please enter a movie title”
title = gets.chomp
if movies[title.to_sym] = nil
title = title.to_sym
else
puts “We already have that movie!”
end
puts “Please give a rating from 1 to 4.”
rating = gets.chomp
rating = rating.to_i
puts “#{title} has been added with a rating of #{rating}”
movies [title]= rating
when “update”
puts “What title do you want to update”
if movies[title] = nil
puts “There is no movie to update, silly!”
else
puts “What is the new rating to assign?”
rating = gets.chomp
rating = rating.to_i
end
puts “#{title} has been given a new rating of #{rating}”
when “display”
puts movies do |movie, rating|
puts “#{movie}: #{rating}”
end
when “delete”
puts “Deleted!”
else
puts “Error!”
end
My code displays point_break and its rating of 4. I am still not able to move forward. Any suggestions?
Would just confirm that the code checker is very sensitive. I put “Update” with a capital “U” and that was the reason why it wouldn’t let me pass. Once I changed the code to be while “update”, it worked.
I know it is not an answer to all the issues.