Prompting: Redux!


A Night at the Movies - Prompting: Redux!

I'm receiving a notification that I haven't added to the movies hash - can someone take me what I'm doing wrong?

movies ={
Momento: 10,
Princess_Bride: 10

puts "What would you like to do?"
choice = gets.chomp
case choice
when "add"
puts "What is the title?"
title = gets.chomp
puts "And how would you rate it?"
rating = gets.chomp

movies[title] = rating

puts "Added #{title} with a rating of #{rating}"
when "update"
puts "Updated!"
when "display"
puts "Movies!"
when "delete"
puts "Deleted!"
    puts "Error!"


try converting the choice to lowercase, and see if that fixes the error,

add the .downcase! method. :slight_smile:


Not necessary. It will only raise more questions when nil comes up.

The issue (for this lesson, at least) may be that the hash contains symbols, rather than ordinary string keys.

"Memento" => 5,
"Princess Bride" => 5


What if the problem is that when he choice prompt comes up a user enters "add" instead of "ADD" so then the console wouldn't know what the user means?


That may be the case in the real world, for our purposes that is overthinking the problem. The only user at the moment is the author, who is fully aware of what inputs are expected. Most people these days don't even know the shift key exists.

However, if the lesson were to expect .downcase, it would be without the ! since there is an assignment. This will never assign nil.


Thanks for the feedback, it finally worked!

I'm not entirely sure what worked, but my response to the initial screen prompt was just "add" instead of "add a movie" and it least I think that is why it worked.


That shouldn't be why it works because your case conditions only account for "add" and not,


I'm just went back and checked what worked and what didn't.

The initial hash did not work as a symbol and had to be changed to a string for the syntax to work, as mtf mentioned above.

I then responded to the initial screen prompt with "add a movie" and I received the "it looks like you didn't add movies to the hash" notification again with an on screen "Error" notification.

So, the next time I responded to the initial on screen prompt with simply "add" and it worked. So, it does appear as though it was the hash string and on screen response had to be changed in order to work.

I tried it several times and responding with "add a movie" responded with an error notification each and every time.


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