8. Display


#1



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


Error msg: Oops, try again. It looks like your 'puts' doesn't include lionking: 10.

My code works in the preview, however will not pass. I have managed to 'cheat' my way to the next stage by just specifically putting the movies themselves. But i'm curious as to what i've done wrong that it cant do it itself (The whole point of display).

Possibly something to do with the to_i or to_sym jiberish that i dont fully understand why/when to use?


movies = {
    lionking: 10,
    toystory: 9
}

puts "Please choose 'add' 'update' 'display' or 'delete'"

choice = gets.chomp.downcase
case choice    
    when "add"
        puts "What movie would you like to ADD?"
        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} "
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 is the new RATING?"
        rating = gets.chomp
        movies[title.to_sym] = rating.to_i
        puts "#{title} has been updated with rating of #{rating}."
end
    when 'display'
        movies.each do |movies, rating|
        puts "#{movies}:#{rating}"
end
    when 'Delete'
        puts "Deleted!"
else
    puts 'Error!'
end


#2

Should be in lower case.

Recommend use the proper names given the movies.

movies = {
    "Lion King" => 4,
    "Toy Story" => 5
}

#3

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