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 trial

JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Removing Items from an Array

Christian George
Christian George
8,738 Points

Why 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.

script.js
var orderQueue = ['1XT567437','1U7857317','1I9222528'];
var shipping =[];

shipping.unshift(orderQueue[0]);
orderQueue.shift();
index.html
<!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
Gunhoo Yoon
5,027 Points

The 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.

  1. Way too verbose
  2. Returns wrong data type.

Here's my explanation.

  1. 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()] 
  1. 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ć
Vedran Brnjetić
6,004 Points

you 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