Learn Introductory JavaScript by Building a Pyramid Generator - Step 100

Tell us what’s happening:

I seem to have done everything correctly but my code does not pass. I could be wrong so can anyone help me find out where i went wrong?

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

for (let i = count; i > 0; i--) {
   rows.push(padRow(i, count));
}

// 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/132.0.0.0 Safari/537.36 OPR/117.0.0.0

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 100

This is not the correct code for Step 100, which is the step you linked to:

For this step you should have this starting code:

for (let i = count; false; false) {

}

and you should:

Set your loop’s condition to run when i is greater than 0 .

the starting code is not supposed to run. How i do work with or around that?

Does your code pass when:

i did that, still not passing

@tbuthelezitrg

Please provide the code of what you did so we can better help.

When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.


See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (')

for (let i = count; i > 0; i–) {
rows.push(padRow(i, count));
}

here it is

Set your loop’s condition to run when i is greater than 0 .

for (initialization; condition; increment/decrement) {
  // Code to be executed in each iteration
}

No you did not do that. Above is the syntax for a for loop. You changed the condition and the increcrement/decrement
What are the instructions asking you to do?
What parts did you change?

it wants me to set the loop to run when i is greater than 0

@tbuthelezitrg

for (initialization; condition; increment/decrement) {
  // Code to be executed in each iteration
}

Great, so given the above syntax is that the initialization, condition, or increment/decrement?

Have you tried hitting the Reset button to restore the starting code for this step?
Then follow the challenge instructions (which I posted above).

1 Like

yes, i did still not working.

Can you show us the latest code which you have tried please?

it hasnt changed. im still using the same code

if it aint cheating. do you mind showing me what you did

@tbuthelezitrg

Can you answer this question?

This code?

As I said, you should hit the Reset button to restore the starting code for the step:

for (let i = count; false; false) {

}

Then, simply change the first false to a condition which checks if i is greater than 0.

1 Like

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

How to Help Someone with Their Code Using the Socratic Method