development-ib-fork/web/10/eigene_loesungen/Aufgabe_02.js

32 lines
748 B
JavaScript

let products = [
{ "produkt": "Joghurt", "preis": 2.49 },
{ "produkt": "Brot", "preis": 3.29 },
{ "produkt": "Käse", "preis": 8.99 },
{ "produkt": "Duschgel","preis": 2.79 }
]
let reduced_products = []
const discound_and_round = price => Math.floor(price*0.9*10**2+0.5)/10**2 //price*0.9.toFixed(2) is not working!
for(product of products){
const new_product = new Map()
new_product.set("produkt",product.produkt)
new_product.set("preis", discound_and_round(product.preis))
reduced_products.push(new_product)
}
console.log("Normale Preise:")
for(product of products){
console.log(product)
}
console.log("\n")
console.log("Reduzierte Preise:")
for(product of reduced_products){
console.log(product)
}