scrimba
Note at 0:15
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Note at 0:15
AboutCommentsNotes
Note at 0:15
Expand for more info
index.js
run
preview
console
import { products }  from "./data.js";

/*
It's the day after Halloween 🎃 and all the candy is on sale!

To buy up all the candy, use map() and filter() to put all the
candy into a `shoppingCart` array.

The new array should contain only the item and the price, like
this:

Expected output:
[
{item: "🍭", price: 2.99},
{item: "🍫", price: 1.99},
{item: "🍬", price: 0.89}
]
*/

// console.log(products[0]);
// console.log(products[0].item);
// console.log(products[0].price);
// console.log(Object.keys(products[0]));

const filterProducts = products.filter(product => product.type === "sweet");
// console.log(filterProducts);
const mapProducts = products.map(product => ({item: product.item, price: product.price}));
// console.log(mapProducts);
// console.log(Object.keys(mapProducts[0]));
const chain = products.filter(product => product.type === "sweet").map(product => ({item: product.item, price: product.price}));
// console.log(chain);


function getSaleItems(products){

const shoppingCart = products.filter(product => product.type === "sweet").map(product =>({item: product.item, price: product.price}));

return shoppingCart;
};
console.log(getSaleItems(products));
Console
[
{item:
"🍭"
, price:
2.99
}
,
{item:
"🍫"
, price:
1.99
}
,
{item:
"🍬"
, price:
0.89
}
]
,
/index.html
LIVE