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 trialSurendra Kulkarni
6,826 Pointsshift() 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
Dino Paškvan
Courses Plus Student 44,108 PointsWhere in the challenge is it asking you to use those two methods simultaneously?
Jason Anello
Courses Plus Student 94,610 PointsThis 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.