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

Cynthia DiFabion
Cynthia DiFabion
3,801 Points

Challenge request is confusing. Several methods I have tried render different Bummer! results.

I have been getting results stating the 'firstWord' should be "The" when the request is to add the variable "firstWord" to the beginning and simultaneously remove it.

spareWord.unshift("firstWord"); spareWord.shift();

Then, it says method shift was not used. I have tried running this in console to see my mistake and it works fine but doesn't pass the challenge.

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>
Cynthia DiFabion
Cynthia DiFabion
3,801 Points

This is the challeng request: 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.

3 Answers

Cynthia DiFabion
Cynthia DiFabion
3,801 Points

I think I understand what you are doing... Basically swapping the first word "The" for "firstWord". That makes more sense! Thanks!

Hey Cynthia,

I've went through the entire challenge and here are the methods you need. Just go through them one by one so you get an understanding of each of them.

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.push(lastWord);
Cynthia DiFabion
Cynthia DiFabion
3,801 Points

The challenge request was confusing in that it stated simultaneously removing "it". It seemed as if I were to remove the variable I just added... which didn't make sense.