Build a Pyramid Generator - Build a Pyramid Generator

Tell us what’s happening:

my code runs fine, but I don’t know how I will add a newline characters so as to pass the test

Your code so far

function pyramid(pattern, rows, boolean) {
  
if (!boolean) {
  for (let j = rows; j > 0; j--) {
    let spaces = ' '.repeat(rows - j);
    let chars = pattern.repeat(2 * j - 1);
    console.log(spaces + chars);
    }
  } else {
      for (let i = 1; i <= rows; i++) {
        let spaces = ' '.repeat(rows - i);
        let chars = pattern.repeat(2 * i - 1);
        console.log(spaces + chars);
    }
  }
}

console.log(pyramid("t", 5, true));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36

Challenge Information:

Build a Pyramid Generator - Build a Pyramid Generator

how? your function is returning undefined

1 Like

This gave me some good things to look at: javascript newline character at DuckDuckGo

Are any of those results helpful to you?

wow, but then it produced the desired output

so why does the console shows undefined?

even better, change this console.log(pyramid("t", 5, true)); to console.log("my function output is", pyramid("t", 5, true)); so you can see better

I didn’t see, but thank you

You didn’t see what?

i didn’t see the solution to my problem

okay, let me try that

You saw nothing talking about newline characters at all? There are several results talking about them though?