No. 27 / Advanced
Plus Sign
Outputn = 5
*
*
*
*
*********
*
*
*
* 9 rows
Controls
5
Character
Normal
How it works
A (2n − 1) × (2n − 1) grid. A cell is a star when it is in the middle row or in the middle column.
rows 2n − 1columns 2n − 1star when i == n || j == n
pattern.js
1
const n = 5;2
3
for (let i = 1; i <= 2 * n - 1; i++) {4
let row = "";5
for (let j = 1; j <= 2 * n - 1; j++) {6
if (i === n || j === n) {7
row += "*";8
} else {9
row += " ";10
}11
}12
console.log(row);13
}