"A Night at the Movies" "Error! Error!" bug


#1

I am on this exercise: https://www.codecademy.com/courses/ruby-beginner-en-0i8v1/0/6

The console says this:

(ruby):11: syntax error, unexpected '=', expecting keyword_then or ';' or '\n'
    if movie[title].nil?==true 
                          ^
(ruby):16: syntax error, unexpected keyword_when, expecting $end
  when "update"
      ^

and Codecademy says this:

Oops, try again. Your syntax doesn't look quite right. Feel free to peek back at the first exercise if you need help!

This is my code:

movies={
    Big_Hero_6: 10
}
puts "Name a movie, MAN!"
choice=gets.chomp
case choice
  when "add"
    puts "What movie?:"
    title=gets.chomp.to_sym{}
    puts "What's the rating according to you?:"
    rating=gets.chomp.to_i{}
    if movie[title].nil?==true 
          movies[title] = rating
    else
       puts "This movie exists in our hash, so it will not be added."
    end
  when "update"
    puts "Updated"
  when "display"
    puts "Movies!"
  when "delete"
    puts "Deleted!"
  else
    puts "Error!"
end

What's wrong with it?


#2

if movies[title.to_sym].nil? should suffice then you could puts afterwards. This

the way it is seems to confuse the computer. Maybe you should pause one line with a ; is what it's saying.


#3

@bayoishola20
My code now looks like this:

movies={
    Big_Hero_6: 10
}
puts "What do you want to do?"
choice=gets.chomp
case choice
  when "add"
    puts "What movie?:"
    title=gets.chomp.to_sym{}
    puts "What's the rating according to you?:"
    rating=gets.chomp.to_i{}
    if movies[title].nil? then true
          movies[title] = rating
    else
       puts "This movie exists in our hash, so it will not be added."
    end
  when "update"
    puts "Updated"
  when "display"
    puts "Movies!"
  when "delete"
    puts "Deleted!"
  else
    puts "Error!"
end

And it works. I just put if movies[title].nil? then true instead of if movies[title].nil? == true.


#4

Good to hear I helped.

Have fun coding! :slight_smile: