Build a Pyramid Generator - Build a Pyramid Generator

Tell us what’s happening:

When I run the tests I get errors for the output, but I fail to see how my output is any different than the expected output… I feel it has to do with some spacing issues but I have no idea. I assumed using another function was not forbidden, tho that might be the issue as well.

Your code so far

function printSymbol(num, symbol) {
  let output = "";
  for (let i = 0; i < num; i++) {
    output += symbol;
  }
  return output;
}

function pyramid(pattern, num, isUpside) {
  let output = "\n";
  if (isUpside) {
    for (let i = num; i > 0; i--) {
      output += (" ".repeat(num - i));
      output += printSymbol((i * 2 - 1), pattern);
      console.log(output);
      output = "";
    }
  }
  else {
    for (let i = 1; i <= num; i++) {
      output += (" ".repeat(num - i));
      output += printSymbol((i * 2 - 1), pattern);
      console.log(output);
      output = "";
    }
  }
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:139.0) Gecko/20100101 Firefox/139.0

Challenge Information:

Build a Pyramid Generator - Build a Pyramid Generator

what is your function returning? that is what is being tested

idk how else to do this so I’m just copy-pasting the test result here:

// running tests 3.

pyramid("o", 4, false)

should return

"\n   o\n  ooo\n ooooo\nooooooo\n"

. 4.

pyramid("p", 5, true)

should return

"\nppppppppp\n ppppppp\n  ppppp\n   ppp\n    p\n"

And my console outputs are

o
ooo
ooooo
ooooooo

ppppppppp
ppppppp
ppppp
ppp
p

There is a new line at the start of both. And I just realised it asks for a new line at the end as well so i added a console.log() statement at the bottom of my function call. But I still get an error with these outputs:

o
ooo
ooooo
ooooooo

ppppppppp
ppppppp
ppppp
ppp
p

I’m lost

okay copy pasting does not work…
but there are indeed a correct amount of spaces at the beginning of every row (and none at the end of rows)

it seems there is a misunderstanding here, console.log prints to the console but doesn’t determine what your function returns. You need to return the requested values from the function, I see you have used return in an helper function so you know how to use it

1 Like

Oh, I see. That was indeed the case, and I passed after some tweaking. Thanks for the help !