3 The Case Statement error


#1



HEEEEEEEEEEEEELP.

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


(ruby):8: syntax error, unexpected tIDENTIFIER, expecting keyword_then or ',' or ';' or '\n'
when 'add' puts "Added!"
^
(ruby):9: syntax error, unexpected keyword_when, expecting $end
when 'update' puts "Updated!"
^


movies = {
    Stalker: 10
    }

puts "Prompt"
choice gets.chomp

case choice
when 'add' puts "Added!"
when 'update' puts "Updated!"
when 'display' puts "Movies!"
when 'delete' puts "Deleted!"
else puts "Error!"
end


#2

HI this part

case choice
when 'add' puts "Added!"
when 'update' puts "Updated!"
when 'display' puts "Movies!"
when 'delete' puts "Deleted!"
else puts "Error!"
end

put it like that

case choice
when 'add' 
    puts "Added!"
when 'update' 
    puts "Updated!"
when 'display' 
    puts "Movies!"
when 'delete' 
    puts "Deleted!"
else 
    puts "Error!"
end

then this line

choice gets.chomp

it's mising the = after choice


#3

What the??
Why does the code care about the indentations? Thanks for the tip, it worked. But even with the = it doesnt let me past without the indentations.
Also, does the distinction between ' and " matter?


#4

it doesn't care about it but if you do something like that

when 'add' puts "Added!"

it see it like a Ternary operator (which is to put a statetment on one line) in other word this tenary operator is wrong
so you can put it like that

case choice
when 'add' 
puts "Added!"
when 'update' 
puts "Updated!"
when 'display' 
puts "Movies!"
when 'delete' 
puts "Deleted!"
else 
puts "Error!"
end

without indent it will also work.

AND

About " and ' there are no diff between them just you can't use them like that

puts "Error'

or

puts 'Error"

#5

If you want to have the statements on the same line as the when keyword, you have to use then.

case choice
when 'add' then puts 'Added!'
...
end