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 an Array

Maurice Tafolla- Cunningham
Maurice Tafolla- Cunningham
7,708 Points

JavaScript Loops, Arrays, and Objects - Challenge 4 not passing

I get an error telling me "that it doesn't look like you called the .shift() method on orderQueue. Try using orderQueue.shift()."

Check out my code:

Clearly I am, unless I'm daft. What's up? My task it to put the first item from orderQueue into the shipping variable. Also I don't know why there is a HTML file attached with this. Sorry?

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

Tobias Helmrich
Tobias Helmrich
31,601 Points

Hey Maurice,

actually your idea was really good because if there are more items shipping at the same time it would be useful to have an array for that. However in this challenge shipping should just be a variable where you store the removed first item from the orderQueue array.

It should work like this:

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

// Task 1
var shipping = orderQueue.shift();

// Task 2
var cancelled = orderQueue.pop();
Maurice Tafolla- Cunningham
Maurice Tafolla- Cunningham
7,708 Points

A minute or so later I solved the lab in the same fashion above. But I think that this challenge should be more specific in how they want it solved. Both sets of code work; furthermore, as I mentioned in my question the hint given states "it doesn't look like you called the .shift() method", which in my case it was clearly used, and I think that can be confusing for someone solving this challenge.

Tobias Helmrich
Tobias Helmrich
31,601 Points

Yes, I agree with you on that. However Treehouse can only check one answer - in this case they're probably checking the shipping variable - and they can't predict every possible way the student may approach to solve the problem. When it comes to developing there is almost always more than one way to solve a problem so I absolutely agree with you that both sets of code work. However here on Treehouse it's also important to look out for small keywords like "variable" or "array" in the challenge's description.

Per Karlsson
Per Karlsson
12,683 Points

Hi Maurice,

You want to save the first value in the array into the variable shipping. shift() removes the first item in an arrays.

So try this out:

var shipping = your shift goes here.

Let me know if you need more help.

Good luck!