Build a Pyramid Generator - Build a Pyramid Generator

Tell us what’s happening:

how can i print the pyramid result in the function without console.log inside, but whit a return statement?

Your code so far

function pyramid(pattern, rows, boolean) {
let result ="";
if (boolean){
  for (let i= rows; i>=1 ; i--){
    let space = " ".repeat(rows-i);
    let letter = pattern.repeat(i*2-1);
     result = space+letter;
  }
} 
if (!boolean) {
  for (let i= 0; i<rows ; i++){
    let space = " ".repeat(rows-i);
    let letter = pattern.repeat(i*2+1);
     result = console.log(space+letter);
  }
}
return result
}

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/143.0.0.0 Safari/537.36

Challenge Information:

Build a Pyramid Generator - Build a Pyramid Generator

Please log the value of result after this line. Is this what you were expecting? Compare this to the code you wrote for a true boolean. See the difference?

Also, did you mean to concatenate to result with each iteration of the loop? Consider how you would do that.

function pyramid(pattern, rows, boolean) {
let result="";
let space="";
let letter="";

if (boolean){
  for (let i= rows; i>=1 ; i--){
   space = " ".repeat(rows-i);
   letter = pattern.repeat(i*2-1);
    result += `${space}${letter}\n` 
    
  }
} 
if (!boolean) { 
  for (let i= 0; i<rows ; i++){
  space = " ".repeat(rows-i);
  letter = pattern.repeat(i*2+1);
  result += `${space}${letter}\n`;
  }
}
return result;
}

console.log((pyramid("o", 4, false)));

im close of the answer but i missed something

  console.log("Actual:   ", JSON.stringify(pyramid("o", 4, false)));
  console.log("Expected: ", JSON.stringify("\n   o\n  ooo\n ooooo\nooooooo\n"));
  console.log("Actual:   ", JSON.stringify(pyramid("p", 5, true)));
  console.log("Expected: ", JSON.stringify("\nppppppppp\n ppppppp\n  ppppp\n   ppp\n    p\n"));

Now add this to the bottom of your code so you can compare actual to expected.

i do that but i can’t find why the tests are false

What is the console showing for that code?

Actual:    "    o\n   ooo\n  ooooo\n ooooooo\n"
Expected:  "\n   o\n  ooo\n ooooo\nooooooo\n"
Actual:    "ppppppppp\n ppppppp\n  ppppp\n   ppp\n    p\n"
Expected:  "\nppppppppp\n ppppppp\n  ppppp\n   ppp\n    p\n"

So the tests are failing because your Actual result is different than the result Expected by the test.

You can see the difference in the lines, right?

Sorry if this was obvious. Please let us know if you have further questions?