Learn Introductory JavaScript by Building a Pyramid Generator - Step 69

Tell us what’s happening:

I am calling the repeat method and I’ve tried various ways like: return character.repeat(8 - ) + " ". I don’t know how to call the repeat method on my " " strings using the rowCount and rowNumber.

Your code so far

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


// User Editable Region

function padRow(rowNumber, rowCount) {
  return character.repeat(8 - []) + " ";
}

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

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 69

the original code for this step shows this:
return " " + character.repeat(rowNumber) + " ";

notice that .repeat function call? It is added to the immediate right of the variable character.
This is done to make character repeat a certain number of times.

So to make the space character repeat, add the .repeat with the parenthesis and the value that it repeats to the immediate right of the " " space character.

String.prototype.repeat() method only takes 1 value as a positive integer.

also pay attention to the data types. if repeat only accepts a number then it wont take an array.

also you cant subtract an array from an integer because they are different data structures.

function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber);
}
this is how I updated it and it does not pass.

You should not have deleted any code. Reset the step to restore the code and this time only add the repeat calls. You will need two of them. (One for each space character)

without deleting code, it still does not pass

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

Please click reset and you will see that this time you deleted the space on the right side of the character repeat.

You need to add code next time without removing any.

This is me adding code without deleting any, and I’m still not getting it to pass.
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(rowNumber) + " ";
}

very good, now you just need to repeat the last space too

1 Like