Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Jason Larkin
Jason Larkin
13,970 Points

Appending an array

I am trying to add the "firstWord" variable to the beginning of the array "firstWord". The error message comes back that task 2 is no longer passing. Can anyone help please?

var spareWords = ["The","chimney","sweep's","dog"];
      var saying = ["quick", "brown", "fox", "jumps", "over", "the", "lazy"];
      var firstWord = spareWords.shift();
      var lastWord = spareWords.pop();
      saying.unshift(firstWord);
Jason Larkin
Jason Larkin
13,970 Points

Thank you Jason; refreshing the browser did it! Thanks again!

1 Answer

Hi Jason,

.push() adds to the end of the array. You want to use .unshift() instead.

push and pop work on the end of the array. shift and unshift work on the beginning of the array.

Jason Larkin
Jason Larkin
13,970 Points

Thank you Jason, but I'm having no luck with that either. Any ideas?

The following passes task 3:

saying.unshift(firstWord);

Maybe try refreshing the challenge.