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

On 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

Oh 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
Harry Tran
10,618 Points

Honestly 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
rafael perez
4,269 Points

I totally agree with you, this question is not clear at all, it made me lost a lot of time. It's poorly redacted

I 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
Marc Balestreri
8,211 Points

Where is the Answer posted? I am stuck on this too since it is not properly worded.

Hi Marc Balestreri , try reading my answers below.

Alan Sánchez
Alan Sánchez
Courses Plus Student 3,983 Points

I 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.

yes, I initially used spareWords.shift("firstWord") which should work, based on the content of the tutorial.

Can you post your code?

http://teamtreehouse.com/library/javascript-foundations/arrays/methods-part-1-2

Are you able to view the challenge through the link?

Since shift is a method, it has to be written as .shift(); did you write it like that?