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 trialChristian George
8,738 PointsWhy dosen't it works? I don't understand. I check my work in console develop tool, and there it's return right value.
Why dosen't it works? I don't understand. I check my work in console develop tool, and there it's return right value.
var orderQueue = ['1XT567437','1U7857317','1I9222528'];
var shipping =[];
shipping.unshift(orderQueue[0]);
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
Gunhoo Yoon
5,027 PointsThe task is to remove first item in the Queue and assign it to var shipping.
While you answer technically isn't wrong. The grader have tendency to only accept what it knows. This includes using unneeded function calls and etc...
Your code differs from what grader asks you in two ways.
- Way too verbose
- Returns wrong data type.
Here's my explanation.
- Your code can be simplified.
var orderQueue = ['1XT567437','1U7857317','1I9222528'];
var shipping = orderQueue.shift();
What your trying to do can also be simplified
var orderQueue = ['1XT567437','1U7857317','1I9222528'];
var shipping = Array(orderQueue.shift())
//or
var shipping = [orderQueue.shift()]
- Grader probably expects shipping variable to have string type while yours have array type. Since you literally created an empty array and appended element to it. While shift() function returns first item of list as it is.
Vedran Brnjetić
6,004 Pointsyou are supposed to use .shift() method on orderQueue to set the shipping vriable:
var orderQueue = ['1XT567437','1U7857317','1I9222528'];
var shipping = orderQueue.shift();
Hope this helps
Christian George
8,738 PointsChristian George
8,738 PointsThank you for your help!