Welcome to Bank Ruptcy, and we want to hire you to fix our algorithm to exchange the stock options, because we have some weird behaviour.
This is our algorithm to exchange the stock options:
var stockOptionsCost = 10.70, paid = 20.80;
function calculateChange() {
return paid - stockOptionsCost;
}
function calculateAmountOfStockOptions () {
return paid / stockOptionsCost;
}
var amountStockOptions = calculateAmountOfStockOptions();
var yourChange = calculateChange();
1.94392523364486
**match_answer_and_solution**
10.100000000000001
**match_answer_and_solution**
Javascript has several problems operating with floating point, this is one of the causes that it should not be to operate with floats.
**match_answer_and_solution**
var stockOptionsCost = 10.70, paid = 20.80;
function calculateChange() {
return (paid - stockOptionsCost).toFixed(2);
}
function calculateAmountOfStockOptions () {
return paid / stockOptionsCost;
}
var amountStockOptions = calculateAmountOfStockOptions();
var yourChange = calculateChange();
assert(yourChange == 10.10);