Tell us what’s happening:
What’s wrong with this code?..
Your code so far
const character = "#";
const count = 8;
const rows = [];
// User Editable Region
function padRow(rowNumber, rowCount) {
return " " + character.repeat(rowNumber) + " " + repeat(rowCount - 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/130.0.0.0 Safari/537.36
Challenge Information:
Learn Introductory JavaScript by Building a Pyramid Generator - Step 69
Teller
October 26, 2024, 11:38pm
2
Hi @booleanmethod9
ReferenceError: repeat is not defined
repeat
is a method not a variable.
Happy coding
So this should work then?:
function padRow(rowNumber, rowCount) {
repeat(rowCount - rowNumber);
return " " + character.repeat(rowNumber) + " ";
}
Teller
October 26, 2024, 11:45pm
4
Have a look at how you used it on the character
variable.
So :
function padRow(rowNumber, rowCount) {
character.repeat(rowCount - rowNumber);
return " " + character.repeat(rowNumber) + " ";
}
?
But you just said ‘.repeat()’ is not a string…
Teller
October 27, 2024, 1:50am
8
.repeat()
is a method.
You used that method on the character variable.
Or did you mean this?:
function padRow(rowNumber, rowCount) {
return character.repeat(rowCount - rowNumber) + character.repeat(rowNumber) + character.repeat(rowCount - rowNumber);
}
Teller
October 27, 2024, 1:52am
10
The " "
part needs to stay the in the code.
function padRow(rowNumber, rowCount) {
return “character.repeat(rowCount - rowNumber)” + character.repeat(rowNumber) + “character.repeat(rowCount - rowNumber)”;
}
?
Teller
October 27, 2024, 1:59am
12
Add the .repeat()
method to the strings " "
From your previous post:
For the first string you need to change the character
variable to " "
Do the same for the second string.
function padRow(rowNumber, rowCount) {
return character.repeat(rowCount - rowNumber) + “” + “”;
}
?
Teller
October 27, 2024, 2:10am
14
From an earlier post:
booleanmethod9:
Or did you mean this?:
function padRow(rowNumber, rowCount) {
return character.repeat(rowCount - rowNumber) + character.repeat(rowNumber) + character.repeat(rowCount - rowNumber);
}
Change the first character
variable to " "
Change the third character
variable to " "
That should get closer.
Lol. Seems like the beginning…
function padRow(rowNumber, rowCount) {
return " " + character.repeat(rowNumber) + " ";
}
like this?
Teller
October 27, 2024, 2:48am
16
Keep the .repeat()
method, literally replace the variable character
with " "
To look like this?:
function padRow(rowNumber, rowCount) {
return “”.repeat(rowNumber);
}
im59138
October 27, 2024, 7:57am
18
no, you need to still have all three of the components that are being concatenated. You are missing character.repeat(...)
and the second " "
You’re saying it will look something like this?:
function padRow(rowNumber, rowCount) {
return “” + “”.repeat(rowNumber) + “”;
}
im59138
October 27, 2024, 5:37pm
20
no, where is the character
variable? please reset the step, and then add the repeat()
method to the two " "
space strings