Back to Freecodecamp

Step 112

curriculum/challenges/english/blocks/learn-introductory-javascript-by-building-a-pyramid-generator/660f50a21fe7645252804f2b.md

latest1.2 KB
Original Source

--description--

What if you had a way to toggle between an inverted pyramid and a standard pyramid?

Start by declaring an inverted variable, and assigning it the value true. You are not changing this variable in your code, but you will need to use let so our tests can modify it later.

--hints--

You should declare an inverted variable with let.

js
assert.match(__helpers.removeJSComments(code), /let\s+inverted/);

You should initialise inverted with the value true.

js
assert.match(__helpers.removeJSComments(code), /let\s+inverted\s*=\s*true;?/);

--seed--

--seed-contents--

js
const character = "#";
const count = 8;
const rows = [];
--fcc-editable-region--

--fcc-editable-region--

function padRow(rowNumber, rowCount) {
  return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}

// TODO: use a different type of loop
for (let i = 1; i <= count; i++) {
  rows.unshift(padRow(i, count));
}

/*while (rows.length < count) {
  rows.push(padRow(rows.length + 1, count));
}*/

/*for (let i = count; i > 0; i--) {
  rows.push(padRow(i, count));
}*/

let result = ""

for (const row of rows) {
  result = result + row + "\n";
}

console.log(result);