Prompting: Redux


#1

Continuing the discussion from 4. Prompting: Redux:

Hey, help me please, where's the mistake?

movies = {"Her" => 6}
puts "What is your favourite movie?"
choice = gets.chomp
case choice
when "add"
puts "What's the title of your favourite movie?"
title = gets.chomp
puts "Wht is the rating? (Type a number 0 to 4)"
rating = gets.chomp
movies[title] = rating
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

This prompt should be asking for a command, such as add.


#3

Ok. thanks I corrected that, by still I have a message Oops, try again. It looks like you didn't add to the movies hash!

How to do that?
Should I add anything else in my code?

Please help, cause this drives me crazy :wink:


#4

This line may be causing an error owing to the white space after the hash in each instance. It should read,

puts "#{title} has been added with a rating of #{rating}."

#5

nope :confused:
my code looks like that now:

movies = {"Her" => 6}
puts "Enter your favourite movie:"
choice = gets.chomp
case choice
when "add"
puts "Enter the title of your favourite movie:"
title = gets.chomp
puts "Enter you rating, type a number 0 to 4:"
rating = gets.chomp
movies[title] = rating
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

and still there is a message:

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


#6

Please post a link to the exercise so we're on the same page. I'll run your code and see what the issue might be.


#7

Still need to change this. Check the first exercise for an example.


#8

https://www.codecademy.com/courses/ruby-beginner-en-0i8v1/0/4
Thanks a lot!


#9

I tested your code and passed.

movies = {"Her" => 6}
puts "Enter a command [add, update, display, delete]:"
choice = gets.chomp
case choice
when "add"
  puts "Enter the title to add:"
  title = gets.chomp
# ...
Enter a command [add, update, display, delete]:
 add
Enter the title to add:
 Babel
Enter you rating, type a number 0 to 4:
 4
Babel has been added with a rating of 4.
nil

#11

Thank you so much!!! I can finally go further :slightly_smiling: