Public
Edited
May 19
Fork of 1. Test
Insert cell
Insert cell
Insert cell
store = FileAttachment("fake_clothing_data2.json").json()
Insert cell
Insert cell
customer = ({
saldo: 50,
discount: 25,
size: 'L'
})
Insert cell
listOfProducts = []
Insert cell
miniStore = [
{id:"test-product", sold_out: false, with_discount: false, price: 80 }
]
Insert cell
miniStore.forEach( item =>{
if(item.sold_out ===false) {

console.log( '#### 1', item.with_discount===false )
console.log( '#### 2', item.price<=customer.saldo )
console.log( '#### 3', item.with_discount===false && item.price<=customer.saldo )
if(item.with_discount===false && item.price<=customer.saldo){
listOfProducts.push(item)
}
else {
const discountOfPrice =(item.price * customer.discount/100);
const priceWithDiscount = item.price - discountOfPrice;
console.log( '>> calculate discount: ', discountOfPrice, )
console.log( '>> calculate new price: ', priceWithDiscount )
console.log('------------------');
if(priceWithDiscount<=customer.saldo){
listOfProducts.push(item);
}
}
}
})
Insert cell
result = listOfProducts.map(item =>(
{ product:item.product,
originalPreis:item.price,
priceWithDiscount:item.price-item.price*customer.discount/100
}
)
)

Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more