// Array of products, each product is an object with different fieldset // A set of ingredients should be added to products var filtered = []; var products = [ { name: "broccoli", vegetarian: true, glutenFree: true, organic: true, price: 1.99, productImg: "images/broccoli.png", Fruits: false, Dairy: false, Vegetables: true, Pantry: false, Bakery: false, MeatandSeafood: false }, { name: "bread", vegetarian: true, glutenFree: false, organic: false, price: 2.35, productImg: "images/bread.png", Fruits: false, Dairy: false, Vegetables: false, Pantry: false, Bakery: true, MeatandSeafood: false }, { name: "salmon", vegetarian: false, glutenFree: true, organic: false, price: 10.00, productImg: "images/salmon.png", Fruits: false, Dairy: false, Vegetables: false, Pantry: false, Bakery: false, MeatandSeafood: true }, { name: "carrot", vegetarian: true, glutenFree: true, organic: true, price: 2.63, productImg: "images/carrot.png", Fruits: false, Dairy: false, Vegetables: true, Pantry: false, Bakery: false, MeatandSeafood: false }, { name: "chicken", vegetarian: false, glutenFree: true, organic: false, price: 6.87, productImg: "images/chicken.png", Fruits: false, Dairy: false, Vegetables: false, Pantry: false, Bakery: false, MeatandSeafood: true }, { name: "cereal", vegetarian: false, glutenFree: false, organic: false, price: 2.97, productImg: "images/cereal.png", Fruits: false, Dairy: false, Vegetables: false, Pantry: true, Bakery: false, MeatandSeafood: false }, { name: "cheese", vegetarian: true, glutenFree: false, organic: false, price: 5.14, productImg: "images/cheese.png", Fruits: false, Dairy: true, Vegetables: false, Pantry: false, Bakery: false, MeatandSeafood: false }, { name: "white fish", vegetarian: false, glutenFree: true, organic: false, price: 13.50, productImg: "images/white-fish.png", Fruits: false, Dairy: false, Vegetables: false, Pantry: false, Bakery: false, MeatandSeafood: true }, { name: "honey", vegetarian: false, glutenFree: false, organic: true, price: 1.89, productImg: "images/honey.png", Fruits: false, Dairy: false, Vegetables: false, Pantry: true, Bakery: false, MeatandSeafood: false }, { name: "onion", vegetarian: true, glutenFree: true, organic: true, price: 2.22, productImg: "images/onion.png", Fruits: false, Dairy: false, Vegetables: true, Pantry: false, Bakery: false, MeatandSeafood: false } ]; products.sort(function(a, b) { return a.price - b.price; }) function getProductImg(productName) { var prodVal = products.find(prod => prod.name === productName); return prodVal.productImg; } // given restrictions provided, make a reduced list of products // prices should be included in this list, as well as a sort based on price function restrictListProducts(prods, restriction) { let product_names = []; for (let i=0; i prod1.name === prod[i]); console.log("test", prodVal); if ( filter === "Fruits" && prodVal.Fruits === true ) { prod_filter.push(prodVal.name); } else if ( filter === "Vegetables" && prodVal.Vegetables === true ) { prod_filter.push(prodVal.name); } else if ( filter === "Pantry" && prodVal.Pantry === true ) { prod_filter.push(prodVal.name); } else if ( filter === "Dairy" && prodVal.Dairy === true) { prod_filter.push(prodVal.name); } else if ( filter === "Meat&Seafood" && prodVal.MeatandSeafood === true) { prod_filter.push(prodVal.name); } else if ( filter === "Bakery" && prodVal.Bakery === true) { prod_filter.push(prodVal.name); } else if ( filter === "" ){ prod_filter.push(prodVal.name); } } return prod_filter; } // Calculate the total price of items, with received parameter being a list of products function getTotalPrice(chosenProducts) { var totalPrice = 0; for (let i=0; i -1){ totalPrice += products[i].price; } } return totalPrice; } function getItemPrice(chosenProduct){ for (let i=0; i -1){ return products[i].price; } } }