Learn Introductory JavaScript by Building a Pyramid Generator - Step 59

Tell us what’s happening:

I cannot get my code to pass and have become stumped. I am on lesson 59 of the JavaScript Build a Pyramid. The error is telling me to use padRow in my .push(). The code I am using is rows.push(padRow); I thought that is what I was doing. Can anyone help?

Your code so far

const character = "#";
const count = 8;
const rows = [];

function padRow(rowNumber, rowCount) {
  return character.repeat(rowNumber);
}



// User Editable Region

for (let i = 0; i < count; i = i + 1) {
  rows.push(padRow);
}

// 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 59

1 Like

padRow is a function, you need to call it

1 Like

I am still not following. When I replace rows.push(padRow); with padRow.push(); I get the following error: Uncaught TypeError: padRow.push is not a function.

push is a method specific to arrays.
in your case padRow is a function referenced by name *** padRow****

invoking (calling) a function looks like this ‘padRow()’ ← the “()” is what triggers the call.

rows.push(guess what goes here)

don’t forget that padRow takes two arguments ‘rowNumber, rowCount’

1 Like

Thank you for the explanation. That really helped!!

1 Like

@brice.web.developmen ,
Mod edit: removed
it will work.