Back to Freecodecamp

Step 109

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

latest1.5 KB
Original Source

--description--

Now that you've tried these methods, you can do another inverted pyramid approach. But first you need to clean up your experimentation.

Remove your numbers array, and the method calls and log calls.

--hints--

You should not have a numbers array.

js
assert.notMatch(__helpers.removeJSComments(code), /numbers/);

You should not have an unshifted variable.

js
assert.notMatch(__helpers.removeJSComments(code), /unshifted/);

You should not have a shifted variable.

js
assert.notMatch(__helpers.removeJSComments(code), /shifted/);

You should not have your console.log statements.

js
assert.lengthOf(__helpers.removeJSComments(code).match(/console\.log/g), 1);

--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));
}*/

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

--fcc-editable-region--
const numbers = [1, 2, 3];
const shifted = numbers.shift();
console.log(shifted);
const unshifted = numbers.unshift(5);
console.log(unshifted);
console.log(numbers);
--fcc-editable-region--

let result = ""

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

console.log(result);