Learn Introductory JavaScript by Building a Pyramid Generator - Step 61

Tell us what’s happening:

I should use the addition operator to add a space before and after the returned values. So far, my code is;
return character.repeat(" " + rowNumber+ " ");
This is not recognized, and the code doesn’t pass. There was a similar question before with a code that was different from mine. The answer was not there but there was only a reply from the person who inquired, saying he was in need of only the white space. I tried all changes that I imagined but did not discover my mistake.

Your code so far

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

// User Editable Region

function padRow(rowNumber, rowCount) {
  return character.repeat(" " + 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;


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36 Edg/

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 61

1 Like

First check if you’re calling repeat correctly

The method takes an integer for how many times a string should repeat.

1 Like

No, I am afraid this is not the point as the repetition will take place according to the for…of loop and the number of repetitions is determined by the variable (count) which is equal to 8.
Did I misunderstand you?

1 Like

Yes, you are correct. The code inside the loop will be executed repeatedly.

But the issue isn’t that, it’s how you used .repeat() method.

This isn’t valid. As .repeat() method takes an integer number as a parameter representing how many times should the string be repeated.


let symbol = "#";
console.log(symbol.repeat(3));    // ###

Another Example:

let symbol = "#";
let output = "(" + symbol.repeat(3) + ")";
console.log(output);    // (###)

That last example is very close to what the challenge wants you to do.
Try resetting the challenge and give it another shot.

1 Like

Hi there. The challenge isn’t asking you to repeat an blank line. The challenge wants you to add a blank space before you repeat and after you repeat.

1 Like

Repeat only takes as an argument the number of times you want to repeat, nothing else, i mean, the blank spaces don’t should be in there.

1 Like

Sorry, the spaces are necessary to shape a pyramid, and thus, have to be repeated. Thanks anyway for your response.

1 Like

I would like to add also the comment that came when the test didn’t pass the code. It says:
You should concatenate an empty space to the beginning of your returned value. You should concatenate an empty space to the end of your returned value.
I already added spaces, so, what is wrong about the spaces that I added?


series with a space before and after the series.

1 Like

do not change the argument of repeat, you are not asked to change that.
You need to add spaces at beginning and end of returned string

1 Like

I did that. So far, I reset twice and I got the same comments as a result of the test.

I did not change the argument of repeat. I am just adding spaces and this is not recognized in the test. The challenge asks the following:
Use the addition operator to concatenate a blank space " " to the beginning and end of your repeated character string. My code now is:
function padRow(rowNumber, rowCount) {
return character.repeat( + rowNumber +);
The comment after the test is:
SyntaxError: unknown: Unexpected token (6:40)
I got similar comments before when I put one space after the addition operator and the unexpected token was shifted to (6:41) in the same line. What is meant by the unexpected token at (6:40) in the above code?

This is in response the + operator you have included in the argument to your .repeat method call.

You have, the original call to the .repeat method in the lesson is,

return character.repeat(rowNumber);

and you have changed it to

return character.repeat( + rowNumber +);

As stated, the .repeat method must take a number as an argument, representing the number of times you wish to repeat the character string.

As this commenter said, this example is very close to what the lesson is asking you to do. Follow this pattern exactly, using your character string, row number, and " " in its place.

The repeated character will be a string, and you are asked to concatenate a space to the front, and one to the end, and then return that resultant string.

1 Like

l didn’t change the argument. I am adding spaces as the challenge asked. The + operator is also required. The challenge says: use the addition operator to add spaces.

You are right, but you adding it on wrong place.

May be. Please tell me what is exactly the wrong place. I tried all possible positions. Please read all what I wrote describing what is happening. I explained in detail and mentioned the comments that came with each test result.

Do not place spaces or the + signs inside the argument of the method call character.repeat(rowNumber) ← that code should not be changed. The spaces and plus signs go around that entire value, as was demonstrated in the example previously.

"(" + symbol.repeat(3) + ")"

Thanks to all of you, and sorry that I misunderstood what was said earlier. Yet, I am not sure if I understand now correctly. This is what I did:
return " (" + character.repeat(rowNumber) + ") ";
and this is the result of the test:
// running tests Your


function should return the repeated


series with a space before and after the series. // tests completed
You see that the added spaes are still unrecognized.
Here is also the repeated values:
No spaces are there before or after.
Sorry for invonvenience.

Remove that "(" ")" braces within strings, and leave a space in both " ".

1 Like