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 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!