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 trialalexeiklika
Courses Plus Student 2,589 PointsIt appears they are asking to unshift and shift simultaneously. I don't understand these instructions.
How can you unshift to the beginning of an array and then shift the element away in the same statement. Why would you even want to do this? It is possible I misunderstand the challenge: Javascript Foundations: Methods Part 1: Coding Challenge.
1 Answer
Stone Preston
42,016 PointsAccording to the documentation on the shift method, the shift() method removes the first element from an array and returns that element. This method changes the length of the array.
on line 18, you need to set the value of the firstWord var by calling the shift() method on the spareWords array. This will remove the first element from the spareWords array and return that value, thus setting the firstWord variable to the first element of spareWords, whilst simultaneously removing it from the array.
var firstWord = spareWords.shift();
alexeiklika
Courses Plus Student 2,589 PointsI misunderstand the phrasing of the instructions. Thank you for clarifying them for me!
Stone Preston
42,016 Pointsyeah its kind of a confusing question.
alexeiklika
Courses Plus Student 2,589 PointsI'm used to seeing words in single quotes as literal strings. Might it be easier to color code variables? Just a thought.
Jim Withington
12,025 PointsThis one confused me as well.
alexeiklika
Courses Plus Student 2,589 Pointsalexeiklika
Courses Plus Student 2,589 PointsInstructions were as follows: 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.
Code: var spareWords = ["The","chimney","sweep's","dog"]; var saying = ["quick", "brown", "fox", "jumps", "over", "the", "lazy"]; var firstWord = spareWords; var lastWord = spareWords; saying; saying;