Learn Introductory JavaScript by Building a Pyramid Generator - Step 68

Tell us what’s happening:

Anyone here to help me with this exercise i cant seem to find 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 (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

Hello @osidev!

Well done on making it this far in the course!

This challenge shows you that you can also apply a method (i.e. .repeat()), to a literal character in addition to a variable representing one.

Your code below places a single space ( " " ) on either side of an expression (e.g. character.repeat(rowNumber)).

The challenge asks

Update your blank space strings to be repeated rowCount - rowNumber times.

So, you need to apply the repeat method directly to the " " in your return statements.

Since .repeat takes a parameter for the number of times you’d like it repeated, this value is in the form of an expression (rowCount - rowNumber). Just shove that in for the parameter and you will move on.

Does this help?
Keep up the good progress!

Happy Coding! :slightly_smiling_face:

2 Likes

Hi, so I’ve done this and it’s still not working…

1 Like

Hi there!
Create your own topic to the challenge step, using help button that appears below the challenge editor when you attempting wrong code more than three times.

1 Like