7.Update


#1

Hi, I'm new here and having some trouble with the Update lesson.

Instructions: "Inside your when "update" block, remove the puts "Updated!" statement.
Prompt the user for a movie title. Store it in title.
if the movies[title] is nil, then the movie is not in the hash. Please puts a string telling the user of their error.
Otherwise (else), we need to update "

The Error message I have been receiving: "Make sure to test your program by choosing 'update"
The first time around I didn't choose update the second and third I did but still get this message.

Here's the code:

movies = {
   Amelie: 4
}
puts "what would you like to do?"
choice = gets.chomp
choice = case
when "add"
puts "what is the title?"
title = gets.chomp
if movies[title.to_sym].nil?
puts "what is the rating?"
rating = gets.chomp
movies[title.to_sym] = rating.to_i
puts "#{title} has been added with a rating of #{rating}."
  else
    puts "That movie already exists! Its rating is #{movies[title.to_sym]}."
end
when "update"
puts "What movie do you want to update?"
title=gets.chomp
if movies[title.to_sym].nil?
    puts "Movie not found!"
else
    puts "What's the new rating? (Type a number 0 to 4.)"
    rating = gets.chomp
    movies[title.to_sym] = rating.to_i
    puts "#{title}has been updated with new rating of #{rating}."
end
when "display"
puts "Movies!"
when "delete"
puts "Deleted"
else 
    puts "Error!"
end

#2

'case' is not a variable, but a keyword.

case choice

#3

Thanks for the response! I changed it and still getting the same error message.


#4

Could it be the missing space character after the string interpolation?

"#{title} has been ... "

#5

I thought so too but no. Thanks, I'm just going to look carefully over everything again.


#6

It worked. I think it was what I was typing. I obviously needed to type a movie already in the hash. (might want to step away from the computer and breathe :slight_smile: )


#7

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