Learn Introductory JavaScript by Building a Pyramid Generator - Step 68

Tell us what’s happening:

I am having some difficulty understanding this the instructions are kind of confusing. I have the empty string and plus at end of the empty string at beginning dont understand where to put it has a error before

Your code so far

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


// User Editable Region

function padRow(rowNumber, rowCount) {
  return character .repeat(rowNumber) + " ".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/126.0.0.0 Safari/537.36 Edg/126.0.0.0

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 68

the original code when you reset this step is shown as follows:

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

This code takes the character variable and repeats it a rowNumber of times.

The instructions ask you to append some spaces to this.
One space should be added to the beginning and one to the end.

The instructions also say that you should use the concatenation operator + to add the required space(s).

An example was shown to you of how to add one space:

" " + "string"

and this example will add one space to the beginning of the string

So through observation, how would you add one space to the beginning of
return character.repeat(rowNumber);

and how would you add one space to the end?

1 Like

ok I was able to figure out the first one code passed for that but not end i used " " + repeat. (rowCount); theres a error around it with red

so you were able to append a single space character, that is great.
Now you just need to append one more space character but to the end.
What have you tried for that? Let us know if you still need help.

1 Like

I added .repeat(rowCount); for the second one but i dont know how to put the empty string for it it says your missing a semi colan but i have one at the end

let me see if an example will help.

The original example they gave was:
" " + "string"

And this example was for adding a single space to the beginning of the string.
Now if I want to add a single space to the —end—, I would do this:

"string" + " "

Notice it is not very different than the first example. We just used the concatenation operator to do this at the end versus at the beginning.

1 Like

Ok thank you so much for allowing the help. I was searching the forum from others they were adding result and adding a second character I passed.

1 Like