Learn Introductory JavaScript by Building a Pyramid Generator - Step 68

Tell us what’s happening:

I have been stuck on this for a good while now and cant figure it out. I have looked on the forum but nothing seems to be working for me.
Here is my code so far,
return character.repeat( " " + rowNumber + rowCount + " ");

How can I concatenate rowNumber and rowCount with a string with a space like this " " in front and at the end.

Thank you

Your code so far

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


// User Editable Region

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

// 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; rv:128.0) Gecko/20100101 Firefox/128.0

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 68

The repeat function is expecting you to give it a number so what you have here will not work.

Reset please. This time add the space to the left and right of the repeated character.

Thank you for responding so quickly.

I am still not understanding what to do right.

I reset and wrote character.repeat(" " + rowNumber + " ");

Do I need to add the rowCount to the concatenation?

The function repeat is expecting a number. So if you try to give it a space character concatenated to a number concatenated to a space character then this will not work.

Instead, leave the code as it was at the start (click reset) and add the space to the left and right of the character

That feels so wrong but it works. Thank you

1 Like

Try to expand on why it feels wrong? It is important you understand how things work in coding.

1 Like

Thanks again. The prompt literally told me exactly what to do. I was overthinking it. Every little struggle helps me learn. Seriously I appreciate the help and fast response. :laughing:

1 Like