JavaScript program to print Square shape with stars


Following program shows you how to print Square shape with stars using for loop.

let n = 5; // you can take input from prompt
let string = "";
for (let i = 0; i < n; i++) {
  for (let j = 0; j < n; j++) {
    string += "*";
  }
  string += '\n';
}
console.log(string);

Output:

*****
*****
*****
*****
*****

Try it online here https://onecompiler.com/javascript/3x5qxs8ex