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 trialChris Harkin
1,104 PointsRemoving 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
9,979 PointsHi 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
Courses Plus Student 1,513 Pointsvar orderQueue = ['1XT567437','1U7857317','1I9222528']; var shipping = orderQueue.shift();
// this one should work
Michał Biajgo
Full Stack JavaScript Techdegree Student 1,223 Pointsvar orderQueue = ['1XT567437','1U7857317','1I9222528']; var shipping = []; shipping.push(orderQueue.shift());
Is not working. Why
Ethan Rivas
9,979 PointsYou'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();
Adrian Dancau
20,633 PointsThis is the correct solution!
const orderQueue = ['1XT567437','1U7857317','1I9222528'];
var shipping = orderQueue.shift(); // Challenge Task 1
var cancelled = orderQueue.pop(); // Challenge Task 2
Gelawdios Ejigu
7,029 Pointsvar orderQueue = ['1XT567437','1U7857317','1I9222528']; orderQueue.shift('1XT567437'); var shipping = '1XT567437';
frontend
15,619 PointsTry using the shift method on the variable itself rather than calling it in the global namespace.
Michał Biajgo
Full Stack JavaScript Techdegree Student 1,223 Pointsbut my example should also result in the same output
vincent batteast
51,094 PointsI 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.