Learn Introductory JavaScript by Building a Pyramid Generator - Step 42

Tell us what’s happening:

Guys i could really use some assistance, pls help. My for… of loop seems to me identical to the example given, i just don’t understand what concatenate means and how i can apply it here. Also, my result string is empty as of now, so how can i concatenate when i haven’t initialised result variable?! Hope my question makes sense.

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) {
row = row + result;
}

// User Editable Region


console.log(result);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 42

Hi there,

Concatenation means appending a new string to an existing string.

For example:

We start with result as an empty string:

let result = "";

We concatenate letter "A" to result:

result = result + "A";

Now, result is "A".

We continue to concatenate letter "B" to result:

result = result + "B";

Now, result is "AB".

That’s called concatenation.


The variable result is already initialized for us on line 9:

let result = ""

We started with an empty string just like the example above.


Now, what is wrong with your code? Why your result string is still empty?

It’s because your concatenation expression is wrong:

What you did was concatenating the result value to the row value.

When what we need to do is:

concatenate the row value to the result value.

Hope this makes sense to you. Happy coding!

4 Likes

Thank you toan, i switched around the expression and passed it :pray:t5:

1 Like