|
Wrong:
price = price - (price-discount_amount)
Right:
price = price-discount_amount;
Or, more succinctly:
price -= discount_amount;
By the same token, this code:
discount_amount = 0.10
price = price - (price*discount_amount)
Could be written:
discount_amount = 0.10;
price -= (price*discount_amount);
Or, even simpler,
discounted_rate = 0.90;
price *= discounted_rate;
Please be sure to put a semicolon at the end of every JavaScript statement.
No, it's not required. But there are a few cases where what YOU think is the end of the statement turns out not to be where JS thinks it is. Play it safe.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
|