JavaScript Number Triangle Pattern (Starting from 11)
Beginner
5 min read
Updated: Sep 2026
3 programs
Live preview
Definition
What Is This Pattern?
An increasing triangle from 11 grows one value per row — each cell is base + i + j (with base 9), so the first row is 11.
Remember
Rule: for i = 1..rows
for j = 1..i
print (9 + i + j) + " "
11
12 13
13 14 15
14 15 16 17
15 16 17 18 19 ← rows = 5
A natural step after Program 31’s number-star diamond — here you practice a formula-driven triangle (compare Program 33’s i + j - 1).
Approach
How to Solve It
Walk i from 1 to rows; on each row append i values using 9 + i + j.
Method
Idea
Best for
Nested loops
Outer i; inner j = 1..i; value 9 + i + j
Learning, interviews
prompt base + rows
Same loops; replace 9 with baseVal
Interactive practice
Compact rows = 3
Same formula; easier to trace by hand
Paper walkthrough
Pseudocode
Pseudocode
for i from 1 to rows:
line = ""
for j from 1 to i:
line += (9 + i + j) + " "
print line (with newline)
Cheat sheet
Goal
Pattern
Set rows
const rows = 5;
Outer loop
for (let i = 1; i <= rows; i++)
Inner loop
for (let j = 1; j <= i; j++)
Value
line += (9 + i + j) + " ";
End row
console.log(line);
Custom base
line += (baseVal + i + j) + " ";
First cell
9 + 1 + 1 = 11
Printing Numbers vs Starting a New Line
API
Effect
Use for
line += value + " "
Stays on the same row
Each number
console.log(line)
Ends the line
After the inner loop
Build the row with +=, then break once with console.log. Putting console.log inside the inner loop prints one number per line.
Try it
Live Preview
Change the row count and the triangle from 11 updates instantly.
Whole numbers from 1 to 9. Tap a chip or type a value — the preview redraws as you go.
Live resultrows = 5 · values = 15
11
12 13
13 14 15
14 15 16 17
15 16 17 18 19
Trace
Worked Walkthrough — rows = 3
Trace each outer i, the formula 9 + i + j, and the printed row.
i
Values 9+i+j
Printed row
1
9+1+1 = 11
11
2
12, 13
12 13
3
13, 14, 15
13 14 15
Each next row starts one higher and adds one more value.
Code
JavaScript Programs
Three complete programs: fixed rows = 5, custom base + rows via prompt, and compact rows = 3. Use View Output for sample results, or Try It Yourself to edit and run in the playground.
Example 1 — Fixed rows = 5
Hard-coded height — nested loops with formula 9 + i + j.
JavaScript
const rows = 5;
for (let i = 1; i <= rows; i++) {
let line = "";
for (let j = 1; j <= i; j++) {
line += (9 + i + j) + " ";
}
console.log(line);
}