Tell us what’s happening:
I believe my code is working, and should pass the tests, but is failing test 3 and 4. I believe this is simply due to how it is being assessed. So I guess, I have two questions.
- Should this pass?
- In a real world example, since this is being assessed differently than how I logically did it, would the team lead expect me to rebuild the function in a way to pass the testing even though the results are as intended?
2.b) If so, is there a simpler way I should have approached this?
Your code so far
function pyramid(str, num, bool) {
let results = "";
const space = " ";
function rowBuild(val, itt, num) {
const spaces = num - 1 - itt;
const blocks = (itt * 2) + 1;
results = results.concat(`\n${space.repeat(spaces)}${val.repeat(blocks)}`)
}
if (bool === false) {
for (let i = 0; i < num; i++) {
rowBuild(str, i, num);
}
} else {
for (let i = (num - 1); i >= 0; i--) {
rowBuild(str, i, num);
}
}
return results;
}
console.log(pyramid("p",4,true));
Your browser information:
User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:145.0) Gecko/20100101 Firefox/145.0
Challenge Information:
Build a Pyramid Generator - Build a Pyramid Generator