Puts and adding the key and value to an existing Hash


#1

Please help!!! The puts is not working right, and I don't know how to correctly add a key and value to an existing Hash. Any help will be super usefull!!

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

(ruby):13: syntax error, unexpected '=', expecting keyword_end
movies (title) = rating
^
(ruby):15: syntax error, unexpected keyword_when, expecting $end
when "updade"
^

movies = {
    Test: 5,
}

puts = "What to do? (add, update, display, delete)"
choice = gets.chomp

case choice
when "add"
    puts "Enter the movie title: "
    title = gets.chomp
    puts = "Now enter the rating: "
    rating = gets.chomp
    movies (title) = rating
    puts "Movie and rating added."
when "updade"
    puts "Updated!"
when "display"
    puts "Displayed!"
when "delete"
    puts "Deleted!"
else
    puts "Error!"
end

#2

puts = "Now enter the rating: "

remove the = sign

and here

movies (title) = rating

use [] brackets instead ()


#3

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