Learn Introductory JavaScript by Building a Pyramid Generator - Step 69

Tell us what’s happening:

i’m stuck at this step i’m not sure what i’m doing wrong or maybe i didn’t understand the question properly, what i get from the question is that i need to repeat the space " " rownumber - rowcount times but i don’t know how to do that

Your code so far

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


// User Editable Region

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

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 69

the original line of code that you’re modifying looked like this:
return " " + character.repeat(rowNumber) + " ";

And this had exactly one space followed by a character variable that we repeat rowNumber of times followed by exactly one space.

So just like you repeated the variable character, you can repeat a space character by just dot chaining it like you did for character. (don’t modify the character repetition though. Just add the repeat function to each space character on both ends)

thank you so much it worked.

1 Like