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 trialanitap
5,372 PointsI pasted this in the Chrome console and it worked. I don't understand why the program says the value is not stored.
var orderQueue = ['1XT567437','1U7857317','1I9222528']; var shipping = []; shipping.push('1XT567437'); orderQueue.shift('1XT567437'); "1XT567437"
shipping; ["1XT567437"] orderQueue; ["1U7857317", "1I9222528"]
var orderQueue = ['1XT567437','1U7857317','1I9222528'];
var shipping = [];
shipping.push('1XT567437');
orderQueue.shift('1XT567437');
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
2 Answers
Marcus Parsons
15,719 PointsHi Anita,
The reason you're seeing an error is that you're using static values to push
and shift
between arrays. The simplest method (which is also the most dynamic) is to simply set the shipping
variable equal to the result of calling the shift
method on orderQueue
. The reason for this is that calling shift
on an array returns an array that has had the first item removed and so shipping
will be the orderQueue
array with the first item removed.
var orderQueue = ['1XT567437','1U7857317','1I9222528'];
var shipping = orderQueue.shift();
anitap
5,372 PointsThank you!
Marcus Parsons
15,719 PointsYou are very welcome, Anita! Happy Coding!