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 JavaScript Foundations Arrays Methods: Part 1

Surendra Kulkarni
Surendra Kulkarni
6,826 Points

shift() and unshift()

This question needs to edited so that it conveys what is expected. In the context of "possibilities are endless" I would like jS expert to demonstrate how to use the two methods simultaneously. If not please change the wording to reflect you expectations succinctly.

2 Answers

Where in the challenge is it asking you to use those two methods simultaneously?

This is task 1 "On line 18, use a method on the 'spareWords' to set 'firstWord' to be first word of the 'spareWords' array whilst simultaneously removing it from the beginning of the array."

There isn't anything there to suggest you should use both methods together. shift() removes from the beginning and unshift() adds to the beginning.

What the challenge wants you to realize by "simultaneously" is that the shift() method does two things. It removes the first element from an array and also returns that element. So you could use it in an expression or in this case, assign it to a variable.