I see that the 3rd and 4th criteria say that the code should return strings so now my code returns the final string and I made sure to the string starts with newline too but doesn’t pass still
for (let i = 0; i < rows; i++) {
pyramidStr += newLine + whiteSpace.repeat(rows - i - 1) + letter.repeat(i * 2 + 1);
}
if (!isDown) {
console.log(pyramidStr);
return pyramidStr;
} else {
const reversedPyramid = pyramidStr.trimEnd().split(newLine).reverse().join(newLine);
console.log(reversedPyramid);
return reversedPyramid;
}
};
Spaces are difficult to see in the extended version, so a trick to have your function output comparable with what the tests say is to use JSON.stringify
For example JSON.stringify(pyramid("o", 4, false)) gives "\n o\n ooo\n ooooo\nooooooo" and we can compare that with the expected value of "\n o\n ooo\n ooooo\nooooooo\n"
let’s put them one above the other, the first one is yours the second is the expected: