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 Arrays

Chris Harkin
Chris Harkin
1,104 Points

Removing items from arrays Challenge Task 1

Hi can can any one help am stuck on the first challenge question for this video.

"Challenge Task 1 of 2

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. "

The error am getting

Bummer! It doesn't look like you stored the first item from the array in the shipping variable.

My Code.

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

8 Answers

Ethan Rivas
Ethan Rivas
9,979 Points

Hi Chris Harkin!

The challenge:

1) The orderQueue array contains a list of customer orders.

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

2) Create a new variable named shipping

var shipping;

3) Remove the first item from the array and place it in the shipping variable.

  • Here is where you have the error, you're passing nothing to the shift function, and you're not even saving it inside the shipping variable:
orderQueue.shift();
  • This is how you save the first item of the list inside the shipping varible. You're passing to the shift function the index 0 (which represents the first item in the array).
var shipping = orderQueue.shift([0]);

I hope this helps you to understand the challenge :)

Aine Reed
PLUS
Aine Reed
Courses Plus Student 1,513 Points

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

// this one should work

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

Is not working. Why

Ethan Rivas
Ethan Rivas
9,979 Points

You're doing it outside the variable, just declare the shipping variable and use the method shift for the orderQueue array inside of it like:

var shipping = orderQueue.shift();

This is the correct solution!

const orderQueue = ['1XT567437','1U7857317','1I9222528'];
var shipping = orderQueue.shift(); // Challenge Task 1
var cancelled = orderQueue.pop(); // Challenge Task 2

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

Try using the shift method on the variable itself rather than calling it in the global namespace.

but my example should also result in the same output

vincent batteast
vincent batteast
38,047 Points

I try this and for some reason it didn't work. var hold = orderQueue.shift(); var shipping = [hold];

But I think this should work var shipping = [orderQueue.shift()]; Because shift return a value.