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

Cory Wallace
Cory Wallace
14,005 Points

this isn't working

At first, I tried creating the shipping variable, then removing the first integer from the orderQueue array via .shift, and pushing it into the shipping array via .shift. Well, that didn't work, I kept getting an error indicating that I hadn't stored the array. Now I've done what's in the photo below, it works in the java console AND COMPLETES THE TASK, yet I get an error indicating that I must call the shipping var using the var keyword.

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

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

this seemed to work for me

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,858 Points

Hi Cory,

Challenges are very specific and very picky. Task #1 is looking for the variable shipping to be holding the first value from the array, so you need to have the shift method attached to the variable assignment.

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

Make sense?

Keep coding! :dizzy:

Cory Wallace
Cory Wallace
14,005 Points

after reading this, I finally realized what my error was. I kept trying to return the results of the first array, by creating an array with the stored shifted information. My problem is that I consistently over think Java, and it's biting me in the hind quarters. Thank you so very much, you just killed a week long struggle for me