Learn Introductory JavaScript by Building a Pyramid Generator - Step 69

Tell us what’s happening:

What’s wrong with this code?..

Your code so far

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


// User Editable Region

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

// User Editable Region


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

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

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 69

Hi @booleanmethod9

ReferenceError: repeat is not defined

repeat is a method not a variable.

Happy coding

So this should work then?:

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

Have a look at how you used it on the character variable.

So :
function padRow(rowNumber, rowCount) {
character.repeat(rowCount - rowNumber);
return " " + character.repeat(rowNumber) + " ";
}
?

You should call .repeat() on your " " strings to repeat them rowCount - rowNumber times.

But you just said ‘.repeat()’ is not a string…

.repeat() is a method.

You used that method on the character variable.

Or did you mean this?:
function padRow(rowNumber, rowCount) {

return character.repeat(rowCount - rowNumber) + character.repeat(rowNumber) + character.repeat(rowCount - rowNumber);
}

The " " part needs to stay the in the code.

function padRow(rowNumber, rowCount) {

return “character.repeat(rowCount - rowNumber)” + character.repeat(rowNumber) + “character.repeat(rowCount - rowNumber)”;
}
?

Add the .repeat() method to the strings " "

From your previous post:

For the first string you need to change the character variable to " "
Do the same for the second string.

function padRow(rowNumber, rowCount) {

return character.repeat(rowCount - rowNumber) + “” + “”;
}
?

From an earlier post:

Change the first character variable to " "
Change the third character variable to " "

That should get closer.

Lol. Seems like the beginning…

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

like this?

Keep the .repeat() method, literally replace the variable character with " "

To look like this?:

function padRow(rowNumber, rowCount) {

return “”.repeat(rowNumber);

}

no, you need to still have all three of the components that are being concatenated. You are missing character.repeat(...) and the second " "

You’re saying it will look something like this?:

function padRow(rowNumber, rowCount) {

return “” + “”.repeat(rowNumber) + “”;

}

no, where is the character variable? please reset the step, and then add the repeat() method to the two " " space strings