Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Removing Items from an Array

Why isn't this working?

I'm not sure why I don't see the solution to this. Is it sleep deprivation? Too much coding? The glass of wine I have sitting next to me right now?

Whatever the reason, this simple challenge has stumped me. What am I doing wrong?

script.js
var orderQueue = ['1XT567437','1U7857317','1I9222528'];

var firstItem = orderQueue.shift();

var shipping = [firstItem];
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>

1 Answer

Robert Bennett
Robert Bennett
11,927 Points

test question answer.

var orderQueue = ['1XT567437','1U7857317','1I9222528'];
var shipping = orderQueue.shift();
var cancelled = orderQueue.pop();

Test Question BIG hint. on why it works...

The challenge is asking you to store the first item from the array into the shipping variable. You would use the .shift() method to do that. It returns the first value from the array. For example, say you had an array like this:

var a = [1,2,3];

And you want to get the first item from that array and store it in a variable named first. You'd do this:

var first = a.shift();

Thank you, Robert. That was so obvious, and yet it was not obvious to me last night, possibly due to the factors listed at the beginning of my question. Much appreciated!