Keep getting error that the hash didn't get updated


#1



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

Hi everyone,
The console keeps telling me that I didn't add to the movies hash but after going back to the example at the beginning I don't see what I'm doing wrong, maybe in the structure (indentation of the various elements) of the case ? However I also tried modifying that in diverse ways and nothing solved it grrrr !!!
I checkout out other user threads about similar issues but since we all do it a little differently I don't seem to see where my version doesn't work.

Thanks for your help !
Here's my code at the moment.


movies = {
    bad_boys: 10
}

case movies
when "add"
puts "Movie title plz?"
title = gets.chomp
puts "Rating plz?"
rating = gets.chomp
movies[title]=rating
puts movies[title]
when "update" 
puts "Updated!"
when "display"
puts "Movies!"
when "delete"
puts "Deleted!"
else
puts "Error!"
end


#2

you need to convert the title to all lowercase leters using the .downcase! Ruby method,

title = gets.chomp.downcase! :slight_smile: As well as for choice.


#3

Hi !

Thanks for your reply, I tried adding ".downcase!" but it didn't change anything, also I don't have choice yet cause I'm at the beginning of building the project.


#4

The link that you gave was for lesson 4 of A night at the movies so I assumed you already had it

Please provide me with the correct link to your exercise :slight_smile:


#5

Hi bandit ! Indeed it's that chapter !


#6

If there are no upper case letters in the input, .downcase! returns nil, which is what is happening above. Use .downcase instead so the inputs don't matter.


#7

Ah good to know thanks !
However the hash is still not getting updated this is really scratching my head haha !


#8

rating is a number, so has no .downcase method. Not sure it is getting set.


#9

Changed it, still stuck :frowning:
Could it be the "code layout" of the case block (don't remember if you can call this a block) ?


#10

There should be a command input to start with.

puts "Enter a command: "
command = gets.chomp
case command

Then at that prompt, enter 'add'.


#11

I'm in the Redux part of the course, check my screenshot just above. I think we are unfortunately not on the same wave length regarding this problem, I have to do what you kindly suggested but in the 1st when "add" part of the case.


#12

Why did you write, case movies?

Suggest go back one lesson and review the setup for case.


#13

Maaaan ! I really need to go to bed lol ! Thanks a lot !
Indeed case movies was totally messed up, helped me also find other stuff that wasn't right.
However, in the screen below is my new code now thanks to your help, but for example by going forward from the past exercice with the choice variable, I kept pressing enter hoping to get the "add" option, noob mistake !
Indeed when I wrote add instead of a movie title to display, then I could start with the case's inputs and finish.

A little suggestion to make it more clear for future students would be to add an extra step in the assignment to change the puts that gets the choice variable so that students change it to something like "what option do you want to select?", with then add etc in a string.


#14

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