i have this array two functions one adds to it the other one takes away from it or at least thats the plan. can someone look at my code and see whats wrong with my second function. splice is taking my last element on array but not the specific one that am trying to get. please
var shoppingCart = [];
function AddtoCart(name, description, price) {
// JavaScript Object that holds three properties : Name,Description and Price
var singleProduct = {};
//Fill the product object with data
singleProduct.Name = name;
singleProduct.Description = description;
singleProduct.Price = price;
//Add newly created product to our shopping cart
shoppingCart.push(singleProduct);
//call display function to show on screen
}
function removefromCart(name, description, price) {
// JavaScript Object that will hold three properties : Name,Description and Price
var singleProduct = {};
//Fill the product object with data
singleProduct.Name = name;
singleProduct.Description = description;
singleProduct.Price = price;
var index = shoppingCart.indexOf(singleProduct);
shoppingCart.splice(index, 1);
}