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

My first task is not passing again..

I think I'm getting the code right but something is making the first task not pass...

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

4 Answers

unshift is a method, it's called on an array, and you pass whatever you're unshifting as a parameter:

saying.unshift(firstWord);

There's no reason to assign this to a variable.

Also a little tip, whenever a challenge already has some code that you should expand on (on a particular line), usually you don't need to add anything in front of that code, you just need to add to it.

Okay, thank-you!

Adama Sy
Adama Sy
7,076 Points

@Dewi what did you do to resolve it?

Thank you

Hello! I don't remember the exact question but it's what Dino was saying from above:

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

So it should add the word firstWord in the beginning...