6/10, Can't figure out what's wrong!


#1

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/en/courses/learn-ruby/lessons/a-night-at-the-movies/exercises/error-error
Hi, I’m havong trouble figuring out what’s wrong with my code.
This is my code,

movies = {
  Starwars: 4,
  Startrek: 3.5,
  Star_Kingdom: 2.8
  }

puts "Please type what you'd like to do today:"
choice = gets.chomp.downcase
case choice
when "add"
  puts "Which movie would you like to add?"
  title = gets.chomp
  if movies[title.to_sym]nil?
    puts "What rating would you like to give to #{title}?"
    rating = gets.chomp
    title = title.to_sym
    rating= rating.to_i
    movies[title]=rating
    puts "The movie #{title} was added with a rating of #{rating}!
Thank You!"
  else
    puts "The movie #{title} already is in our database!"
  end

  
  when "update"
    puts "Updated!"
  when "display"
    puts "Movies!"
  when "delete"
    puts "Deleted!"
  else
    puts "Error!"
end

<In what way does your code behave incorrectly? Include ALL error messages.>

I’m getting this error message:

(ruby):12: syntax error, unexpected tFID, expecting keyword_then or ';' or '\n'
(ruby):25: syntax error, unexpected keyword_when, expecting end-of-input
  when "update"
      ^

Thank You!




#2

Missing dot before nil method.

These lines can be combined…

rating = gets.chomp
movies[title.to_sym] = rating.to_i

although your code works fine. It’s just nicer to reduce verbosity when it improves readability.


#3

Thanks a lot! I kept on typing it in and the color didn’t change, and I just didn’t realize what was wrong with that. Thank you!
I thought so about the combination, but I wanted to be safe…


#4

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