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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Yusuf Salaam](https://secure.gravatar.com/avatar/f6203f77cb4a7aec0661d4780f523d2e?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Yusuf Salaam
1,748 PointsIm getting stuck on step 3 of array challenge. Can someone please show me how to do it?
var spareWords = ["The","chimney","sweep's","dog"];
console.log(spareWords.toString())
//Shift and unshift method
var firstWord = spareWords.shift();
spareWords.unshift("firstWord");
console.log(spareWords.toString())
//Push Pop method
console.log(spareWords.toString())
spareWords.push("lastWord");
console.log(spareWords.toString())
var lastWord = spareWords.pop();
console.log(spareWords.toString())
var lastWord = spareWords.pop();
var saying = ["quick", "brown", "fox", "jumps", "over", "the", "lazy"];
This is what I have so far!
2 Answers
![Ryan Carson](https://secure.gravatar.com/avatar/edb1260aa6f7f77688deee83e0a088f7?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Ryan Carson
23,287 PointsI'll give you a tip ...
var spareWords = ["The","chimney","sweep's","dog"];
var saying = ["quick", "brown", "fox", "jumps", "over", "the", "lazy"];
/* var firstWord = spareWords.do-something-here */
/* var lastWord = spareWords.do-something-here */
/* saying.do-something-here */
/* saying.do-something-here */
![Peter Szerzo](https://uploads.teamtreehouse.com/production/profile-photos/130040/micro_ptr-couch.jpg)
Peter Szerzo
22,661 PointsHey Yusuf,
Try this:
var firstWord = spareWords.shift();
var lastWord = spareWords.pop();
saying.unshift(firstWord);
saying.push(lastWord);
The array commands are as follows: push - add element to end of the array pop - take element off the end of the array (and return it) unshift - add element to the beginning of the array shift - take element off the beginning of the array (and return it)
This article might help: http://www.bennadel.com/blog/1796-javascript-array-methods-unshift-shift-push-and-pop.htm
Also, fun conversation on why these methods are named as they are: http://www.perlmonks.org/?node_id=613124
Cheers, Peter
Peter Szerzo
22,661 PointsPeter Szerzo
22,661 Pointssorry, Ryan, for giving it away :)