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 trialMaurice Tafolla- Cunningham
7,708 PointsJavaScript 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?
var orderQueue = ['1XT567437','1U7857317','1I9222528'];
var shipping = [];
shipping.push(orderQueue.shift());
<!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
31,603 PointsHey 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();
Per Karlsson
12,683 PointsHi 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!
Maurice Tafolla- Cunningham
7,708 PointsMaurice Tafolla- Cunningham
7,708 PointsA 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
31,603 PointsTobias Helmrich
31,603 PointsYes, 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.