Lesson 4: Prompting Redux - my code looks perfect


#1



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


Here is my code, I'm getting an error: "Oops, try again. It looks like you didn't add [the movie I put in] to the movies hash!"


movies = {
    Mermaids: "4"
}
puts "What would you like to do?"
choice = gets.chomp

case choice
when 'add' 
    puts "What title would you like to add?"
    title = gets.chomp
    puts "What would you like to rate this movie?"
    rating = gets.chomp
    puts "#{title} has been added with a rating of #{rating}."
when 'update'
    puts "Updated!"
when 'display'
    puts "Movies!"
when 'delete'
    puts "Deleted!"
else
    puts "Error!"
end


#2

Hi you should add the title and the rating to the hash movies for example

#an empty Hash
movies = {};

#add something to the Hash movies
movies["RRRR"] = 12,

#Now the Hash movies has a movie with a reting of 12

movies {
    "RRRR" = 12,
}

but

in your case where I put "RRRR" you should put title and instead of 12 you should put rating
Hope that could help you.


#3

Wizmarco - YES, that worked, thank you!!


#4

@leeta Your code looks correct. But the only mistake I've seen is number in your hash movie. Number always written without quotes

so
Movies = {
Mermaids: 4
}


#5

Problem:

After your last line of code in the when 'add' statement, you have to add a line of code to add the movie you have typed into the hash movies. I think this is why it is saying the error "Oops, try again. It looks like you didn't add to the movies hash!"

Solution:

Add a statement to the last line of the when 'add' statement to tell the code to put the movie inside the hash and the code should work.

Hope this helps....


#6

Hi this Line

movies["#{title}"] = "#{rating}"

why do You put Them insider The "#{ }" ?
Just remove It. .


#7

Don't you call the variable like that?
E.x.
puts"How many apples do you have?"
a = gets.chomp
puts"You have #{a} apples!

I don't think that's the problem....


#8

Sorry you post your code because it's right or because you need help. ?


#9

Because it's right...


#10

You should Take a look At The rules of The forum... https://discuss.codecademy.com/faq
And that post has already been solved. .


#11

Sorry, I didn't know that...


#12

thank, that is very helpfull


#13

Hi,

I have also a problem with this lesson. This is my code:

movies = { 
    'the big lebowski' => 10
}

puts "What do you want to do?"
puts "- add"
puts "- update"
puts "- display"
puts "- delete"
choice = gets.chomp

case choice
when "add"
    puts "Which movie do you want to add?"
    title = gets.chomp
    puts "Which rating has the movie?"
    rating = gets.chomp
    movies["title"] = rating
    puts "'#{title}' has been added with a rating of '#{rating}'"
when "update"
    puts "Updated!"
when "display"
    puts "Moives!"
when "delete"
    puts "Deleted!"
else
    puts "Error!"
end

When I "Save & Submit Code" I get this:
Oops, try again. It looks like you didn't add adsfdasfafda to the movies hash!

But with the line "movies["title"] = rating" the movie should be added, right?

Can anyone please help me?

edit: I also tried to add the movie with "movies[:title] = rating" but this ends also in the same error.


#14

HI this line

movies["title"] = rating

just remove the " " around title


#15

omg!! Thank you!!!

I'm so blind/stupid...


#16

nice adivce helped me finihs that lesson. now I undertand what was wrong you need to create a empyt one and specific a title and rating.