Learn Introductory JavaScript by Building a Pyramid Generator - Step 62

Tell us what’s happening:

I understand that I need to call .repeat() on my " ". I am not sure if I have coded too far ahead or what answer the program will accept, but I cannot get it to accept any version of " ".repeat(rowCount - rowNumber) without adding character.repeat(rowNumber * 2 - 1). This completes a pyramid in my console; however, I keep getting this error: You should call .repeat() on your " " strings to repeat them rowCount - rowNumber times. What is it looking for exactly? I called .repeat on my " ".

Your code so far

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


// User Editable Region

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

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

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 62

You start with the line

return " " + character.repeat(rowNumber) + " ";

One of your space strings disappeared

I understand. I tried this: " " + character.repeat(rowNumber) + " ".repeat(rowCount - rowNumber); and get the same error.

" " + character.repeat(rowNumber) + " ".repeat(rowCount - rowNumber);

where is another space string in this code?

Yes, there is a space in the code. When I typed my reply, I mistakenly left out the space. Your suggested code is what I tried first and it did have a space between the quotations. Here is the exact code I have that is not working:
return " " + character.repeat(rowNumber) + " ".repeat(rowCount - rowNumber);

please post your code , using three back ticks (```) in a seperate line, above and below your code.

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

you have missed this one. this one also need repeat method

Wow! Thank you so much! :wave:

1 Like

your most welcome. happy coding.