6. Error! Error! - Why do i get this error


The think the problem is something to do with the hash symbols? but i cant figure out what is wrong. this is the error code i get:

(ruby):1: syntax error, unexpected tIDENTIFIER, expecting keyword_do or '{' or '('
wolf of wall street: 4,
(ruby):3: syntax error, unexpected '}'

This is my code:
movies = {
wolf of wall street: 4,
wolf: 4,
puts "what would you like to do?"
puts "type add -- to add a movie"
"type update -- to update a movie"
"type delete -- to delete a movie"
choice = gets.chomp

case choice

when "add"
puts "What movie would you like to add?"
title = gets.chomp

if movies[title.to_sym].nil?
puts "what rating would you give this movie"
rating = gets.chomp
movies[title.to_sym] = rating.to_i
puts "#{title} was added with a rating of #{rating}!"
puts "#{title} already exists"

when "update"
puts "updated!"

when "delete"
puts "deleted!"

puts "Error!"

Please explain to me why this is wrong? i already know an alternative to pass this, i just want to know why this way doesnt work? :frowning:


Never mind, just fixed it. found out that i was getting the error because there were spaces in the first key within the hash xD

haha stupid mistakes are the funniest when you fix them. anyway i hope this might help someone who may have the same problem


Good job coming up with a fix for your own problem :+1: Learning from mistakes is the best way to learn for sure!


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