4/10 Prompting Redux

movies ={ LOR:3, MR:5, NT:4}

puts “What do you want to do?”

case choice
when “add”
puts “Whats the title?”
puts “Whats the rating?”
puts “Added!”
when “update”
puts “Updated!”
when “display”
puts “Movies!”
puts movies
when “delete”
puts “Deleted!”
puts “Error!”

Though it says “Added!” in the end and finishes successfully, when i try to find the added movie in movies by typing diaply, its not there.
I even checked others’ code and it seems to be exactly the same. any mistake there?

You need to add

puts movies

at the end of your code (after the last end) if you want to see the updated contents of your hash

When you add a new movie to the hash, it’s just stored in memory for as long as you’re running the current session of the program. Anything you entered in the console is forgotten when you re-save and re-run the program.

When you go through the add case, then hit Save and Submit Code to re-run the program and choose ‘display’, the program has been re-started so it doesn’t remember that you added a new movie. In the real world, if you wanted to store the data in the hash more permanently you would attach your program to a database, but you can’t do that with these exercises.

If you want to see the movie list after you add a movie, you’ll have to add a puts statement to the end of your add case like @k_o_f k_o_f said.

1 Like