Remove Item
Part of the Fundamentals section of Coddy's JavaScript journey — lesson 73 of 77.
Challenge
EasyNow, add a function named removeItem that gets a string (the item) and removes it from the list.
In the end, the function will output:
Milk removed from the grocery list.For the input "Milk".
And if the item does not exist in the list:
Milk is not in the grocery list.
Add the following code at the end of your code to test it (instead of the previous testing code):
addItem("Milk");
addItem("Bread");
addItem("Eggs");
removeItem("Bread");
removeItem("Cheese");Try it yourself
// Grocery list array
let groceryList = [];
// Function to add an item to the grocery list
function addItem(item) {
groceryList.push(item);
console.log(`${item} added to the grocery list.`);
}
addItem("Milk");
addItem("Bread");
addItem("Eggs");All lessons in Fundamentals
4Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Type Coercion7Bill Split Calculator
Welcome MessageCalculating The Tip And Total2Variables
NumbersStringBooleanNaming ConventionsEmpty VariablesRecap - Initialize VariablesConstants3Operators Part 1
Arithmetic OperatorsModulo OperatorArithmetic ShortcutsComparison OperatorsStrict vs Loose EqualityRecap - Simple Math6Basic IO
OutputOutput with VariablesType Conversion - Part 1Type Conversion - Part 2Recap - Till 120Recap - True or False