5/20 When and Then: The Case Statement


#1

I don't know but this code isn't working
puts "Hello there!"
greeting = gets.chomp
case greeting
when 'English' then puts "Hello!"
when 'French' then puts "Bonjour!"
when 'German' then puts "Guten Tag!"
when 'Finish' then puts "Haloo!"
else "I don't know that language!"
end

It says Oops, try again. It looks like your program doesn't default to printing 'I don't know that language!'
I even tried to copy paste the code but no use


5. When and Then: The Case Statement
#2

Instead of "else" try "default"


#3

I didn't know default works in ruby as well,
useful info. Thanks for that lolman

BTW I found what the error was I forgot the 'puts' after the else. Lams
So instead of else "I don't know that language!"
it should be: else puts "I don't know that language!"


#4

Oh, I didn't even see that, good catch!


#5

So, other than adding "puts", the only mistake was "default" instead of else? I don't get it? Why doesn't "else" work?


#6

default is not a Ruby reserved word. To see this proved out, got to this module's first lesson and change,

else
  puts "Sorry, I didn't understand you."
end

to

default
  puts "Sorry, I didn't understand you."
end

and Submit. Then enter a command that is not in the list:

What would you like to do?
-- Type 'add' to add a movie.
-- Type 'update' to update a movie.
-- Type 'display' to display all movies.
-- Type 'delete' to delete a movie.
 go
nil

Now change it back to else.

 go
Sorry, I didn't understand you.
nil

#7

2 posts were split to a new topic: Seems like there might be a bug here


#8