LoopsX Studio
No. 18 / Pyramids

Inverted Hollow Pyramid

Outputn = 5
*********
 *     *
  *   *
   * *
    *
5 rows
Controls
5
Character
Normal
How it works

Row i prints i − 1 spaces, then 2(n − i) + 1 stars. Only the outline is kept: each row prints just its first and last star, and the first row is filled completely.

i 1 → nspaces i − 1stars 2(n − i) + 1
pattern.js
1const n = 5;
2
3for (let i = 1; i <= n; i++) {
4 let row = "";
5 for (let s = 1; s <= i - 1; s++) {
6 row += " ";
7 }
8 for (let j = 1; j <= 2 * (n - i) + 1; j++) {
9 if (j === 1 || j === 2 * (n - i) + 1 || i === 1) {
10 row += "*";
11 } else {
12 row += " ";
13 }
14 }
15 console.log(row);
16}