Learn Introductory JavaScript by Building a Pyramid Generator - Step 117

Tell us what’s happening:

I have removed all comments, but I will not proceed further.

Your code so far

const character = "#";
const count = 8;
const rows = [];
let inverted = true;

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

// User Editable Region

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

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

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

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 117

Hi @sarimrao9 and welcome to our community!

You should notice that your console is reported syntax errors in your code. This is because you have removed the single-line comment markers (i.e. //) but not the comment itself.

Also, you should remove all of the commented out code too (i.e. the while and for loops which appear just above let result = ""). Again, you have remove the comment markers (/* and */) but not the code that they were commenting out.

If you hit the Reset button, you can restore the starting code for this step. Then completely remove all code which is commented out and also the above comment.