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

balraj sarai
balraj sarai
6,303 Points

task 3 and 4

I am having an issue answering task 3 and 4,

<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; saying; </script>

Every time I do as it asks it comes up with an issue that task one is no longer present.

it says add a variable firstWord to the saying array,so I add... var firstWord = saying;

then there's an issue with task one.

i then revert to just writing, saying.unshift();

because there is an error saying I have no added the unshift method or the variable firstWord to it.

but in task 3 there is nothing telling me to add a unshift method.

someone please help.

1 Answer

Balraj,

What you're doing is setting the variable firstWord to equal the array saying;

> var firstWord = saying;  // sets firstWord to equal to the saying array
> console.log(firstWord);
["quick", "brown", "fox", "jumps", "over", "the", "lazy"]

This is why task 1 is no longer passing, because the firstWord variable no longer equals the last element of the spareWords array.

What you need to do is call a method on the saying array that will add the firstWord variable at the front of the array and then in the challenge after that you need to call a method to add the lastWord variable to the end of the array. the error is telling you that you have not added the unshift method to saying.

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;

That code will get you past the 3rd challenge. See if you can figure out the method you need for the 4th.

-Luke