Learn Introductory JavaScript by Building a Pyramid Generator - Step 41

Tell us what’s happening:

I am struggling to answer this question i believe my rows array is incorrect.

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 value of row) {
  rows.push(result);
}

// 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/130.0.0.0 Safari/537.36

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 41

you need to iterate over the rows array. you can’t write of row because row doesn’t exist

can you simplify this, a bit confused

1 Like

See the example,

for (const value of iterable) {

}

You are being asked to iterate over the rows array, i.e. make the rows array the iterable of this loop

like this

for (const value of rows) {

}```

good, now there is an other request in the instructions you need to follow

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

not sure on how to do that

Right now you are assigning each value in rows to a variable named value. This is the new variable created to temporarily hold each value in the collection rows

Since rows is a collection of rows, then when you iterate over each one it makes sense to call the variable row

let numbers = [1,2,3]

for (const number in numbers) {
console.log(number)
}

Output:
1
2
3

so i have to update the let?

No,

for (const value of rows) {

Here you create a variable called “value” but you need it to be called “row”

assigning each value to a row variable.

That’s what this part of the sentence means.

like this

for (const value of rows) {
const rows = 
}

Nope. You are still creating the “value” variable. “rows” already exists so you don’t want to redefine it.

I think you should see some more examples and get a good understanding of how this loop works:

https://www.w3schools.com/js/js_loop_forof.asp

https://www.geeksforgeeks.org/javascript-for-of-loop/

i have updated it to this

for (const value of rows) {
console.log(row); 
}

Where is the variable “row” created?

You create a variable called “value” but you need it to be called “row” instead

Change “value” to “row”

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.