7. Update works, but isn't accepted


#1



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


I have made a bit of code to update a movie's rating, like the exercise says. I get the right output and result, but my code won't be accepted by codecademy. Here is my code:

'movies' hash:

movies = {
    cars: 5,  
    batman: 3,
    hunger_games: 5,
}

Here is the code (from the case statement)

when "update"
    puts "Title:"
    title = gets.chomp
    if movies[title.to_sym].nil?
        puts "This title is not in the database. Use add to add a title"
    else
        puts "New rating:"
        movies[title.to_sym] = gets.chomp.to_i
        puts "Movie was updated. New rating: #{movies[title.to_sym]}"
    end

The output:

Input:
 update
Title:
 batman
New rating:
 1
Movie was updated. New rating: 1
nil

But codecademy is simply not letting me pass, can anyone enlighten me on the problem?
Error message:

Oops, try again. It looks like batman wasn't updated with a new rating of .

Thank you very much for your help!


#2

Assign gets.chomp to a variable, rating and convert to integer when assigning it to movies.


#3

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