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!

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

How do I nest insited if and if etc.. ruby

Whats wrong with the code? im sure I nested it bad but not sure how to solve it .

puts " Do you want to reverse your name ( yes/no )?"
q2 = gets.chomp

if q2 == "yes"
   puts " Enter your name you want to reverse . "
   namRe = gets.chomp
   namRe.reverse
   puts " As you wish! Your name in lower case #{lowerNo}"
  elsif q2 == "no"
   puts " Maybe make it lower case ( lower / no )?"
      lowerNo = gets.chomp
        if lowerNo == "lower"
           lowerNo.downcase!
        elsif lowerNo == "no"
          puts " I will not annoy you anymore"
         else 
          puts " AS you want!"
         end

2 Answers

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Add another end at the end of this, maybe this will help.

J Scott Erickson
J Scott Erickson
11,883 Points

While not necessary, you'll want to indent your clauses and the bodies of control statements two spaces ( some people use tabs, although I can speak for most ruby developers when I say we prefer spaces ). It will help make your code more readable and help you when debugging to know where you drop in and out of different statements.

puts " Do you want to reverse your name ( yes/no )?"
q2 = gets.chomp

if q2 == "yes"
  puts " Enter your name you want to reverse . "
  namRe = gets.chomp
  namRe.reverse
  puts " As you wish! Your name in lower case #{lowerNo}"
elsif q2 == "no"
  puts " Maybe make it lower case ( lower / no )?"
  lowerNo = gets.chomp
  if lowerNo == "lower"
    lowerNo.downcase!
  elsif lowerNo == "no"
    puts " I will not annoy you anymore"
  else 
    puts " AS you want!"
  end
end