Learn Introductory JavaScript by Building a Pyramid Generator - Step 23

Tell us what’s happening:

You should have seen “freeCodeCamp” printed to the console. This is because .pop() returns the value that was removed from the array - and you pushed “freeCodeCamp” to the end of the array earlier.

But what does .push() return? Assign your existing rows.push() to a new pushed variable, and log it.

My resolution was:

rows.push(“freeCodeCamp”);
let pushed = rows.push(“freeCodeCamp”);

Your code so far

let character = 'Hello';
let count = 8;
let rows = ["Naomi", "Quincy", "CamperChan"];

// User Editable Region

rows.push("freeCodeCamp");
let pushed = rows.push("freeCodeCamp");

// User Editable Region

let popped = rows.pop();
console.log(popped);
console.log(rows);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36

Challenge Information:

Learn Introductory JavaScript by Building a Pyramid Generator - Step 23

use push once, not twice

The solution is adding the new pushed variable to the existing
rows.push(“freeCodeCamp”); line, rather than adding an additional line with the new pushed variable. Then make sure to log it after.

let pushed = rows.push(“freeCodeCamp”);
console.log(pushed);

Happy coding!

I am stuck here. Could you show me the code?
Here is my code:

let character = 'Hello';
let count = 8;
let rows = ["Naomi", "Quincy", "CamperChan"];
rows.push("freeCodeCamp");
let pushed = rows.push("freeCodeCamp");
console.log(pushed);
let popped = rows.pop();
console.log(popped);
console.log(rows);

You have the correct code, but you’re adding it as an additional line rather than editing the line that was already there.

rows.push(“freeCodeCamp”); is what you start with. Integrate the new pushed variable into that line instead of writing a new line, and you should be good.

Good luck and happy coding!

1 Like

hei @mesarojgiri please open your own post to ask for help

solution removed by moderator

please do not provide full solutions

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.