Learn Introductory JavaScript by Building a Pyramid Generator - Step 45

Tell us what’s happening:

Hey everyone, I’m really lost on how to do this next step. Of course you’re supposed to be making the whole # pyramid but I’m just not able to get past the .repeat segment. Here is my code below.

const character = “#”;
const count = 8;
const rows = ;

for (let i = 0; i < count; i = i + 1) {
rows.push(character);
const character = “#”;
character.repeat(i);
}

let result = “”

for (const row of rows) {
result = result + row + “\n”;
}

console.log(result);

Your code so far

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


// User Editable Region

for (let i = 0; i < count; i = i + 1) {
  rows.push(character);
  const character = "#";
  character.repeat(i);
}

// User Editable Region


let result = ""

for (const row of rows) {
  result = result + row + "\n";
}

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/133.0.0.0 Safari/537.36

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 45

Welcome to the forum :wave:

You’ve already declared and assigned the character variable in the first line of code at the top, you don’t need to do this again.

You start with this line of code:

  rows.push(character);

Add the .repeat() method on the character variable.

For example:

console.log(variable);
console.log(variable.repeat(3));

I hope this helps!

2 Likes