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

Problem with the challenge task

This is the challenge task 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.

and this is my code

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

and this is the error

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

tnx

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

2 Answers

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 Points

They want the shipping variable to end up as just the string value, not another array with an item in it. Also, the shift() function returns that value that it's removing, so you can just use the result of that and assign it to shipping.

var orderQueue = ['1XT567437','1U7857317','1I9222528'];
var shipping = orderQueue.shift();
Kelsea Anderson
Kelsea Anderson
12,632 Points

Hi Ljiljana,

The challenge wants you to remove the first item in the array and store it in the variable in one step. Instead of pushing the value to shipping, you can reference the index in shift() - like this:

var shipping = orderQueue.shift([0]);

Hope that helps!