Learn Introductory JavaScript by Building a Pyramid Generator - Step 66

Tell us what’s happening:

I have called padRow in .push() call but didn’t work. I have tried by searching various methods on internet, but sadly nothing works.

Your code so far


// User Editable Region

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

function padRow(rowNumber, rowCount) {
  return character.repeat(rowNumber);
}

for (let i = 0; i < count; i = i + 1) {
  rows.push(function padRow);
}


let result = ""

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

console.log(result);

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 66

1 Like

Welcome to the forum @SINHA_404

Carefully read the instructions.

A function definition includes the keyword function
A function call is structured differently.

Happy coding

1 Like

Tell us what’s happening:

I have tried all possible ways available. But nothing works.

Your code so far


// User Editable Region

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

function padRow(rowNumber, rowCount) {
  return character.repeat(rowNumber);
}

for (let i = 0; i < count; i = i + 1) {
  rows.push(function padRow);
}

let result = ""

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

console.log(result);

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 66

So how to solve this?

Hi there!

You need to call the function padRow within the .push() method. Calling a function didn’t need the function keyword.
Search for how to call a function in JavaScript

1 Like

Hey @SINHA_404 :wave:
Let’s see if I can help.

There are 2 places that need some fixing. The rest is good!

Your function accepts 2 arguments but you only need one (rowCount is not used for anything):

function padRow(rowNumber, rowCount) { // remove rowCount
  return character.repeat(character); 
}

padRow just needs a number which represents the number of ‘#’ characters in your row. Give it some meaningful variable name like “rowLength”.

function padRow(rowLength) {
  return character.repeat(rowLength);
}

Then, in your first for-loop, you can break up what you want to do into 2 steps. Get the row. Add the row…

You also need to start the index ‘i’ at 1 , and not 0.
The first row will be length 1 ( “#” ). Then you want the loop to finish at count, so it must be <= ( less-than or equal to count (8)):

code removed by moderator

You can also do the for-loop like this:
(I did it in 2 steps to make it easier to read)

code removed by moderator

I hope this helps. Best of luck.

in your editable region there is various extra code, make sure you don’t have anythign duplicated, it can cause syntax errors and break everything

I have merged your two topics together, please do not open multiple topics for the same step

hi @anon75571083

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

also you should maybe familiarise yourself with the curriculum before helping

1 Like

Anyone who came here for this qn doubt here’s the answer:
code removed by moderator

hi @rameshsowmya365

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge. How to Help Someone with Their Code Using the Socratic Method

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.