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 trialNatalia Ninou
Front End Web Development Techdegree Student 8,203 PointsThe array assigned to the variable orderQueue contains a list of order numbers. Declare a new variable named shipping. R
The array assigned to the variable orderQueue contains a list of order numbers. Declare a new variable named shipping...
const orderQueue = ['1XT567437','1U7857317','1I9222528'];
const shipping = [0]
orderQueue.shift();
3 Answers
Cameron Childres
11,820 PointsHi Natalia,
Your code uses const to assign shipping
to an array and then separately removes the first element of orderQueue
with shift(). Using const locks the shipping
variable in to referencing the array [0] you've created, so you won't be able to reassign it to something else. We need to remove the first element '1XT567437' from orderQueue
and assign it to shipping
(as a string, not an array).
Since the shift() method removes the first element of an array and also returns that element, you can accomplish the goals here with one line:
const orderQueue = ['1XT567437','1U7857317','1I9222528'];
var shipping = orderQueue.shift();
// shipping is now equal to '1XT567437'
The first element of orderQueue
will be removed and assigned directly to the variable shipping
.
Hope this helps! Let me know if you have any questions.
Alana Warson
5,296 PointsWhy did the instructor not lecture that "var shipping" is how we are to create the variable shipping?
Cameron Childres
11,820 PointsLet me rephrase -- you can use const
, let
, or var
here. The issue is that you didn't assign the first element of the array to the variable. This also passes the task:
const orderQueue = ['1XT567437','1U7857317','1I9222528'];
const shipping = orderQueue.shift();
The important part is that orderQueue.shift()
is assigned to shipping
. This is accomplished by declaring the variable and setting it equal to (or assigning it to) orderQueue.shift()
.
Didier Pham
7,175 Pointslooks more like const shipping now has the action of taking out the element But wasn't actually given the element otherwise wouldn't your agree that adding an element is suppose to be unshift and Not shift...there's no way anyone could have guessed this lol.