Files

1.6 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
660f4b641290da41b2cf0dd9 Step 103 1 step-103

--description--

Just like addition, there are different operators you can use for subtraction. The subtraction assignment operator -= subtracts the given value from the current variable value, then assigns the result back to the variable.

Replace your iterator statement with the correct statement using the subtraction assignment operator.

--hints--

Your for loop should not use i = i - 1.

assert.notMatch(__helpers.removeJSComments(code), /for\s*\(\s*let\s*i\s*=\s*count\s*;\s*i\s*>\s*0\s*;\s*i\s*=\s*i\s*-\s*1\s*\)\s*\{\s*rows\.push\(\s*padRow\s*\(\s*i\s*,\s*count\s*\)\s*\);/);

Your for loop should use subtraction assignment to reduce i by 1.

assert.match(__helpers.removeJSComments(code), /for\s*\(\s*let\s*i\s*=\s*count\s*;\s*i\s*>\s*0\s*;\s*i\s*-=\s*1\s*\)\s*\{\s*rows\.push\(\s*padRow\s*\(\s*i\s*,\s*count\s*\)\s*\);/);

--seed--

--seed-contents--

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--
for (let i = count; i > 0; i = i - 1) {
  rows.push(padRow(i, count));
}
--fcc-editable-region--

let result = ""

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

console.log(result);