Learn Introductory JavaScript by Building a Pyramid Generator - Step 68

Tell us what’s happening:

icant undestand i tried so much but cant get the correct answer

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

Use the addition operator to concatenate a single space " " to the beginning and end of your repeated character string.

You can think of it this way:

In the following function, rowNumber is the " repeated character string"

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

Now you need to add spaces at the beginning of rowNumber using string concatenation. For example, "a" + " " + "b" results to "a b".

You just need to add one space to the left and right of this repeated character. They showed you an example of how to add a space to something so try and show us your code again if you don’t succeed.

3 Likes

Yes this is not a solution that uses the addition operator as requested.
I would suggest that you edit the post to not include invalid solutions will just serve to confuse people here.

Great point. I deleted the post.

1 Like

Thank u man, I finnaly found a solution <3

please note to actually put a space inside the quotes " " instead of just “”. code could be okay but if you dont put that space it will return an error