Learn Introductory JavaScript by Building a Pyramid Generator - Step 61

Tell us what’s happening:

I am required to use the addition operator to concatenate a space before and after the repeated character. Earlier I added spaces between double quotes like this (“ “). The test result was that I should add spaces. Now I deleted the double quotes and got the following result:
SyntaxError: unknown: Unexpected token (6:41)
I don’t think that the plus operator is the unexpected token because there is another one at the beginning with no reference to it as unexpected token. I can’t see the error.

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;
}

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/125.0.0.0 Safari/537.36 Edg/125.0.0.0

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 61

Hello.

This is your character string.

 character.repeat(rowNumber)

Do you know what to do with it now?

Hello, I am required to add spaces before and after the repeated value using the addition operator. Did I understand the challenge correctly?

I don’t think so, sir. In the above reply, I have shown you the character string. Now, what you need to do is to add the spaces before and after.

This is how you add spaces before after or both.

" " + variable/text + " "

You should nest the spaces inside quotation marks, as I did.

1 Like

I did that earlier as you can see above. I did it now based on your advice. Here is the code:
return character.repeat(" " + rowNumber + " ");
and this is the comment afrer the test:
// running tests 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. Your

padRow()

function should return the repeated

character

series with a space before and after the series. // tests completed
AS you see the spaces that I added are not recognized.

You need to concatenate your return value, not the .repeat() argument.
Your return value is:

character.repeat(rowNumber)

@haahinnawy

1 Like

I need to add spaces before and after.

Adding Space example:

" " yourString " "

Adding addition operator example:

+ yourSring +

@haahinnawy

The only argument the repeat method takes is a number, which is the number of times it should repeat the string it was called on.

"GOAL!!!".repeat(3) // 'GOAL!!!GOAL!!!GOAL!!!'

If you want to add a space on either side of the string it returns, it should happen to the left and right of the method call.

" " + string.method(argument) + " ";

Thank you very much. Sorry that I misunderstood what was said earlier. Now it is all right. What I did is:
return (" " + character.repeat(rowNumber) + " ");
Before this the brackets were put inside the quotation marks. Sorry also for inconvenience that I caused.

1 Like