Tell us what’s happening:
I’m sure I could clean up my code a lot, but my testing shows the code returning the correct string. I’m not sure why It’s failing the 3rd and 4th tests.
Your code so far
const pyramid = (char,rows,isUp) => {
let pyramidStr = ``;
if(!isUp){
let spaces = ``;
let charLine = ``;
for(let i = 1; i <= rows;i++){
if(i === 1){
charLine = charLine + char;
for( let j = 1; j < rows ;j++ ){
spaces = spaces + ` `;
}
}
else{
charLine = charLine + char + char;
spaces = spaces.slice(0,-1)
}
let newLine = spaces + charLine + `\n`;
pyramidStr = pyramidStr + newLine
}
return pyramidStr
}
if(isUp){
let spaces = ``;
let charLine = char;
for(let i = 1; i <= rows -1; i++){
charLine = charLine + char + char;
}
for(let i = 1; i <= rows; i++){
if(i === 1){
pyramidStr = pyramidStr + charLine + `\n`;
}
else{
spaces = spaces + ` `;
charLine = charLine.slice(0,-2);
let newLine = spaces + charLine + `\n`;
pyramidStr = pyramidStr + newLine;
}
}
return pyramidStr
}
}
console.log(pyramid('o',4,false))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36
Challenge Information:
Build a Pyramid Generator - Build a Pyramid Generator