Function in JavaScript

Hello guys! Please i need help understanding how this code works:
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);

It from the Pyramid Generator, can anybody explain how it works?
That line is really hard to understand, can you break it down for someone new to coding

what is it that is confusing to you? what is it that you understand instead? starting from what you understand is a much better way to help you

I understand padRow is a function with two arguments, but what I don’t understand is it what it returns: what those line of code does?

there are many things used to make the return string, there is a string made of a space " ", there is the repeat function, there is the character variable, and the rowNumber and rowCount parameters are used, and the concat + operator is sued, which of these are confusing you?

I am confused of what they stand to perform as a line of code?
Like what does this line of code do:
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);

which part?

the return determines the output of the function
the repeat repeats the string on which it’s used a number equal the argument passed to it
the + concatenates two strings together
the - is the subtraction operation, it’s used between two numbers to make a new number

which part of the line?

you can also go back several steps so you can build it again step after step

1 Like

Thank you, I will do that. Last question please:
what’s the essence of adding " ".repeat(rowCount - rowNumber) to the end of the code, when if removed, it doesn’t change the pyramid?

so that the output is a rectangle, there is the same number of spaces before and after

1 Like

Thank you for making our time to explain, appreciate.