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

Michael Hicks
Michael Hicks
24,208 Points

Choice of words in this exercise is confusing

"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."

Below is the correct answer, but goodness, maybe use a different name for the the value of var firstWord!

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

2 Answers

If the variable firstWord is going to hold the first word of something, it seems logical to me. Reading the sentence out loud sounds a bit crazy, I'll admit, but I guess the code itself should be somewhat self-explanatory...

Perhaps you could make some suggestions though? I know the Treehouse staff and mods are all over these forums and might take your feedback into account, but it's always helpful to propose alternatives when suggesting something should be changed.

Michael Hicks
Michael Hicks
24,208 Points

I agree with you. Sometimes learning can be a frustrating experience and I'm glad there's a community of people like you to help with the journey. I think my confusion was with the way 'firstWord' was used interchangeably as a variable with the string 'The" in the array 'spareWords'. It seems trivial, but I had trouble understanding. I would suggest phrasing it as such:

On line 18, use a method on 'spareWords' to set the variable 'firstWord' to the 'spareWords' array whilst simultaneously removing the first value from the beginning of the array.

The variable firstWord isn't set to the spareWords array, it's set to the returned value of the shift() method of that array, which results in the string "The".

I guess maybe they could ask for the first 'item' or value in the array, rather than the first 'word'?

Michael Hicks
Michael Hicks
24,208 Points

Yes, I think asking for 'the first value' in the array rather than 'firstWord' would make it clear that the variable firstWord isn't set to the spareWords array, but instead the string 'The' within the spareWords array.