Build a Pyramid Generator - Build a Pyramid Generator

Tell us what’s happening:

Unsure why my return which matches test requirement is not passing. Here is my code. This is the test question, calling pyramid("o", 4, false) should give this output:


   o
  ooo
 ooooo
ooooooo

Here is what my code returns; it also includes proper line indentation using /n as requested by the test requirement, because I am meeting it character per character I can’t see any solution and it does not seem to be spaces inserted as that did not impact me passing the other tests.

    o
   ooo
  ooooo
 ooooooo

Your code so far

function pfunction pyramid(stringchar, int, booleanvalue){

  let i = 0;

  let wordToRepeat = stringchar;
  let finalReturn = "\n";

  if(i < int && booleanvalue == true){

    let repeats = wordToRepeat.repeat(int);

    let lengths = 0;

    let x=int * 2;

    let space = " ";

    while(lengths < int){
      if(x % 2 === 0){
        x--;
      }

      let string = wordToRepeat.repeat(x)
      let spaces = space.repeat(lengths);
      console.log(spaces + string + "\n")
      finalReturn += spaces + string + "\n";
      console.log(finalReturn)
      if(x == 0){
        break
      }
      lengths++;
      x = x-2;

    }


  }else{
    let repeats = wordToRepeat.repeat(int);

    let lengths = 0;

    let x=0;
    let spac = int;

    let space = " ";

    while(lengths < int){
       if(x % 2 === 0){
        x--;
      }
     
      
      let string = wordToRepeat.repeat(2 + x);
      let spaces = space.repeat(spac);
      
      finalReturn += spaces + string + "\n";
      console.log(finalReturn)
      lengths++;
      x = x+2;
      spac--;


    }

  

    

  }
  return finalReturn;

}

console.log(pyramid("o", 4, false))yramid(stringchar, int, booleanvalue){

  let i = 0;

  let wordToRepeat = stringchar;
  let finalReturn = "\n";

  if(i < int && booleanvalue == true){

    let repeats = wordToRepeat.repeat(int);

    let lengths = 0;

    let x=int * 2;

    let space = " ";

    while(lengths < int){
      if(x % 2 === 0){
        x--;
      }

      let string = wordToRepeat.repeat(x)
      let spaces = space.repeat(lengths);
      console.log(spaces + string + "\n")
      finalReturn += spaces + string + "\n";
      console.log(finalReturn)
      if(x == 0){
        break
      }
      lengths++;
      x = x-2;

    }


  }else{
    let repeats = wordToRepeat.repeat(int);

    let lengths = 0;

    let x=0;
    let spac = int;

    let space = " ";

    while(lengths < int){
       if(x % 2 === 0){
        x--;
      }
     
      
      let string = wordToRepeat.repeat(2 + x);
      let spaces = space.repeat(spac);
      
      finalReturn += spaces + string + "\n";
      console.log(finalReturn)
      lengths++;
      x = x+2;
      spac--;


    }

  

    

  }
  return finalReturn;

}

console.log(pyramid("o", 4, false))
console.log(pyramid("x", 6, false))

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36

Challenge Information:

Build a Pyramid Generator - Build a Pyramid Generator

Hi @jakejmkerr

Why do the points not align?

Happy coding

1 Like

Thank you I would have never noticed.

1 Like