I am looking at this assignment, and my question is about the part in bold at the end:
// Do not edit the code below. var myGroceryList = ['chips', 'pizza', 'hotpockets', 'MtnDew', 'corndogs']; // Do not edit the code above.
Here we're going to write a function that mimics going shopping and checking things off of our grocery list and adding new items to our list.
Write a function called removeItem that is given two arguments, the first is
myGroceryList
, and the second is an item to remove frommyGroceryList
. If the second argument (or the item to add or remove) matches an item inmyGroceryList
, remove that item from the your grocery list and return the new, updated grocery list.Once you do that, write another function called
addItem
that is given two arguments, the first ismyGroceryList
and the second is an item to add to your grocery list. InaddItem
add the item you passed in tomyGroceryList
then return the new, updated grocery list.In both removeItem and addItem check to see if the 'myGroceryList' and 'item' arguments are truthy. If they are not, return an empty array.
Here are some examples of calling your functions and what should be returned:
removeItem(myGroceryList, 'chips') --> ['pizza', 'hotpockets', 'MtnDew', 'corndogs']; addItem(myGroceryList, 'Jerky') --> ['pizza', 'hotpockets', 'MtnDew', 'corndogs', 'Jerky']; removeItem(myGroceryList) --> []; addItem() --> [];
Here is my code:
removeItem=(myGroceryList,item)=>{
return myGroceryList.filter((thing)=>{
return thing != item
})
}
addItem=(myGroceryList, item)=>{
myGroceryList.push(item);
return myGroceryList;
}
How can I get the final step of this to work?