Lesson 9/10: Delete - it won't let me pass :(


#1

https://www.codecademy.com/courses/learn-ruby/lessons/a-night-at-the-movies/exercises/delete?action=lesson_resume&link_content_target=interstitial_lesson

Hi everybody,

I’m stuck at Lesson 9/10, where I’m supposed to delete a movie. I can add, update, display and delete movies, thus my code seems to be working just fine. No errors whatsoever. It still doesn’t let me pass: "Make sure to test your program by choosing ‘delete’."
I did and it worked. How can I get this ■■■■ thing to pass?

Thanks in advance



choice = nil
movies = {}
while choice != "end"
print "Choose your weapon(add/update/display/delete/end):"
choice = gets.chomp

case choice
  when "add"
  	print "What's the title: "
  	title = gets.chomp.to_sym
  	if movies[title].nil?
      print "Rating?(1-5): "
			rating = gets.chomp
  		movies[title] = rating
  		puts "Added #{title} with Rating #{rating}"
  	else
      puts "Movie has already been added!"
    end
  when "update"
  	print "What's the title"
  	title = gets.chomp.to_sym
  	if movies[title].nil?
      puts "ERROR: Movie not in DB!"
    else
      print "Rating?(1-5): "
			rating = gets.chomp
      movies[title] = rating
    end
  when "display"
			movies.each do |mov,rat|
        puts "#{mov}: #{rat}"
      end
  when "delete"	
  	print "What's the title?: "
  	title = gets.chomp.to_sym
  	if movies[title].nil?
      puts "ERROR: Movie not in DB!"
     else
      movies.delete(title)
      puts "#{title} deleted!"
  	end
  when "end"
  	puts "Terminated!"	
  	break
  else
  	puts "Error!"
end
end



#2

Ok, I figured it out. A manually defined a movie hash (movies={your_movie: your_rating} and removed the loop. Now it works :slight_smile:


#3

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