LoopsX Studio
No. 02 / Squares

Hollow Square

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

Row i prints n stars. Only the outline is kept: each row prints just its first and last star, and the first and last rows are filled completely.

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