Prompting Redux, what am I missing?


#1


https://www.codecademy.com/courses/ruby-beginner-en-0i8v1/0/4?curriculum_id=5059f8619189a5000201fbcb#

Why???

Oops, try again. It looks like you didn't add to the movies hash!


choice = puts "what is your favorite movie?"
case choice
  when "add"
    puts "Name a movie"
    title=gets.chomp
    puts "Rate that movie"
    rating=gets.chomp
    movie[title]=rating
    puts "your movie has been added"


#2

Make sure you're successfully storing user-input in your choice variable. You can check if you did by printing it out after having taken user input.


#3

I want to store the users input in the movies hash but it is saying that it isn't added. I though movies[title]=rating would do the trick but I am missing something because I keep getting an error.

movies={
Pulp_Fiction: 4,
}
choice = puts "what is your favorite movie?"
case choice
when "add"
puts "Name a movie!"
title=gets.chomp
puts "Rate that movie!"
rating=gets.chomp
movie[title]=rating
puts "your movie has been added!"


#4

The user is supposed to be able to choose between adding, updating, displaying, and deleting.


#5

Right, but if they choose to add then I want the choice to be saved in the movies hash.


#6

You would, yes. But you're not giving them the ability to choose to add. Because you don't read input for what they want to do. Which code is responsible for checking whether they want to add/whatever? Is it having the desired effect? How does one take input?

When the program isn't working, observe what it does, confirm whether it's doing each thing it should.


#7

movies={
Pulp_Fiction: 4,
}
choice = puts "what is your favorite movie?"
case choice
when "add"
title = puts "Name a movie!"
title=gets.chomp
rating = puts "Rate that movie!"
rating = gets.chomp
movie[title]=rating
puts "your movie has been added!"
when "update"
puts "Updated!"
when "display"
puts "Movies!"
when "delete"
puts "Deleted!"
else
puts "Error!"
end


#8

I'm really lost here. Everything seemed to be working before this task, and the only thing I've altered is what the instructions prompted:

Inside your when "add" block, remove the puts "Added!" statement.
In its place, prompt the user for a movie title. Save the result in a new variable called title. (*Your code already has an example of how to do this!)
Next, prompt the user for the rating of the movie. Save that in a new variable called rating.
Add that movie/rating pair to the movies hash and puts a message indicating the pair was added. (No need for to_sym or to_i just yet!)

It is still giving me an error that I haven't added the movie and rating to the hash though. I have no clue what else I would need to change?


#9

Your program is supposed to allow choosing between add/update/display/delete

Your code does not allow for that choice.
So, the problem is in the code responsible for that behaviour.
Test it/compare with other places where you ask for input from the user


#10

Thank you for your help. I finally figured out what you were saying. I included the choice and it worked.


#11

I was also typing movie[title] instead of movies[title]


#12

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