3 of 3
See edit note. "Condition? ifTrue : IfFalse" was used incorrectly.
Issues:
Vatis unused as an argument, and even if it were used it would always be reinitialized in your code and assigned a value of 20.pricebwas a typo.
Beyond that the code doesn't seem to have any evident problems.
function getTotalPrice(price1, price2, vat) {
vat = (vat === undefined? 20 : vat); // give vat a default value if empty
return (price1 + price2) * vat;
}
document.write(getTotalPrice(4, 3));
Edit: Per the comment below, which is true, I figured I should just go ahead and simplify the math here. If the asker has a different equation in mind he should probably explain a bit more.
Edit: (vat === undefined? 20 : vat) is correct, producing any value other than undefined, default 20. (vat === undefined? vat : 20) will only produce undefined or 20.
brymck
- 7.7k
- 30
- 32