star pattern in javascript
let n = 5; // you can take input from prompt or change the value
let string = "";
// External loop
for (let i = 1; i <= n; i++) {
// printing spaces
for (let j = 1; j <= n - i; j++) {
string += " ";
}
// printing star
for (let k = 0; k < 2 * i - 1; k++) {
string += "*";
}
string += "\n";
}
console.log(string);