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

Having problems with this Challenge

The Challenge question is: 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.

<script> var spareWords = ["The","chimney","sweep's","dog"]; var saying = ["quick", "brown", "fox", "jumps", "over", "the", "lazy"]; var firstWord = spareWords; var lastWord = spareWords; saying; saying; </script>

5 Answers

spareWords.shift();

Hi Gary,

Sometimes the error message can be very helpful, as is the case for this challenge. After running the non-working code, it suggested the method to use. Hope this helps!

As I read it, it seems to suggest using BOTH methods shift and unshift simultaneously. The question could have been expressed more simply by saying 'remove the first element...'. The methods themselves are already confusing with their naming conventions.

I used the shift method and I don't know what I'm doing wrong. This is what I am putting in: var firstWord = spareWords.unshift("firstWords"). Obviously I know I'm doing something wrong, but what. I been at for 30 mins going nuts here

Hi Gary,

In your code you're using the unshift method but you should be using the shift method. It does not take any arguments.

It will remove the first element from the array and also return that value.

Gary Christie

If it makes you feel better, I struggled with some of the challenges in this section that could be worded more clearly. Several of these challenges have been made by someone that assumed people taking it would have slightly more knowledge than a complete beginner.

agreed