9jat
March 7, 2018, 7:27pm
1
Tell us what’s happening:
Your code so far
function nextInLine(arr, item) {
// Your code here
var remove = arr.push(item);
return remove.shift(); // Change this line
}
// Test Setup
var testArr = [1,2,3,4,5];
// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
**Link to the challenge:**
https://www.freecodecamp.org/challenges/stand-in-line
1 Like
What is the value of remove
?
1 Like
9jat
March 7, 2018, 7:45pm
3
arr.push(item); I give this value
9jat
March 7, 2018, 7:45pm
4
function nextInLine(arr, item) {
// Your code here
var remove = arr.push(item);
I see you code. What is the actual value of remove
after that operation. Test it using the console.
1 Like
9jat
March 7, 2018, 8:04pm
6
It gives me an error, I don’t understood what I was doing wrong.
I’m trying to help you see where the error is coming from. Try using console.log()
to look at what the value of remove
is.
9jat
March 7, 2018, 8:11pm
8
function nextInLine(arr, item) {
// Your code here
var remove = arr.push(item);
return remove.shift();
}
console.log(nextInLine([1, 2, 3], 7));
I use this code, but again error
I know. I’ve seen it every time you’ve posted it.
9jat
March 7, 2018, 8:13pm
10
Ok can you do this and tell me what is wrong please
I’ve told you what you need to do as a first step to debug the problem. Look at what the value of remove
is after var remove = arr.push(item);
.
9jat
March 7, 2018, 8:15pm
12
How I can do this tell me
Use a console.log
statement after that line and look at the console.
Either you don’t have a correctly written console.log
statement in the right place, or you aren’t looking at the right console.
9jat
March 7, 2018, 8:22pm
16
Please I stuck on that verify it for me please
You are assigning remove
the value returned by arr.push(item)
. What does the .push()
function return?
If it doesn’t return anything, then remove
is undefined. .shift()
is an array function. You can’t shift an undefined value.
(But it does return something.)
9jat
March 7, 2018, 8:29pm
20
Why it returns me nothing when I use push
I gave as a parameter an array