Tell us what’s happening:
I am failing test cases 3 and 4 but I am not sure why.
My output string matches the expected return string. I’m not sure what is the problem. Am I overlooking something?
Your code so far
function pyramid(str, num, bool){
let patt = [];
// turn array into string
let result = "";
let count = 1;
for(let i = 0; i < num; i++){
// push char pattern to array
patt.push(" ".repeat(num - (i + 1)) + str.repeat(count));
// increase the number of char for next row
count += 2;
//console.log(patt);
}
// invert the pyramid
if (bool){
patt = patt.reverse();
}
// turn array into string
for(let row of patt){
result = result + "\n" + row;
}
// return the results
result = result + "\n";
let final = JSON.stringify(result);
console.log(final);
return final;
};
pyramid("o", 4, false);
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/145.0.0.0 Safari/537.36
Challenge Information:
Build a Pyramid Generator - Build a Pyramid Generator