Here is the code to display pyramid but its not exactly producing required output.
repeat() to determine the number of spacer characters for each line. You do that by passing the number of lines - 1 as an argument.Here's my solution
function drawPyramid(lines, fillChar, spacerChar) {
let fillChars = '';
let spacer = spacerChar || ' '; // Default spacer is ' '
let spacerCount = lines;
for (let i = 1; i <= lines; i++) {
fillChars += fillChar;
// Makes lines always have an odd number of fill characters
if (i >= 2)
fillChars = fillChar + fillChars;
console.log(spacer.repeat(spacerCount - 1) + fillChars);
spacerCount--;
}
}
drawPyramid(4, '*');