Build a Pyramid Generator - Build a Pyramid Generator

Tell us what’s happening:

I just cannot figure out how to make the loop into a pyramid

Your code so far

function pyramid(str, num, isTrueOrFalse) {
  function repeatRow(str, num) {
    return str.repeat(num)
  }

  let result = []

  if (isTrueOrFalse == false) {
    for (let i = 1; i <= num; i++) {
      " " + result.push(repeatRow(str, i))
    }
  } else if (isTrueOrFalse == true) {
    for (let i = num; i > 0; i--) {
      result.push(repeatRow(str, i))
    }
  }
  
  
  return result.join("\n")
}

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/138.0.0.0 Safari/537.36 OPR/122.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

Hi @subhanowaiskhan

o
oo
ooo
oooo

You need to add some spacing before each pyramid level.

Happy coding

Yes I figured that out, but thank you for your time!

1 Like