Learn Introductory JavaScript by Building a Pyramid Generator - Step 91

Tell us what’s happening:

where is the mistake? I have followed the instructions it seems

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));
}*/

let continueLoop = false;
let done = 0;


// User Editable Region

while (continueLoop) {
  done++;
  rows.push(padRow(done, count));
  if (done !== count) {
    continueLoop = false;
  } 
}

// User Editable Region


let result = ""

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

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

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 91

It looks like you updated the wrong condition.

I would suggest resetting the code

The directions say to update the while loop condition

this is the while loop condition

once you update that to check if if done is not equal to count , then the test will pass

1 Like

It really is much more helpful if you talk about what you have tried yourself to figure out what is wrong with your code

while (continueLoop) {
  done++;
  rows.push(padRow(done, count));
  if (done !== count) {
    continueLoop = false;
  } 
}

it doesn’t look like you changed anything

Do you need help better understanding how conditions work in while loops?
if so, then please let us know so we can help you and explain it :+1:

yess, explained to me

The while loop was first introduced here in this step

Here is also a video on a while loop

But basically, a while loop will run a block of code while the condition is true

while (condition) {
  // code block to be executed
}

once the condition becomes false, then the loop will stop running that block of code.

Here is an example of using a while loop:

let i = 0;

while (i <= 15) {
  console.log(i);  
  i += 3;      
}

the condition for the while loop in this case is checking when i is less than or equal to 15.

i <= 15

For this lesson you are working on, you are changing the wrong part

that is an if statement. not the condition for the while loop.

you need to reset the code and update the condition for the while loop

 while (continueLoop)
1 Like

Oh, I have the same error, I spent the whole day wondering what I was doing wrong! :laughing:

1 Like

Please can you open a new topic if you have a query with this step.

You need change the while condition () with !==

read carefully the problem.
I am coming from other language as rookie and I get confused and my minds going chaotic.

Read the problem again please.

Read carefully the problem

thank you, very helpful answer, I was making the same mistake!