Learn Introductory JavaScript by Building a Pyramid Generator - Step 68

Tell us what’s happening:

I’m supposed to add " " at the beginning and end of the return string. Not how to get it in the (rowNumber) without having it error out. Does it need to go on the outside of it?

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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 68

This challenge wants you to add space before and after the function call. Not necessarily inside it.

Hope this helps. Happy coding. :slight_smile:

Thank you. I moved the end +" " to outside the ), which took care of that error of having at the end, but am struggling to figure out how to add " " + to the beginning of the string, because having it inside and outside of the ( both throw errors. I’m missing something, but not sure what.

Can you show me your current code?

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

Ended up with the correct solution , but do not understand the why of it.

what do you mean? If you want to understand, this is a good place to ask.

I thought the string began with the (rowNumber). Since I had to put the +" " before character, does that mean everything including and after character is the string and return is the function?

I’m not 100% sure I understood this but let me try to explain anyway.

you have a character variable in the return statement.
That character variable is itself a string.
You also have a function (or method) being called on that string.
character.repeat()
This repeat is taking the string in character and trying to repeat it the number of times you provided when you called it. In your last shared code it was being repeated rowNumber times.
So now character.repeat(rowNumber) is itself returning a string
Then we use the concatenation operator to expand that string by adding spaces to the right and left.

Not sure if I got what you wanted to hear in the above, but I hope so

Thank you. Now that makes sense. I appreciate your help and patience.

1 Like

Use the addition operator to concatenate a single space " " to the beginning and end of your repeated character string.
Mod edit: code removed

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

1 Like

sorry, next time i’ll do that thank you for your advice

1 Like