Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Operators and Control Structures Ruby Control Structures The Ruby Case Statement

it only prints the first case output even if the user name another thing it won't go to else statement

i only get the first weather the user is right or not

Can you copy your code into here, please?

Steve.

1 Answer

Brent Larson
Brent Larson
2,554 Points

Hi I was having the exact same issue. Make sure you enter the variable name 'answer' after the case statement. Using the following code the else statement was NOT reading:

  when "reverse"
    puts "This is your name backwards:"
    puts name.reverse
  when "uppercase" 
    puts "This is your name in all uppercase letters:"
    puts name.upcase
  when "both"
    puts name.upcase.reverse
  else
    puts "Ok maybe later."
end

The following code is correct and should work (worked for me just fine), notice the word 'answer' after the case statement:

case answer
  when "reverse"
    puts "This is your name backwards:"
    puts name.reverse
  when "uppercase" 
    puts "This is your name in all uppercase letters:"
    puts name.upcase
  when "both"
    puts name.upcase.reverse
  else
    puts "Ok maybe later."
end