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

What is the answer?

What is the answer of this question?

script.js
var orderQueue = ['1XT567437','1U7857317','1I9222528'];
orderQueue.shift(0);
var shipping = [orderQueue.push(0, 1)];
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

Tealium Solutions, I looked over the challenge.

The first part reads as follows:

The orderQueue array contains a list of customer orders. Create a new variable named shipping 
-- remove the first item from the array and place it in the shipping variable.

So, let's create this shipping variable:

var shipping;

Okay, now that we have created a shipping variable, let's remove the first item from the array. Now, before we remove the first item, let's think, "Is there an available method that can remove the first item?"

Yes. shift()

So, let's add that.

var shipping = orderQueue.shift();

Sweet. Now we are at task two, which reads as follows:

Now create a new variable named cancelled. Remove the last item from the orderQueue 
array and store it in the variable cancelled. Use the array method you 
learned in the last video for this challenge.

Okay, we used the shift method to pass the first task. Let's ask ourselves, "If I am able to remove the first item, can I remove the last item?"

Yes, part II. pop()

So, let's add that.

var cancelled = orderQueue.pop();

Boom! You should pass.

If you ever get stuck on a challenge, feel free to reach out.

Never Stop Learning