4/10 Stuck! (The program won't compute. I need to know what am I doing wrong here?)


#1

I am just about to start crying, seeing that "It looks like you didn't add to the movies hash!" almost the 40th time. Please help.

movies = {
"Under the Tuscan Sun"=> "4",
"Miss Potter"=> "3",
"Bridget Jones's Diary" =>"2",
"Pride and Prejudice" => "1",
"Love Actually" => "3"
}

puts "What would you like to do?"

choice = gets.chomp.downcase!

case choice
when "add"
puts "Name of the movie you want to add:"
title = gets.chomp.upcase!
puts "What's the rating?"
rating = gets.chomp

movies[title] = rating
puts "#{title}, #{rating} had been added."

when "update"
puts "Updated!"
when "display"
puts "Movies!"
when "delete"
puts "Deleted!"
else
puts "Error!"
end


#2

Would you argue that you have? Have you had a look at the hash after adding to confirm?
What stops you from addressing the problem that's described to you, what do you need to know?


#3

The program won't compute. I need to know what am I doing wrong here?


#4

What do you mean by compute?
If it's crashing, then you'll need to consider the accompanying error message

What about my other two questions?


#5

Have a good day! thank you for your help.


#6

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!)


#7

Sometimes you have to roll up your sleeves to fix something, "help" isn't a magic word that fixes problems :confused:


#8

When asking for help, please ask for the expertise of other people, don't ask them to fix the problem for you.

Help others understand what information you are missing, explain why you can't solve it.

You're describing the wrong problem - you're describing what the exercise is, instead of describing what prevents you from completing it.


#9

Thank you... but I wonder, do you charge for this wisdom or is it free?


#10

There's nothing in it for me other than the conversation itself.

Whenever you're stuck on a problem you're welcome to describe what's going on and ask about how to continue.

If you walk up to somebody on the street and explain that you need help and why you can't fix it by yourself, then it's fairly likely they'll be happy to give a hand. It's the same thing here.

But if you were to tell them to write an essay for you... they'll probably be upset instead.


#11

I am 4 days old in Ruby. I do not know how to describe the problem (speak coders' language) yet. Let's not waste each others time. I really need someone to look at my code and tell me where am I making a mistake.

I have written the essay. I just do not know one sentence in the essay.

Can you help, or not?


#12

Then which is that sentence? You're showing the whole essay right now, along with the instructions. That's not a question


#13

movies[title] = rating
puts "#{title}, #{rating} had been added."


#14

And what's the problem with that sentence?

If you mean to say that won't add a rating for the title as a key, well, it does. That isn't the problem.
Maybe the title isn't what it's supposed to be, maybe the rating isn't what it's supposed to be.
Maybe you undo it at a later time

This is why you'd need to inspect the result (which was my original suggestion) to confirm whether you agree with codecademy's error message

It said there was a problem with the content of your hash, so have a look at it and see if you agree. Right?
How can you show the content of something in the program? That's what printing is for.


#15

Jesus Christ! I have had a look at it 47 times to be exact. Yes, I was counting. Now I need someone to tell me WHAT IS WRONG WITH THE DARN CODE.


#16

never mind! I am banging my head against the wall here.

Cheers!


#17

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