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

Methods Part 1 elements code challenge

Hey I am stuck on challenge 1/4 here. I know I need to be using the shift method but can't for the life of me figure it out. I have been back through the video too but I think it's more an issue of understanding the question that not knowing how to do it. The 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." -- Any help greatly appreciated. :)

5 Answers

I got it working using the shift and unshift methods :)

Please somebody can help me out this is my piece of code var spareWords = ["The","chimney","sweep's","dog"]; var saying = ["quick", "brown", "fox", "jumps", "over", "the", "lazy"]; spareWords.unshift("firstWord"); var firstWord = spareWords.shift(); can anybody point what am i doing wrong. thx

Again another e.g <script> var spareWords = ["The","chimney","sweep's","dog"]; var saying = ["quick", "brown", "fox", "jumps", "over", "the", "lazy"]; spareWords.unshift("firstWord"); alert(spareWords); spareWords.shift(); alert(spareWords); var firstWord = spareWords; var lastWord = spareWords; saying; saying; </script> it work's but does not pass what should i do ?

use spareWords.shift(); on the variable they asked for only. You have to go back over the difference between .shift and unshift. cant really use both on this particular question.

Has anyone figured this out? How can you set 'firstWord' to be the first word of the array and remove it? I understand shift and unshift, but this question makes no sense.