FAQ: The Zen of Ruby - Up the Down Staircase

This community-built FAQ covers the “Up the Down Staircase” 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 Up the Down Staircase

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!

Why does the code print out the letter L on the screen again at the end once it puts the letters from L to P? Thanks!

puts “L”.upto(“P”) { |letter| puts letter }

L
M
N
O
P
L

Could be having two puts keywords. Try,

'L'.upto('P') { |x| puts x }
1 Like

Hello all!

I don’t get why in this first case at the end you should add " "

95.upto(100) { |num| print num, " " }

Prints 95 96 97 98 99 100

and in this second one is not necessary

“L”.upto(“P”) { |letter| puts letter }

#prints

L
M
N
O
P

Many thanks!

The comma tells the draw pencil to stay on the same line. The space character is inserted and the pencil awaits the next puts. Notice how the output is all on one line. The second example positions the draw pencil on the next line after each puts.

1 Like

but when I try to use the " " with the letters, I get the error:
wrong number of arguments (given 2, expected 1)

So does the space character only work in certain circumstances?

I think it’s because you were using puts instead of print.

“LL”.upto(“PP”) { |x| print x, " " }

LL LM LN LO LP LQ LR LS LT LU LV LW LX LY LZ MA MB MC MD ME MF MG MH MI MJ MK ML MM MN MO MP MQ MR MS MT MU MV MW MX MY MZ NA NB NC ND NE NF NG NH NI NJ NK NL NM NN NO NP NQ NR NS NT NU NV NW NX NY NZ OA OB OC OD OE OF OG OH OI OJ OK OL OM ON OO OP OQ OR OS OT OU OV OW OX OY OZ PA PB PC PD PE PF PG PH PI PJ PK PL PM PN PO PP
:grin:

2 Likes

Hey guys,
I understand what the question is asking and was able to input the correct line of code:
“L”.upto(“P”) { |letter| puts letter }

However, what if I wanted the reverse order? The code:
“P”.downto(“L”) { |letter| puts letter }
does not work. Any ideas? Thanks!

If we examine the documentation for String class, we see that it has an upto method, but not a downto method. That one seems to belong only to Integer, and perhaps other numeric classes.

Class: String (Ruby 2.4.0)

1 Like