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.