Learn Introductory JavaScript by Building a Pyramid Generator - Step 103

Tell us what’s happening:

Where was wrong my code. I thought that is correct way. If someone can help me let me know. thanks.

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 -= i = 1) {
  rows.push(padRow(i, count));
}

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

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 103

Take away the i in the middle and the equal sign too

Hi there, that’s not quite how you use an subtraction assignment operator. The goal of the subtraction assignment operator is to set i equal to i minus whatever number is at the end of the operator.

Here’s how the subtraction assignment operator is supposed to work with x being any number.

i equal to i minus x.

Or the equivalent in a normal expression.

i = i - x.;

This statement currently means set i equal to i minus i and assign that to one. While it’s not mathematically or logically correct, you are almost there.

1 Like

Thank you so much I found solution.

1 Like

Thank you so much gave to me a tip.