Learn Introductory JavaScript by Building a Pyramid Generator - Step 43

Tell us what’s happening:

my console is rejecting my code and its correct even according to the co-pilot
the code is result = result + “\n” + row; is this correct or its wrong?

Your code so far

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

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

let result = ""


// User Editable Region

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

// User Editable Region


console.log(result);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/133.0.0.0

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 43

it’s wrong, you need to add the new line character after row

meaning what by adding a new line?

because even after adding a new line after the new line character after row it still refusing my code

no, you need to add the new line character after row, not a line break in the code

1 Like

Hi,
You have added the new line \n between character and row. It should be after both of them. If you’ve done it, can you share your code?

1 Like

for (const row of rows){
result = result + row + “\n”;
done
but how come they gave us this example: ```
lineOne = lineOne + “\n” + lineTwo;

The example is given just to teach us how to use \n to create a new line. In the example, you have line one, then \n which moves to the new line and then your line two.

how come in the console it was showing the same result even before putting the \n after row

It looks the same, but there’s a slight difference. When you put the \n before row, it creates an empty line and then proceeds with row, resulting in:


0
1
2
3
4
5
6
7

You can see the empty line in the console. But putting \n after row, adds row, in this case 0, first and then adds a new line after it.
I hope this helps!