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

Lance Volk
seal-mask
.a{fill-rule:evenodd;}techdegree
Lance Volk
Full Stack JavaScript Techdegree Student 1,628 Points

My code checks out in the console, but it says I didn't pass the challenge, both arrays check out.

When checking the arrays, shipping and orderQueue in the console, they are as they were asked to be. Am I missing something? I have removed the first item from the orderQueue array and put it into the shipping array.

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

3 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! The brackets around the orderQueue.shift(); are unnecessary. Try removing those and give it another go. Hope this helps! :sparkles:

Lance Volk
seal-mask
.a{fill-rule:evenodd;}techdegree
Lance Volk
Full Stack JavaScript Techdegree Student 1,628 Points

Thanks Jennifer, I thought that arrays always had to be in brackets, it still worked, but I'm all for less code. Thanks again, Lance

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Right, except that shipping isn't an array. Shipping is holding an element that you shifted out of an array. The shift method is used directly on the array :smiley:

If you had wanted to add it to an array named shipping then you could chain a shift and a push to push it into a new array.

Lance Volk
seal-mask
.a{fill-rule:evenodd;}techdegree
Lance Volk
Full Stack JavaScript Techdegree Student 1,628 Points

My mistake Jennifer, I thought I was creating another array called shipping instead of just a variable. Thanks for the clarification. Lance