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 trialGeorge Drakoglou
7,969 PointsArrays method's part 1 challenge:elements (new)
I was rewvewing a little javascript and I saw some new challenges. All of the was easy but I stuck in one. It says
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.
var spareWords = ["The","chimney","sweep's","dog"];
var saying = ["quick", "brown", "fox", "jumps", "over", "the", "lazy"];
var firstWord = spareWords;
var lastWord = spareWords;
I quite didn't understand the deal. To put something on the beginning of an array we use unshift amd to remove it we use shift.
I did something like
var firstWord = spareWords.unshift() or .shift() but I quite didn't know what to put in the parenthesis;
Adam Ruf
10,638 PointsThanks, George & Marvin!
Glad I'm not the only one who got stuck on this one.
I think this question was poorly worded and needs updating. It sounded like it was asking us to use the .unshift method to add the string "firstWord" to the array and simultaneously use the .shift method to remove it (Which is kind of a weird request).
More helpful wording for this challenge might be something like, "For the variable "firstWord", use a method to remove the first word from the beginning of the "spareWords" array.
Gregory Dillon
Courses Plus Student 2,228 PointsAdam Ruf
Same
Juliano Vargas
Courses Plus Student 15,575 PointsI am having the same issues with this task it seems that we are not understanding what they want us to do or we are not interpreting well or the question is badly elaborated anyone know how the code to pass this task?
Juliano Vargas
Courses Plus Student 15,575 PointsOk here is what i did to pass this task use this : var firstWord = spareWords.shift(); and forget about unshift(); all it does is remove "the" from the array spareWords so the does the question make sense to anybody?
Joga Gavidia
4,047 PointsThe question is confused, have to be better explained!
13 Answers
Mike Rolih
9,766 PointsAll I did to pass this challenge was to omit the .unshift() method and just used the .shift() method like this: var firstWord = spareWords.shift(); and this should work for you. This question is poorly written and really confusing and should be revisited by Treehouse.
Benjamin Noack
8,079 PointsI agree, the wording needs improvement. Thanks
danieldeepak
9,934 PointsI do agree, they need to rephrase their questions. I spend more time trying to figure out poorly written questions than code.
Enny Benzonelli
6,479 PointsI agree. The question is really confusing. It should be reworded.
Juliano Vargas
Courses Plus Student 15,575 PointsOk here is what i did to pass this task use this : var firstWord = spareWords.shift(); and forget about unshift(); all it does is remove "the" from the array spareWords so the does the question make sense to anybody?
George Drakoglou
7,969 PointsThank you very much!!!
Marvin Abella
6,378 Pointsglad I helped =D goodluck!!
Marvin Abella
6,378 PointsGeorge you should pick the best answer so this would be labeled as answered.
Karthikeyan Palaniappan
5,271 PointsThanks Marvin, I too fell in this trap. The question is little tricky to understand.
Marvin Abella
6,378 PointsHonestly I had to re-watch the video a couple times to figure it out. It just takes test & trial, that's how we learn. Good luck on your ventures!
Adrian Durran
8,164 PointsI am having some issues with part 2 of this task....where it asks to set the last word in the array and then remove it from the array....
var spareWords = ["The","chimney","sweep's","dog"];
var saying = ["quick", "brown", "fox", "jumps", "over", "the", "lazy"];
var firstWord = spareWords[0];
sparewords.shift();
var lastWord = spareWords[2]; //as "The" has been shifted out??????
spareWords.pop();
Anybody got round this?
Jeff Busch
19,287 Points"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 way the question is worded you would` think Treehouse wants firstword to be added to the array, then removed from the array. It should say something like assign 'firstWord' the first value of the array 'spareWords' whilst simultaneously removing the first value from the array.
Andy Bradbury
Courses Plus Student 4,697 PointsAdding my name to the list and I agree, I did exactly the same and tried the following:
var firstWord = spareWords.unshift("firstWord");
Didn't work, so then:
var firstWord = spareWords.unshift("firstWord").shift(); (which also didn't work, obviously)
Then I finally Googled it and found this.
Inês Pinho
1,778 PointsThank's everyone. Once you get the first is the same on the rest... just "ignore" the first part of the task... i guess, cause it's confusing, i thought it was to add/take those words - 'fristWord', etc... - to the end/ beginning of the array :)
Kevin McNamara
4,171 Pointsvar firstWord = spareWords.shift();
loiclebunetel
4,184 PointsIt's still not reworded : (
Jonathan Musso
3,760 PointsI really struggled to understand this question...lol. Thanks for this thread.
Ben Schnell
14,763 PointsWow, agreeing with everyone above, this is a terribly worded question.
Marvin Abella
6,378 PointsMarvin Abella
6,378 PointsYou leave the parenthesis empty since its a default (0) it removes the first element in the array.
var firstWord = spareWords.shift(); dont forget the semi-colon, i had problems with this as well.