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 trialYele X.
5,537 PointsOn line 18, use a method on the 'spareWords' to set 'firstWord' to be first word of the 'spareWords' array whilst simult
.shift method is not working for this challenge
Can anyone explain why .shift doesn't work?
5 Answers
Gloria Dwomoh
13,116 PointsOh okay. I think what happened is that you didn't understand the question well. Shift does work but it is asking you to put what it returns into the variable firstWord, you don't need to give an input to the method shift as it removes the 1st element and returns it.
You can read more from Mozilla's developer post - Array.prototype.shift() "The shift() method removes the first element from an array and returns that element. This method changes the length of the array."
Try this
var firstWord = spareWords.shift();
Harry Tran
10,618 PointsHonestly I don't think this one was worded very properly to understand the context of what it was asking. Like I thought they wanted me to add a new word to the beginning called "firstWord" than remove it.
rafael perez
4,269 PointsI totally agree with you, this question is not clear at all, it made me lost a lot of time. It's poorly redacted
Danita Copeland
7,547 PointsI also agree. The question could have been written more clearly. I interpreted the question the same way that you did and spent 15 minutes trying to solve it. I'm glad someone posted the answer.
Marc Balestreri
8,211 PointsWhere is the Answer posted? I am stuck on this too since it is not properly worded.
Gloria Dwomoh
13,116 PointsHi Marc Balestreri , try reading my answers below.
Alan Sánchez
Courses Plus Student 3,983 PointsI agree as well. It's not that I didn't understand what pop, push, shift and unshift do, it's just that the instructions were not clear and I got confused. In the end I figured it out after I re-read the instructions several times trying to figure out if they meant something else, as they did.
Yele X.
5,537 Pointsyes, I initially used spareWords.shift("firstWord") which should work, based on the content of the tutorial.
Gloria Dwomoh
13,116 PointsCan you post your code?
Yele X.
5,537 Pointshttp://teamtreehouse.com/library/javascript-foundations/arrays/methods-part-1-2
Are you able to view the challenge through the link?
Gloria Dwomoh
13,116 PointsSince shift is a method, it has to be written as .shift(); did you write it like that?