6. Error! Error!


#1



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


(ruby):1: syntax error, unexpected tCONSTANT, expecting tASSOC
17 Miracles : 10,

I just want to use the syntax, key followed by ":"


movies = {
    17 Miracles : 10,
    Superman : 10
    
}

puts "What would you like to do?"
puts "Please type one of the following according to your choice"
puts "add - Add a movie"
puts "update - Update a movie in the database"
puts "display - Display a movie of your choice"
puts "delete - Delete a movie in the database"

choice = gets.chomp

case choice
when "add" 
  puts "Enter the movie title to be added:"
  title = gets.chomp
  if movies[title.to_sym].nil?
  puts "What is the movie rating?"
  rating = gets.chomp
    movies[title.to_sym] = rating.to_i
  puts "Thank you! The pair has been added!"
  else puts "The movie already exists!"
  end
when "update"
    puts "Updated!"
when "display"
    puts "Movies"
when "delete"
    puts "Deleted!"
else 
    puts "Error!"
end


#2

Perhaps a closer look at what the syntax is?
http://ruby-doc.org/core-2.1.1/Hash.html

Also note that space isn't allowed in names, 17 Miracles is not a valid name.


#3

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