Learn Introductory JavaScript by Building a Pyramid Generator - Step 108

Tell us what’s happening:

i cant solve this i even looked on the help forum and did as someone else was told typing key for key it didnt do anything

Your code so far

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

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

// TODO: use a different type of loop
/*for (let i = 1; i <= count; i++) {
  rows.push(padRow(i, count));
}*/

/*while (rows.length < count) {
  rows.push(padRow(rows.length + 1, count));
}*/

/*for (let i = count; i > 0; i--) {
  rows.push(padRow(i, count));
}*/


// User Editable Region

const numbers = [1, 2, 3];


const unshifted = numbers.unshift(5);
console.log(unshifted);
console.log(numbers);

const shifted = numbers.shift();
console.log(shifted);
console.log(numbers);

// User Editable Region


let result = ""

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

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

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 108

You need to change the order of the code, like this:

MOD EDIT: Solution removed.

Directly below your numbers array, declare a shifted variable and assign it the result of calling .shift() on the numbers array. On the next line, log the shifted variable to the console.

You haven’t put your variable declaration directly below the numbers array. Also, you’ve added an additional console.log() which isn’t required.

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.

1 Like

i still dont get it declare how exactly?

Oh sorry, first time replying, my bad, thanks!

Hi @Sinan

Here is a comparison of the original code and your code.

The code in blue is the original code, the code in red is your code.
The code in magenta is the overlap.

For this step you need to place the shifted variable declaration and the console log for it below the numbers array.

Happy coding

No worries and welcome to our community!

here’s what i got:

 console.log(numbers);
const shifted = numbers.shift();
console.log(shifted);

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

it still isnt working

console.log(numbers);
const shifted = numbers.shift();
console.log(shifted);

You shouldn’t have that first console.log().

did that too, didnt work

const shift = numbers.shift();
console.log(shift);

Please post your full code.

1 Like

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

1 Like

why am i typing in the answer and it isnt working? the code is even showing up on the compiler

You may have an error somewhere else in your code. Please post your full code, using the correct formatting, as indicated above.

const character = "#";

const count = 8;

const rows = [];

function padRow(rowNumber, rowCount) {

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

}

// TODO: use a different type of loop

/*for (let i = 1; i <= count; i++) {

rows.push(padRow(i, count));

}*/

/*while (rows.length < count) {

rows.push(padRow(rows.length + 1, count));

}*/

/*for (let i = count; i > 0; i--) {

rows.push(padRow(i, count));

}*/

const numbers = [1, 2, 3];

const unshifted = numbers.unshift(5);

console.log(unshifted);

console.log(numbers);
const shift = numbers.shift();

console.log(shift);

Your code is still in the wrong order.
You need to put the shifted variable directly below the numbers array (i.e. above the unshifted variable).