Tell us what’s happening:
I am still failing the tests 3 & 4 and I am at a loss on why it is wrong. Is the instructions asking for a specific method that I missed ? My output on the console is correct. I am using an “asterisk” as a “space” placeholder to visually see the spaces in the pyramid, and I remove the “asterisk” and place a " " and I delete my log statements when I run my tests. Please, if I can receive a clue on why my function is not passing, I would be grateful! Thank you!
Your code so far
function pyramid(str, num, boo) {
let char = "";
let spaceChar = "*";
// "*" is a visual symbol to see the spaces.
if (boo === false) {
for (let i = 0; i < num; ++i) {
let numSpace = num - 1;
let bigSpace = spaceChar.repeat(numSpace - i) + str.repeat(i + 1);
char += "\n" + bigSpace + str.repeat(i)+ "\n";
}
}
if (boo === true) {
for (let i = num; i > 0; i--) {
let bigSpace = spaceChar.repeat(num - i) + str.repeat(i - 1);
char += "\n" + bigSpace + str.repeat(i)+ "\n";
}
}
return char;
}
console.log("This pyramid is upwards (false):" + "\n" + pyramid("o", 4, false));
console.log("This pyramid is downwards (true):" + "\n" + pyramid("p", 5, true));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Challenge Information:
Build a Pyramid Generator - Build a Pyramid Generator