Build a Pyramid Generator - Build a Pyramid Generator

Tell us what’s happening:

The code result is the same as the Test Check. Please advise, where do they need to be fixed?

Your code so far

function pyramid(char, rows, boolean) {
  let result="";
  for (let i = 1 ; rows ; i++) {
    if (boolean === false) {
      if (i>rows) {
        result += `\n`;
        //result += `+n`;
        break;
      } else {
      result += `\n` + " ".repeat(rows-i) + char.repeat(2*i-1) 
      //result += `+n` + " ".repeat(rows-i) + char.repeat(2*i-1) 
      }
    } else if (boolean === true) {
      if (rows - i === -1) {
        result += `\n`;
        //result += `+n`;
        break;
      } else {
      let rowss = rows + 1;
      result += `\n` + " ".repeat(i-1) + char.repeat((rowss-i)*2-1); 
      //result += `+n` + " ".repeat(i-1) + char.repeat((rowss-i)*2-1); 
      }
    } 
  }
  //console.log(result);
  //console.log(typeof result);
  return console.log(result);
} 

pyramid("o", 4 , false);
pyramid("p", 5 , true);

/*
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".
*/
console.log("-n   o-n  ooo-n ooooo-nooooooo-n");
console.log("-nppppppppp-n ppppppp-n  ppppp-n   ppp-n    p-n");

console.log("===========");
console.log("\n   o\n  ooo\n ooooo\nooooooo\n");
console.log("\nppppppppp\n ppppppp\n  ppppp\n   ppp\n    p\n");
 

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36 Edg/136.0.0.0

Challenge Information:

Build a Pyramid Generator - Build a Pyramid Generator

Hi. Your function returns the result variable to the console. The instructions say the function should return a string.

There may be other things wrong with your code but I sugget you fix that.

Yes, I have noticed it too. I changed the return not using console log and it passed, somehow before I did the same but still not passed. It’s ok now, thank you.

1 Like