No. 19 / Diamonds
Half Diamond (Right Pascal)
Outputn = 5
* ** *** **** ***** **** *** ** *
9 rows
Controls
5
Character
Normal
How it works
The top half runs i = 1 to n. Row i prints i stars. The bottom half runs i = 1 to n − 1. Row i prints n − i stars.
i 1 → nstars i
i 1 → n − 1stars n − i
pattern.js
1
const n = 5;2
3
for (let i = 1; i <= n; i++) {4
let row = "";5
for (let j = 1; j <= i; j++) {6
row += "*";7
}8
console.log(row);9
}10
11
for (let i = 1; i <= n - 1; i++) {12
let row = "";13
for (let j = 1; j <= n - i; j++) {14
row += "*";15
}16
console.log(row);17
}