1let n = 5; // you can take input from prompt or change the value
2let string = "";
3// External loop
4for (let i = 1; i <= n; i++) {
5 // printing spaces
6 for (let j = 1; j <= n - i; j++) {
7 string += " ";
8 }
9 // printing star
10 for (let k = 0; k < 2 * i - 1; k++) {
11 string += "*";
12 }
13 string += "\n";
14}
15console.log(string);
1let n = 5;
2let string = "";
3for (let i = 1; i <= n; i++) {
4 for (let j = 0; j < i; j++) {
5 string += "*";
6 }
7 string += "\n";
8}
9console.log(string);