Back to Freecodecamp

Step 41

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

latest1.6 KB
Original Source

--description--

To manipulate the result string, you will use a different type of loop. Specifically, a for...of loop, which iterates over each item in an iterable object and temporarily assigns it to a variable.

The syntax for a for...of loop looks like:

js
for (const value of iterable) {

}

Note that you can use const because the variable only exists for a single iteration, not during the entire loop.

Create a for...of loop to iterate through your rows array, assigning each value to a row variable.

--hints--

You should use another for keyword.

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

You should declare a row variable.

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

You should use const to declare your row variable.

js
assert.match(__helpers.removeJSComments(code), /const\s+row\s+/);

Your for...of loop should declare your row variable.

js
assert.match(__helpers.removeJSComments(code), /for\s*\(\s*const\s+row\s+/);

Your row variable should be extracted from rows using the of keyword.

js
assert.match(__helpers.removeJSComments(code), /for\s*\(\s*const\s+row\s+of\s+rows\s*\)/);

Your for...of loop body should be empty.

js
assert.match(__helpers.removeJSComments(code), /for\s*\(\s*const\s+row\s+of\s+rows\s*\)\s*\{\s*\}/);

--seed--

--seed-contents--

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

for (let i = 0; i < count; i = i + 1) {
  rows.push(i);
}

let result = ""

--fcc-editable-region--

--fcc-editable-region--

console.log(result);