Tell us what’s happening:
Please I don’t understand what is happening here.. I have declared a variable already and also I have used the for.. of loop to iterate but still not responding to my code.. please help .
Thanks
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
const rows = 8;
for (const 8 of rows) {
}
// User Editable Region
console.log(result);
Your browser information:
User Agent is: Mozilla/5.0 (Linux; Android 12; CPH2387) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.98 Mobile Safari/537.36
Challenge Information:
Learn Introductory JavaScript by Building a Pyramid Generator - Step 41
Create a for...of
loop to iterate through your rows
array, assigning each value to a row
variable.
You need to replace the literal value, 8, in your for...of
loop with the variable name mentioned in the instructions above to move on.
Also, you already have a global array variable for rows
and since it was declared as const, you should be seeing an error message for that in the console. Please remove that line of code since the instructions did not ask you to declare that variable again. Also, note that for...of
loops do not require an iteration counter like for
loops do.
If you still have questions, please respond here and I will do my best to help you.
So what you mean is, I should remove the number 8 and replace it with value but it still didn’t work out
Would you post the updated code you tried, please?
I think you may be getting confused by the fCC for...of
loop example. Here’s another example of a for...of
loop taken from the MDN JavaScript Reference:
const array1 = ["a", "b", "c"];
for (const element of array1) {
console.log(element);
}
// Expected output: "a"
// Expected output: "b"
// Expected output: "c"
In this example, we are looping over an array (array1
) of items (e.g. “a”, “b”…) and within the array we’re just logging the variable we’ve declared (const element
) to store the value of the current array item for each iteration of the loop.
Thanks for the help I appreciate