Can't pass, someone can assist me

Tell us what’s happening:
Describe your issue in detail here.

   **Your code so far**
function nextInLine(arr, item) {
 // Only change code below this line
 arr.push()
 
arr.shift(),arr.shift(),arr.shift(),arr.shift(),arr.shift()

 return item;
 

 // Only change code above this line

}

// Setup
const testArr = [1, 2, 3, 4, 5];

// Display code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6));
console.log("After: " + JSON.stringify(testArr));
   **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36 Edg/102.0.1245.33

Challenge: Stand in Line

Link to the challenge:

You might want to review the section on how push works here.

And you don’t want to remove everything from the array, just the first item. And you want to return that removed item from the function. You should end up with [2,3,4,5,6] in the console logs at the bottom.

Tell us what’s happening:
Describe your issue in detail here.

   **Your code so far**
function nextInLine(arr, item) {
 // Only change code below this line
 arr.push(2)
 
arr.shift(),arr.shift(),arr.shift(),arr.shift(),arr.shift(),arr.unshift;

 return item;
 

 // Only change code above this line

}

// Setup
const testArr = [1, 2, 3, 4, 5];

// Display code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6));
console.log("After: " + JSON.stringify(testArr));
   **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36 Edg/102.0.1245.33

Challenge: Stand in Line

Link to the challenge:

arr.push(2)

is addding 2 to the end of the array. You are asked to add item and not 2.

To understand better the shift function, open developer tools and look at what this code does:

const result=arr.shift()
console.log(result)

DearT.:
1.i also can’t understand your meaning :“is addding 2 to the end of the array. You are asked to add item and not 2.” ? At the “arr.push(2)” the “2” inside is 2 items or a number? if is items its number are "6"and “7”? if is number the queue is:[1,2,3,4,5,2]?
2. a.nextInLine([], 5) should return a number.

b.nextInLine([], 1) should return 1

c.nextInLine([2], 1) should return 2

d.nextInLine([5,6,7,8,9], 1) should return 5

e.After nextInLine(testArr, 10), testArr[4] should be 10
What are the" a-e" 's meaning?

the function has two parameters, arr and item. arr will be an array, and item will be a number. You need to use both of them in the function for it to work properly. They are asking you to add the parameter item to the end of arr, then remove the first element from arr and return that removed element. If you use arr.push(2) the function will always add the number 2 to arr, which makes the function not very flexible.

Open developer tools. In firefox, press Shift/Ctrl/k. In Edge or Chrome, press Shift/Ctrl/j
Click on Console
Paste this code in the console:

const arr=[0,1, 0]
console.log("arr at first: ",arr)
let res
res=arr.push(2)
console.log("arr.push(2): ", res)
console.log("arr final: ", arr)

Press return

Finally, google:
what does js push() return
what does js shift() return

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.