Learn Introductory JavaScript by Building a Pyramid Generator - Step 99

Tell us what’s happening:

i have tried a lot cant understand what mistake i am doing

Your code so far

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

function padRow(rowNumber, rowCount) {
  return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}

// TODO: use a different type of loop
/*for (let i = 1; i <= count; i++) {
  rows.push(padRow(i, count));
}*/

/*while (rows.length < count) {
  rows.push(padRow(rows.length + 1, count));
}*/


// User Editable Region

let i= count;
for (; i !== false; i--) {
 
}


// User Editable Region


let result = ""

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

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 99

You should only create a for loop. this is the for loop structure:

for (iterator, condition, iteration) {

}

now, in the right position declare your iterator i and assign count to it, then use false for condition and iteration statements

that’s correct, but iterator, condition and iteration are divided by semicolon( ; ) not by comma ( , )

for (iterator;  condition; iteration) {

}
2 Likes

You have done two mistakes:

  • You have declared the i variable outside the for loop. Remove it from there. You have to declare it inside the parentheses of for loop, means at first parameter.
  • You have the condition i == false, but you have to set the condition as false. Replace i == false with false.
  • Replace i– with false.

Syntax of for loop:

for (iterator; condition; iteration){
    // Loop Logic
}

You have to declare the variable let i = count at place of iterator, and condition set to false and iteration also set to false.

1 Like

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