Tell us what’s happening:
I am having issues with the output of my program meeting the test cases. I ‘m printing the results of my function to the console and the sample from the test-cases to the console to compare the differences. They both appear the exact same. Same number of characters, number of whitespaces, and the newlines before/after. I am confused as to why this isn’t passing the test cases.
Your code so far
function pyramid(string, numRows, boolVal) {
let n;
let x;
let count = 0;
let masterPattern = "";
if (boolVal === true) {
n = 2 * numRows - 1;
x = 0;
while (count < numRows) {
masterPattern += "\n" + " ".repeat(x) + string.repeat(n) + " ".repeat(x);
n = n - 2;
x++;
count++;
}
} else {
n = 1;
x = numRows - 1;
while (count < numRows) {
masterPattern += "\n" + " ".repeat(x) + string.repeat(n) + " ".repeat(x);
n += 2;
x--;
count++;
}
}
return masterPattern;
}
// Debugging
console.log(pyramid("p", 5, true));
console.log("\nppppppppp\n ppppppp\n ppppp\n ppp\n p\n");
Test Cases:
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".
Challenge Information:
Build a Pyramid Generator - Build a Pyramid Generator