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? vat20 : 20vat); // 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.
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? vat : 20); // 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.
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.
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) {
var sum = price1 + price2;
vat = (vat === undefined? vat : 20); // give vat a default value if none exists.empty
return ((sumprice1 *+ vatprice2) * 100) / 100;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.
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) {
var sum = price1 + price2;
vat = (vat === undefined? vat : 20); // give vat a default value if none exists.
return ((sum * vat) * 100) / 100;
}
document.write(getTotalPrice(4, 3));
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? vat : 20); // 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.
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) {
var sum = price1 + price2;
vat = (vat === undefined? vat : 20); // give vat a default value if none exists.
return ((sum * vat) * 100) / 100;
}
document.write(getTotalPrice(4, 3));