Log in from a computer to take this course

You'll need to log in from a computer to start Learn Ruby. But you can practice or keep up your coding streak with the Codecademy Go app. Download the app to get started.

apple storegoogle store
Learn

The if/else statement is powerful, but we can get bogged down in ifs and elsifs if we have a lot of conditions to check. Thankfully, Ruby provides us with a concise alternative: the case statement. The syntax looks like this:

case language when "JS" puts "Websites!" when "Python" puts "Science!" when "Ruby" puts "Web apps!" else puts "I don't know!" end

But you can fold it up like so:

case language when "JS" then puts "Websites!" when "Python" then puts "Science!" when "Ruby" then puts "Web apps!" else puts "I don't know!" end

Instructions

1.

We’ve added some code to prompt the user for input.

Add a case greeting statement (in either style!) to the file. It should do the following:

  1. When the user types “English”, the program should puts "Hello!"
  2. When the user types “French”, the program should puts "Bonjour!"
  3. When the user types “German”, the program should puts "Guten Tag!"
  4. When the user types “Finnish”, the program should puts "Haloo!"
  5. Otherwise, the program should puts “I don’t know that language!”

Once you’re done, make sure to enter some input in the terminal after you’ve hit the “Run” button to test your code.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?