Pattern
***** * * * * * * *****
DEMO CODE
let n = 5; // row or column count// defining an empty stringlet string = "";for(let i = 0; i < n; i++) { // external loopfor(let j = 0; j < n; j++) { // internal loopif(i === 0 || i === n - 1) {string += "*";}else {if(j === 0 || j === n - 1) {string += " * ";}else {string += ' ';}}}// newline after each rowstring += "\n";}// printing the stringconsole.log(string);
No comments:
Post a Comment