Learn Introductory JavaScript by Building a Pyramid Generator - Step 40

Tell us what’s happening:

hi guys who can help me with step 40 of Java script

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 rows) {};

// User Editable Region


console.log(result);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 40

Hello there!
I hope this syntax will guide you.

for (variable of iterable)
  statement

Here is a link as well.

1 Like

hello sir,
tnx a lot but i need a little bit more clue
i saw this pattern on the link you sent me.
and wrote down some thing like that:
const rows =[‘0’,‘1’,‘2’];
for (const value of rows );{console.log(rows);}
but it was wrong
and the explanation for being wrong is " you should declare a row variable"
is nt this"const rows =[‘0’,‘1’,‘2’];" or this “let rows” declaring rows variable?!
best regard,

In the place where you have the value, you should have the variable provided in the lesson.

1 Like

you mean the variables that provided in step 40 :thinking:
you mean this variables=( i = 0; i < count; i = i + 1)??
or i should use the row variable that provided in prior lessons like this:
“Naomi”, “Quincy”, “CamperChan” ???

The first one is not a variable, those are just statements for the loop. Use the second option.

2 Likes

i go for it and wrotr some thing like this:

for (const “Naomi”,“Quincy”,“CamperChan” for rows;){}
but it is still not the solution!

this is not a valid variable name, you need to use a valid variable name to access the values in rows

1 Like

what ca be considered as a valid variable name dear ilenia?

for example the one you are asked to use

1 Like

if you mean this variable

const rows= “iterator”,“condition”,“iteration”;
for(const values of rows;){console.log(rows);}

still not the answer!!

Hi there, you seem to be quite confused about this step which is quite normal for someone new to programming. So may I suggest that you read the following page which talks about for loops with more examples. This should help you make progress I believe.

1 Like

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

1 Like

You are very close in what you originally wrote. Step 40 at the end sets out everything to include in the for … of code, as per the Example.

1 Like

What you initially had just needs to update the value variable name.

The variable is automatically assigned the current element in the array on each iteration.

const array = [1, 2, 3];

for (const element of array) {
  console.log(element); // 1, 2, 3
}

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

So row is the identifier name you should use for that variable.

1 Like

tnx
but really cant figure the answer when I write : for( const value of rows;){console.log(rows);}
it just tell me " you should declare rows variable"
but when i declare it like this : “const rows = [iterator,condition,iteration];” or this : "const rows = [Naomi,Quincy,Champer Chan]
or this const rows= [0,1,2,3,4,5,6,7],
it just told me you have already declared row variable!!!

does it say rows or does it say row? Because you are asked to use a specific name for the variable of the loop, which is not value

2 Likes

yessssssss that was the answer thank you dear ilenia xxxx

1 Like