Files

1.6 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
660f530d6e33d159e1bf4947 Step 115 1 step-115

--description--

If your pyramid is not inverted, then you will want to have an else block that builds the pyramid in the normal order.

In earlier steps, you learned how to work with else statement like this:

if (condition) {
  // if condition is true, run this code
} else {
  // if condition is false, run this code
}

Add an else block to your if block.

--hints--

You should add an else block.

assert.match(__helpers.removeJSComments(code), /if\s*\(\s*inverted\s*\)\s*\{\s*rows\.unshift\(\s*padRow\(\s*i\s*,\s*count\s*\)\s*\);\s*\}\s*else\s*\{/);

Your else block should be empty.

assert.match(__helpers.removeJSComments(code), /if\s*\(\s*inverted\s*\)\s*\{\s*rows\.unshift\(\s*padRow\(\s*i\s*,\s*count\s*\)\s*\);\s*\}\s*else\s*\{\s*\}/);

--seed--

--seed-contents--

const character = "#";
const count = 8;
const rows = [];
let inverted = true;

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

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

}
--fcc-editable-region--

/*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 + "\n" + row;
}

console.log(result);