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
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
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
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)
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
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.