const animationData = [
animationData.push({
inputVal: 2,
marginTop: -200,
addElDelay: 1500
})
This LIFO array already has 1 element and the best method to add the next one is to ‘push’ it onto the stack.
The instruction given is: “Treat your animationData
array as a stack and add a new object to it.”
Hi there!
You have modified your array. Reset the challenge step and just add a new object with required key/value pairs. It’s a simple object addition challenge.
The solution mentioned by @hasanzaib1389 is one correct answer.
Your solution by using .push()
method is accepted as another correct answer.
But you used it inside the array definition, which is invalid.
Reset your challenge to restore the array to its original value and add your push()
statement after the array.
Yeah @Biter! You can also add it by using .push()
method and adding the new object to it By calling the push method on that array outside of that array.
Hi,
I’m not able to use push, my code fails if I try. So, shouldn’t the array be the same as we made it several steps back?
The challenge is passing for me with push method and also with simple object addition. You may have accidentally modified your other code. Reset the challenge step and try again.
EDIT: if your code didn’t passed, then post your updated code here.
Hi - again,
If we do a const animationData = ;
each time the code runs, the array is reset, right?
So, I’ll need to comment out that code line?!?
Or, leave it and do all the new value/pairs in a single section maybe a function.
I put the 2 items together and that passes, but when there are many of them having to edit the main file many times seems bulky. But I can live with that: “All-in-one and one-in-all.”
That is a declaration of animationData
variable an assignment of an empty array. When this code run, you will see an empty array within the console. Try to log that variable and check it.