Build a Pyramid Generator - Build a Pyramid Generator

Tell us what’s happening:

So i managed to get true to output my pyramid the way i like. But how about false? Its getting really annoying, I’ve been trying to solve this problem for a bit of time!

Your code so far

function pyramid(ltr, rows, bool) {
    let newStr = ''
   switch (bool) {
    case true:
        for (let i = 0; i < rows; i++) {
            newStr += `${' '.repeat(i)}${ltr.repeat(rows * 2 - 1 - i * 2)}\n`
        }
        break;
    case false:
        for (let i = 0; i < rows; i++) {
            newStr += `${' '.repeat(rows * 2 - 1 - i)}${ltr.repeat(rows * 2 - 1)}\n`
        }
        break;
   }

    return newStr
}

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36 Edg/139.0.0.0

Challenge Information:

Build a Pyramid Generator - Build a Pyramid Generator
https://www.freecodecamp.org/learn/full-stack-developer/lab-pyramid-generator/lab-pyramid-generator

Keep going. What can you change to make the pyramid look different?
The struggle is where you learn the most so just keep trying.

Honestly, I was kind of annoyed that I didn’t get proper help, but I understand; We shouldn’t be giving away the answers. In the end i managed to get the answer on my own! Used the rubber ducky method :grin:

1 Like