# Build a Pyramid Generator - Build a Pyramid Generator

**URL:** <https://forum.freecodecamp.org/t/build-a-pyramid-generator-build-a-pyramid-generator/771550>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [December 26, 2025, 9:22pm UTC](https://forum.freecodecamp.org/t/build-a-pyramid-generator-build-a-pyramid-generator/771550 "2025-12-26T21:22:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrened](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/andrened/32/379658_2.png) [@andrened](https://forum.freecodecamp.org/u/andrened)\
**Post date:** [December 26, 2025, 9:22pm UTC](https://forum.freecodecamp.org/t/build-a-pyramid-generator-build-a-pyramid-generator/771550/1 "2025-12-26T21:22:14Z")

</div>

### Tell us what’s happening:

I am not sure how to proceed, if I try for example pyramid(“o”, 4, false), I can print out:

row 1: 3 empty spaces, 1 char  
row 2: 2 empty spaces, 3 char  
row 3: 1 empty space, 5 char  
row 4: 0 empty spaces, 7 char

which seems like the test case, what am I missing?

### Your code so far

```js
const pyramid = (char, rows, bool) => {
    let result = [];
    let cRow = 1;

    //startMarker
    result.push("\n");

    if (bool === "false") {
        for (let j = cRow; j <= rows; j++) {

            //spacing
            for (let i = 1; i <= rows - cRow; i++) {
                result.push(" ");
            }

            //char
            for (let i = 1; i <= cRow * 2 - 1; i = i + 1) {
                result.push(char);
            }

            //endRow
            result.push("\n");
            cRow++;
        }
    }

    if (bool === "true") {
        for (let j = cRow; j <= rows; j++) {

            //spacing
            for (let i = cRow; i > 1; i--) {
                result.push(" ");
            }

            //char
            for (let i = 2 * rows - cRow; i >= cRow; i -= 1) {
                result.push(char);
                console.log(`i: ${i}, cRow: ${cRow}`);
            }

            //endRow
            console.log(`result: ${result}`);
            result.push("\n");
            cRow++;
        }
    }

    //return
    return result.join("");
}

let char = "o";
let rows = 4;
let dir = "false";
const result = pyramid(char, rows, dir);
console.log(result);

```

### Your browser information:

User Agent is: `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.1 Safari/605.1.15`

### Challenge Information:

Build a Pyramid Generator - Build a Pyramid Generator

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/javascript-v9/lab-pyramid-generator/lab-pyramid-generator)**
>
> Learn to Code — For Free

---

<div class="post-metadata">

**Author:** ![dhess](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/dhess/32/406235_2.png) [@dhess](https://forum.freecodecamp.org/u/dhess)\
**Post date:** [December 26, 2025, 9:50pm UTC](https://forum.freecodecamp.org/t/build-a-pyramid-generator-build-a-pyramid-generator/771550/2 "2025-12-26T21:50:31Z")

</div>

Welcome to the forum @andrened!

You can add this code to the bottom of your script file to compare what your code is producing to what is expected:

```auto
  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"));

```

---

<div class="post-metadata">

**Author:** ![faust.levity](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/faust.levity/32/406663_2.png) [@faust.levity](https://forum.freecodecamp.org/u/faust.levity)\
**Post date:** [December 26, 2025, 9:56pm UTC](https://forum.freecodecamp.org/t/build-a-pyramid-generator-build-a-pyramid-generator/771550/3 "2025-12-26T21:56:30Z")

</div>

Boolean values are not strings in JavaScript.  
You can simply write then down as `false` or `true`.

---

<div class="post-metadata">

**Author:** ![andrened](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/andrened/32/379658_2.png) [@andrened](https://forum.freecodecamp.org/u/andrened)\
**Post date:** [December 26, 2025, 10:37pm UTC](https://forum.freecodecamp.org/t/build-a-pyramid-generator-build-a-pyramid-generator/771550/4 "2025-12-26T22:37:04Z")

</div>

thanks @dhess and @faust.levity I had logged spaces as “\_“ to read them easier, and now the code works 🏆

Happy to remove the code above if needed

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [May 7, 2026, 6:45pm UTC](https://forum.freecodecamp.org/t/build-a-pyramid-generator-build-a-pyramid-generator/771550/5 "2026-05-07T18:45:19Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
