Back to Freecodecamp

Step 43

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

latest1.5 KB
Original Source

--description--

Now all of your numbers are appearing on the same line. This will not work for creating a pyramid.

You will need to add a new line to each row. However, pressing the return key to insert a line break between quotes in JavaScript will result in a parsing error. Instead, you need to use the special <dfn>escape sequence</dfn> \n, which is interpreted as a new line when the string is logged. For example:

js
lineOne = lineOne + "\n" + lineTwo;

Use a second addition operator to append a new line after the result and row values.

--hints--

You should use the \n escape sequence. Remember that it needs to be a string, so it is wrapped in quotes.

js
assert.match(__helpers.removeJSComments(code), /('|")\\n\1/);

You should concatenate your row variable to your result variable.

js
assert.match(__helpers.removeJSComments(code), /result\s*\+\s*row\s*\+\s*('|")\\n\1/);

You should concatenate the \n escape sequence to your row variable.

js
assert.match(__helpers.removeJSComments(code), /row\s*\+\s*('|")\\n\1/);

You should assign the entire concatenation back to your result variable.

js
assert.strictEqual(result, "0\n1\n2\n3\n4\n5\n6\n7\n");

--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--
for (const row of rows) {
  result = result + row;
}
--fcc-editable-region--

console.log(result);