Back to Freecodecamp

Step 99

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

latest1.5 KB
Original Source

--description--

What if you made your pyramid upside-down, or <dfn>inverted</dfn>? Time to try it out!

Start by creating a new for loop. Declare your iterator i and assign it the value of count, then use the boolean false for your condition and iteration statements.

--hints--

Your code should have a for loop.

js
assert.lengthOf(__helpers.removeJSComments(code).match(/for\s*\(/g), 2);

Your for loop should initialise i with the value of count.

js
assert.match(__helpers.removeJSComments(code), /for\s*\(\s*let\s+i\s*=\s*count/);

Your for loop should use false as the condition.

js
assert.match(__helpers.removeJSComments(code), /for\s*\(\s*let\s+i\s*=\s*count\s*;\s*false/);

Your for loop should use false as the iteration.

js
assert.match(__helpers.removeJSComments(code), /for\s*\(\s*let\s+i\s*=\s*count\s*;\s*false\s*;\s*false\s*\)/);

--seed--

--seed-contents--

js
const character = "#";
const count = 8;
const rows = [];

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.push(padRow(i, count));
}*/

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

--fcc-editable-region--

--fcc-editable-region--

let result = ""

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

console.log(result);