thecodezone.
The Code Zone
Short steps, at your pace · Free lessons and practice · Member video walkthroughs
Save your next small win.

Checking your account…

YOUR SAVED CODE-ALONG

Build a triangle one row at a time: video workspace

Keep the lesson open on your other screen. Your edits stay in this workspace, separate from the practice activity. Sign in to save and reload a private account draft across devices, or share a snapshot when you need help.

Open Theater ModePop Out Code Editor (opens a separate window when supported)Go to editor Join Our Coding Skool$7/m · 7 Day Free Trial in The Code Zone on Skool (opens in a new tab)Watch the video & read the lesson (opens in a new tab)Ask a question in The Code Zone (opens in a new tab)

CODE-ALONG / THEATER MODE

Print a triangle

ORIGINAL WALKTHROUGH · 05:05

Watch with Rob.

Try the challenge first. When you need help, watch Rob work through it, pause to try a change, then check your own code below.

LEARN WITH THE CODE ZONE

Unlock this video walkthrough

Written lessons and coding practice are free. Video walkthroughs are included with a paid Code Zone membership or an active free trial.

Have a Code Zone website account? Use your learning account’s email to get a six-digit sign-in code, or use your existing website password.

Need a website account? Paid Skool members and active trial members can use the email from their membership questions to request a sign-in code. No invite link or Skool password needed.

Close this window to keep practicing. After signing in, you’ll return to this lesson.

Video walkthroughs are included with an active Code Zone membership. The written lesson and practice are free.

Video settings & progress

Start the video to enable typing controls.

YOUR TURN

Build a triangle one row at a time: video workspace

Complete printTriangle(maxLevels) with a for loop. This browser adaptation defines the requested triangle precisely: print left-aligned rows containing 1 X, then 2 X, and so on up to maxLevels X, with no spaces or blank lines. Keep levels = 10 and the supplied call for your first run. Zero levels prints nothing. A centered pyramid is an optional later variation, not this checked shape.

To pass this challenge

Checks run separate copies with supplied inputs; your editor stays unchanged.

  • Define the requested function
  • Use a for loop
  • Ten levels produce ten growing rows
  • Three levels are X, XX, XXX
  • One level prints one X
  • Zero levels prints no rows
Sample output for the starting inputs
X
XX
XXX
XXXX
XXXXX
XXXXXX
XXXXXXX
XXXXXXXX
XXXXXXXXX
XXXXXXXXXX

Random values are supplied during checks. Run code uses real randomness.

Run code displays your current output. Check challenge checks the named scenarios and requested structures in a separate sandbox. Save account draft keeps your code across devices when signed in. Word wrap is enabled.

Ready to checkRun the checks to see your results here.

Need a nudge?

The row number is its width

For row 3, print "X".repeat(3).

Keep the function reusable

The checks change levels; the function must follow its parameter.

Replace your editor code?

Your current work will be replaced. Choose Cancel to keep it.

See the attached lesson’s comicCartoon Rob demonstrates the print a triangle challenge with its actual inputs and outcomes.