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 trialVan Young
15,136 Pointsadding item to variable
How do you add item to shipping variable? shipping,push won't work
var orderQueue = ['1XT567437','1U7857317','1I9222528'];
orderQueue.shift('1XT567437');
var shipping = [];
var shipping.push('1xt567437');
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
3 Answers
Steven Parker
231,236 PointsTheoretically, it could work, if you also removed the item needed from the array at the same time. But this challenge is expecting you to remove the item and assign it directly to the new variable.
So, without duplicating the contents of the array, what array method could you use to remove the first item and return its value?
Van Young
15,136 PointsThat's the shift function, which I used? I cant add object to variable with the push
Steven Parker
231,236 PointsNo, but you can assign the result of the "shift" to it. And "shift" does not take an argument.
Van Young
15,136 PointsI did it, nevermind. But it was seriously a lucky guess
Van Young
15,136 PointsVan Young
15,136 Pointsreturn function?
Steven Parker
231,236 PointsSteven Parker
231,236 Points"Return" is not a function, but a statement used inside a function to end it (and optionally return a specified value). You won't need to make a function for this challenge.
But the lesson introduced some array methods that take items out of an array and return their value. One of them takes the first item and the other takes the last. For task 1, the one that takes the first would be useful.