.3 The case Statement


Hello everyone. I am totally stuck, I don't understand what's wrong with my code...
I "undressed" it to its most basic form to try to find maybe a typing mistake or anything, but the message is still the same, and I don't understand what's wrong, and what I should do...
Please help !


Error message :
(ruby):10: syntax error, unexpected tIDENTIFIER, expecting keyword_then or ',' or ';' or '\n'
when "add" puts "added!"
(ruby):11: syntax error, unexpected keyword_else, expecting $end
else puts "error"

    the_big_L: 5,
    fight_club: 5

puts "Choose a movie"

choice = gets.chomp

case choice
when "add" puts "added!"
else puts "error"


mrfdl.rb:10: syntax error, unexpected tIDENTIFIER, expecting keyword_then or ',' or ';' or '\n'
when "add" puts "added!"

Look at where it's pointing and what it's saying.
puts was unexpected, instead it expected one of:
then , ; \n
where \n is a newline character

So puts is not allowed there, but it lists what is allowed, you can then look up what effect those would have there.

You've got documentation for case here:

And here's for then, on the same page:

And those also briefly describe what effect comma and semicolon have


Thank you, I'm gonna look this up, though I don't get why I get this error since I think I respected the syntax that was given in the examples and in the "course"...
It just makes me confused that I copied/pasted solutions from the forum that work just fine and have the exact same syntax as mine (at least i'm pretty sure they do... i am ready to accept that maybe i just forgot one "," somewhere of course...)


It finally worked with

case choice
when 'add'
  puts "Added!"
else puts "error"

But I don't understand why as " " and ' ' are the same to me in that case


If you're saying that changing between ' and " makes a difference there, then no, it does not, and you really need to question how you came to that conclusion!


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