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

Ranjen Naidu
Ranjen Naidu
2,474 Points

I am having prob with Array > method part 1 exercise

I already put it correctly as above but it showing me the error as below : Can anyone assist me where i did wrong and how to fix it ?

index.html
<!DOCTYPE html>
<html lang="en">
  <head>
    <title> JavaScript Foundations: Arrays</title>
    <style>
      html {
        background: #FAFAFA;
        font-family: sans-serif;
      }
    </style>
  </head>
  <body>
    <h1>JavaScript Foundations</h1>
    <h2>Arrays: Methods Part 1</h2>
    <script>
      var spareWords = ["The","chimney","sweep's","dog"];
      var saying = ["quick", "brown", "fox", "jumps", "over", "the", "lazy"];
      var firstWord = spareWords.unshift("firstWord");
      spareWords.shift();
      var lastWord = spareWords;
      saying;
      saying;
    </script>
  </body>
</html>

4 Answers

Hi Ranjen,

I had the same problem and then figured it out with trial and error. Try re-wording the challenge question to something like this:

"On line 18, remove the first word from the spareWords array and store that value into the variable firstWord."

Can you figure it out from here?

Ranjen Naidu
Ranjen Naidu
2,474 Points

Hi Robert thans for the help but still haven't fixed it. Did you mean like this ?

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

Hint: You don't need to unshift anything.

Ranjen Naidu
Ranjen Naidu
2,474 Points

Ok i fixed it with this :

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

Thanks Robert :)

Ranjen Naidu
Ranjen Naidu
2,474 Points

Yes you are right Robert , actually the answer is just this line :

var firstWord = spareWords.unshift("firstWord");

Thanks again :)