forked from WEB-IB-SS26/development-ib
implemented the 2nd js code exercise
parent
b54903697b
commit
051d7fad01
|
|
@ -0,0 +1,31 @@
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Reference in New Issue