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

Bob Sutherton
Bob Sutherton
20,160 Points

Array Methods shift/unshift CODE CHALLENGE (not sure what i'm doing wrong!)

So here is the link to the code challenge question.

https://teamtreehouse.com/library/websites/javascript-foundations/arrays/methods-part-1-elements

Here is my code:

<!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;
      var lastWord = spareWords;
      spareWords.unshift(firstWord);
      spareWords.shift(firstWord);
      saying;
      saying;
    </script>
  </body>
</html>

3 Answers

Bob Sutherton
Bob Sutherton
20,160 Points

Is it possible that there is a bug on this code challenge? It is giving me an error:

"Bummer! You're missing the shift method."

spareWords.shift(firstWord);
Sreng Hong
Sreng Hong
15,083 Points

Hi, James!!! There isn't a bug on this code challenge. You don't need to type firstWord in the bracket. <br /> The right answer is like this: <br />

var firstWord = spareWords.shift();

Sreng Hong
Sreng Hong
15,083 Points

method shift() means removes the first element of an array, and returns that element

Bob Sutherton
Bob Sutherton
20,160 Points

Thanks for your help, Sreng!

ilker senturk
ilker senturk
17,583 Points

var firstWord = spareWords; var lastWord = spareWords;

you need to get the first value of the array by adding shift() method

spareWords.shift();

Bob Sutherton
Bob Sutherton
20,160 Points

Thanks for your reply. When I try that, it doesn't work.