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

The orderQueue array contains a list of customer orders. Create a new variable named shipping -- remove the first item f

help me

script.js
var orderQueue = ['1XT567437','1U7857317','1I9222528'];
oderQueue.shift();
var shipping = ['1XT567437'];
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>

8 Answers

You are asked to remove the first item and simultaneously save it in your new variable called shipping. It should look like this:

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

I feel this question should be altered or taught in the last video on taking a value from the array and putting it into a string, I was unsure you could take the value and move it. least for newbies here :)

I agree they should have taught us how to insert the value into a new variable using this method. We learned how to remove and add to and from one variable only. I guess they were looking to see if our mind could wrap around the challenge but we can only implement what we have been taught. However I do love the course. Thanks

I agree.

I agree with you

You need simply create a variable with inside the action that you want to run.

Like this.

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

var shipping = orderQueue.shift();

thanks it worked

Correct - Answer

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

var shipping = orderQueue.shift(0);

my solution:

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

Thanks so much your cades has been working great for me so far, and I would suggest other to use your solutions.!

I don't understand how that would work.

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

var orderQueue = ['1XT567437','1U7857317','1I9222528']; // I understand this ok

orderQueue.shift(); // I understand this ok

var shipping = //how is the first item saved in shipping?

The .shift() not only removes the first the first item from the queue but also returns it, thus you can assign this return value to the variable.

The two comments above are correct, but you must watch your spelling as you have spelt order as oder. :)