Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

See edit note. "Condition? ifTrue : IfFalse" was used incorrectly.
Source Link

Issues:

  1. Vat is unused as an argument, and even if it were used it would always be reinitialized in your code and assigned a value of 20.
  2. priceb was 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:

  1. Vat is unused as an argument, and even if it were used it would always be reinitialized in your code and assigned a value of 20.
  2. priceb was 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:

  1. Vat is unused as an argument, and even if it were used it would always be reinitialized in your code and assigned a value of 20.
  2. priceb was 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.

added 154 characters in body
Source Link
brymck
  • 7.7k
  • 30
  • 32

Issues:

  1. Vat is unused as an argument, and even if it were used it would always be reinitialized in your code and assigned a value of 20.
  2. priceb was 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:

  1. Vat is unused as an argument, and even if it were used it would always be reinitialized in your code and assigned a value of 20.
  2. priceb was 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:

  1. Vat is unused as an argument, and even if it were used it would always be reinitialized in your code and assigned a value of 20.
  2. priceb was 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.

Source Link
brymck
  • 7.7k
  • 30
  • 32

Issues:

  1. Vat is unused as an argument, and even if it were used it would always be reinitialized in your code and assigned a value of 20.
  2. priceb was 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));
lang-js

AltStyle によって変換されたページ (->オリジナル) /