001window.onload = ()=>{
002
003
004
005
006
007 const getFullPrice = function (sugarTax, vat) {
008 return this.price +
009 (this.sugar?sugarTax:0) +
010 (this.price / 100 * vat);
011 }
012
013
014 const cokeOriginal = {
015 price: .60,
016 sugar: true
017 };
018
019
020 const cokeZero = {
021 price: .60,
022 sugar: false
023 };
024
025
026 const taxes = [.08, 20];
027
028
029 const cokeOTotal = getFullPrice.apply(cokeOriginal, taxes);
030 const cokeZTotal = getFullPrice.apply(cokeZero, taxes);
031
032
033 console.log('Coke Original £'+ cokeOTotal.toFixed(2));
034 console.log('Coke Zero £'+ cokeZTotal.toFixed(2));
035
036}