Learn Introductory JavaScript by Building a Pyramid Generator - Step 68

Tell us what’s happening:

hello guys!
how i can You concatenate a single space to the beginning of the returned value?

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 (X11; Linux x86_64) 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

1 Like

Hi Samuel,

Look at the given example in the instruction:

" " + "string"

this will return a new string: " string"

The code above concatenate a single space " " to the beginning of the string "string".

What we need to do is:

concatenate a single space " " to the beginning and end of character.repeat(rowNumber)

2 Likes

wow @toan that is great i was very struggle with this question but finally i try to do as you say & i passed it!thanks.

1 Like

So what in particular are we adding or tagging on here? Some empty spaces or quotations marks as well? Hard to follow that.

Hi @darstol ,

We just need to add an empty space at the beginning and the end of the returned string, there are no quotation marks here.

For example:

When character.repeat(rowNumber) is "AAA", the current function padRow returns the string "AAA".

What we need to do is: We need to make changes to the padRow function to make it returns the string " AAA " (with the space at the begining and the end), instead of "AAA".

About the quotation marks (""), it’s the sign to let us know that the data we are dealing with is a string.
For example, Hello! is not a string, but "Hello!" is a string.

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

" " + “string” + " "