Hi all,
I’m very new to the coding world. And I’m having trouble with the following task in javascript. Think I’ve got the first bit right. But obviously not all. Any help really appreciated. thanks.
“Write a function nextInLine
which takes an array ( arr
) and a number ( item
) as arguments.
Add the number to the end of the array, then remove the first element of the array.
The nextInLine
function should then return the element that was removed.”
I’m getting the following errors:
nextInLine([], 1) should return 1
After nextInLine(testArr, 10), testArr[4] should be 10
// tests completed ```
Any help or ideas welcome.
```js
function nextInLine(arr, item) {
// Your code here
arr.push(6);
return arr.shift();
}
// Test Setup
var testArr = [1,2,3,4,5];
// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 10)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));