Here is the code to display pyramid but its not exactly producing required output.
This will create a proper pyramid in a console:
function createPyramid(rows)
{
for (let i = 0; i < rows; i++) {
var output = '';
for (let j =0; j < rows - i; j++) output += ' ';
for (let k = 0; k <= i; k++) output += '* ';
console.log(output);
}
}
createPyramid(5) // pass number as row of pyramid you want.