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 a stroke ...

Hi there, I like challenging assignements, but I think you went a little bit too far here. I don't understand a single word of what's requested from me. I mean I speak english but can't figure out what I'm supposed to do ? set firstword as the firstword whilst removing it from the beginning ..... wait' what ???!

if somebody could explain this to me like I'm 8 years old ? please. ;)

thank you for your time Cheers A.

3 Answers

Calvin Nix
Calvin Nix
43,828 Points

Hello Alban,

Yeah I just read through the assignment and the wording is a bit confusing.

All the challenge wants you to do is essentially "steal" values from the array.

You can do this by shifting the array and it will kick out the first item of the array.

Please let me know if that clears up some confusion.

thanks, Calvin

Hi Alban,

I'll try to break it down for you.

Here's the instructions: 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.

The challenge wants you to do 2 things. The variable firstWord should be assigned the first word from the spareWords array and also that first word should be removed from the array.

The first word from that array is the word "The". So the variable firstWord should get the value "The" and the spareWords array should look like ["chimney","sweep's","dog"] when you are done.

The video shows 4 methods: push, pop, shift, and unshift We need the one that deals with removing the first element from an array. You may need to review what each one does but shift() is the one that removes from the beginning.

The shift() method does 2 things, hint, hint. It removes the first item from an array and it also returns that value. This means you can use that return value as part of a larger expression or simply assign that return value to another variable which is what we want to do here.

So spareWords.shift() is going to evaluate to the string "The" which can then be assigned to the firstWord variable.

var firstWord = spareWords.shift();

I hope that makes sense. Let us know if anything isn't clear.

Hi Calvin, thank you for your answer, I understand what you mean but I think I'll leave it there for now and come back later after looking at the video again.

thx A.