Tell us what’s happening:
I’ve gotten stuck on this lesson for the last couple of days and I think it’s just coming down to not properly understanding the fundamentals. Just going to talk my code out loud for those of you to see what I’m thinking when attempting to solve it…
Problem is asking me to write a function that takes an array and a number and pass them as arguments. The array is composed of [1,2,3,4,5] and labeled as arr. The number is labeled as item.
So by typing “arr.push(item)” - I am selecting to view the parameter array and add the six to the end of the array?
Then by typing “arr.shift(item)” - I am selecting to remove the first value from the array group?
Then typing “return item;” is bringing back the values that just got solved for?
Your code so far
function nextInLine(arr, item) {
// Only change code below this line
arr.push(item);
arr.shift(item);
return item;
// Only change code above this line
}
// Setup
var 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/86.0.4240.111 Safari/537.36
.
Challenge: Stand in Line
Link to the challenge: