Learn Introductory JavaScript by Building a Pyramid Generator - Step 68

Tell us what’s happening:

Hi again, so I tried multiple solutions to this but I seem not to get the thing I am doing wrong. here’s the hint message I get? You should call .repeat() on your " " strings to repeat them rowCount - rowNumber times. the question is what do I change exactly?

Your code so far

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


// User Editable Region

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

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 68

Where are your " " strings? It looks like you deleted them?

Yes because its not working,
this was what I wrote initially;
function padRow(rowNumber, rowCount) {
return " “+character.repeat(rowCount-rowNumber)+” ";
}

Ok, but you are not calling .repeat on the " " strings. You changed the argument to the call to .repeat on the string character instead of repeating the " " strings

that’s the part I am not getting, am I to add the rowCount-rowNumber inside " ", after, in between… I am confused.

What does this code do, in your own words?

1 Like

repeat the # for the result derived from rowCount-rowNumber, so if rowCount-rowNumber = 1, repeat it only one time…ish?

If character happens to be #, yes.

So how would you repeat " "? It should look similar.

hmm. from what you said now I am writing it like this but its still wrong;
function padRow(rowNumber, rowCount) {
string = " ";
return string.repeat(rowCount-rowNumber)+character.repeat(rowNumber);

}
is it I have to create a seperate function, because they can’t be two returns in one function

No, you need to create zero extra functions or variables.

character is a string. You can call .repeat() on strings. So how would you repeat the string " "?

Thank you for making me jug my brain more, I understand now.

function padRow(rowNumber, rowCount) {

return " “.repeat(rowCount-rowNumber)+character.repeat(rowNumber)+” ".repeat(rowCount-rowNumber);

}

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.