Build a Pyramid Generator - Build a Pyramid Generator

Tell us what’s happening:

Any comments on this one? it is returning what is asked but not sure what is wrong with it

Your code so far

function pyramid (str, number, inverted) {
  
  if(inverted === false) {
for(let i = 1; i <= number; i++) {
  let space = " ".repeat(number - i);
  let character = str.repeat(2 * i - 1);
  console.log(space + character)
 }
 } else {
  for (let i = number; i >= 1; i--) {
    let character = '';
    for (let j = 0; j < number - i; j++) {
      character += ' ';
    }
    for (let k = 0; k < 2 * i - 1; k++) {
      character += str;
    }
    console.log(character);
  }
  
 }
}
 
pyramid("o", 4, false)

pyramid("p", 5, true)
 
 

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 OPR/118.0.0.0

Challenge Information:

Build a Pyramid Generator - Build a Pyramid Generator

1 Like

What pyramid function is returning?

You’ve got to build the string and return it instead of just logging to console. Also if you want to debug your final result with console to make sure if matches the desired output exactly with the whitespaces and escape characters you can try using console.log(JSON.stringify(result))