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 Basics Conditionals Course Summary

Adaugo Akaluso
Adaugo Akaluso
553 Points

Downcase, upcase, reverse

Is there a solution for the challenge using these 3 methods?

1 Answer

Is there a solution for the challenge using these 3 methods?

Not the most robust solution, but this seems to work:

def case_change(answer, string)
  if answer == "lower case"
    puts string.downcase
  elsif answer == "upper case"
    puts string.upcase
  elsif answer == "reversed"
    puts string.reverse
  else
    puts "Answer not applicable. Please only enter 'lower case', 'upper case' or 'reversed'."
  end
end

puts "Please type any string: "
string = gets.chomp
puts "Would you like to see #{string} in lower case, upper case or reversed?"
answer = gets.chomp
puts case_change(answer, string)
Adaugo Akaluso
Adaugo Akaluso
553 Points

Thank you so much. That was very helpful. Definitely learned something regarding 'chomp'. Without it, we get an Argument Error. Thanks again.