FAQ: The Zen of Ruby - In Case of Many Options

This community-built FAQ covers the “In Case of Many Options” exercise from the lesson “The Zen of Ruby”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Ruby

FAQs on the exercise In Case of Many Options

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Whilst trying to convert the example into a hash, I found a way around “JavaScript” not working with .capitalize! :

answer = {
  Ruby: "Ruby is great for web apps!",
  Python: "Python is great for science.",
  JavaScript: "JavaScript makes websites awesome.",
  HTML: "HTML is what websites are made of!",
  CSS: "CSS makes websites pretty.",
  }

puts "What's your favorite language again?"
language2 = gets.chomp
language2.downcase!

case language2
  when "ruby"
  	language2.capitalize!
  when language2.length > 4
  	language2.capitalize!
  when "javascript"
  	language2.capitalize!
  	language2.gsub!("s", "S")
	else
  	language2.upcase!
  end

puts answer["#{language2}".to_sym]

is there a more elegant way to do this?

Why do we use == for the if statements and = for the case statement?

if language == "Ruby"
  puts "Ruby is great for web apps!"
when language = "Ruby"
    puts "Ruby is great for web apps!"

puts “What’s your favorite language?”

language = gets.chomp

case language

when “Ruby”

puts “Ruby is great for web apps!”

when “Python”

puts “Python is great for science.”

when “JavaScript”

puts “JavaScript makes websites awesome.”

when “HTML”

puts “HTML is what websites are made of!”

when “CSS”

puts “CSS makes websites pretty.”

else

puts “I don’t know that language!”

end

If you use the solution button in this exercise, the resulting program hangs infinitely even though there’s no loop. Why is this?

1 Like

Why not just do?

when "JavaScript".downcase then puts "JavaScript makes websites awesome."

We don’t use = for the case statement, instead we write:

when "Ruby"
  puts "Ruby is great for web apps!"

which is is equivalent to:

if language === "ruby"
  puts "Ruby is great for web apps!"

The Triple Equals Operator === is a method used to define equality in the context of a case statement.

Source Class: Object

Hope this helps :slight_smile:

1 Like