Learn Introductory JavaScript by Building a Pyramid Generator - Step 70

Tell us what’s happening:

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 result = “”

for (const row of rows) {
result = result + “\n” + row;
}
console.log(result);

Hello can someone please explain to me what is the use of rowCount? im stuck.
icant understand where did it gets its value and what are the value of rowCount in padRow function.

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

// User Editable Region

for (let i = 1; i <= count; i++) {
  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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 70

1 Like

:balloon:Hello @efrigillana !

Welcome to the forum!

Judging by your code, and the lack of changes to it, it seems that the assigned task is unclear. You simply need to comment out the entire for loop by placing the appropriate characters (“/“) at the before the for loop and (”/”) after.

Does this help?
Keep up the good progress!

Happy Coding! :slightly_smiling_face:

1 Like

Hello @ios-man,

Good day mate, my question is about this

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

im bothered since i don’t get this line. like what is the use of rowCount? is rowCount and count variable the same?

1 Like

Welcome to the forum @efrigillana

rowCount and count are different.

You declared the count variable on line two.
rowCount is a parameter in the padRow function.

In the for loop, the padRow function pushes numbers into the rows array.

Happy coding

2 Likes

just want to confirm if my assumptions are correct.

in this line on my for loop

function padRow(rowNumber, rowCount)

rows.push(padRow(i, count));

this line means the value of “i” pushes to the “rowCount”, and the “count” pushes to the “rowCount” is what im thinking is correct?