Learn Introductory JavaScript by Building a Pyramid Generator - Step 69

Tell us what’s happening:

my problem is that idk how to repeat " " rowCount-rowNumber times by using .repeat()

Your code so far

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


// User Editable Region

function padRow(rowNumber, rowCount) {
  " ".repeat(rowCount - rowNumber);
  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; rv:128.0) Gecko/20100101 Firefox/128.0

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 69

Looks like you DO know how to repeat space by a rowCount minus rowNumber times!

The problem isn’t that you don’t know how. The problem was that you didn’t know WHERE to do it.

Where do you think it makes sense to repeat the space that many times?

1 Like

i mean i did it before the return so i thought it could work

Hi, @Program_Parker

i mean i did it before the return so i thought it could work

… and that is perfectly ok!

Now ask yourself: This section of your code:

" ".repeat(rowCount - rowNumber);
return " " + character.repeat(rowNumber) + " ";

What do you think it is returning? In other words, what sort of modifications do you think you are actually applying on the characters after calling the repeat methods in those different parts of the function?

And whatever the result, try to think also why you are getting that result.

1 Like

Hey, thank you so much. I was facing the same problem.

1 Like

but what is the solution after all?

You have to work that out yourself based on the hints given. If you need more help, you can post the updated code in your reply and ask a follow up question.

why can’t you just give the answer so i can understand later why, i don’t think i can get it . Just get back from a month vacation and i barely even remember what was happening.

We’re here to help answer coding questions. If you just want the answers, they are freely available elsewhere.

I mean like your hints are not helping me, could you maybe specify what you mean?

At the moment, what is the part of this problem that is confusing you?

What were you able to understand from the responses you received?

If you understood something, and changed the code, what does your new code look like?

i mean i understood the repeat but idk what’s is the problem with the placing

The end goal is to return spaces, repeated a certain number of times, before and after the character repeated a certain number of times.

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

“update your blank space strings” means you should make a change to the blank space strings in this line:

return " " + character.repeat(rowNumber) + " ";

If you add it before the return then it won’t be returned. The line you added isn’t stored in a variable or returned so it just does nothing, it has no effect on the blank spaces that are in the return line.

i still don’t understand why doesn’t it work it seems okay to me, it just doesn’t work

if you’d like to, join the fCC discord server and discuss the code there one-on-one. It may help you move forward a bit faster since you’re struggling to understand the different responses you’ve received so far.

What is it that you don’t understand? If you can’t ask something specific it’s very hard to know what to explain.

Is it the space strings?
The .repeat() function?

###############
#############
###########
#########
#######
#####
###
#
this is what happened

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Ask for Help button located on the challenge (it looks like a question mark). This button only appears if you have tried to submit an answer at least three times.

The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.

i don’t think my line of code is bad. in my opinion it must be with the placing of it but i can’t understand where should i put it

That’s correct sort of.

You need to modify the return line, don’t add a new line above it.

  " ".repeat(rowCount - rowNumber);  //Dont add a new line
  return " " + character.repeat(rowNumber) + " "; //modify this line instead