Javascript Challenges

Floats Operations Imprecision

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();

Exercise

Correct!
False!

What returns calculateAmountOfStockOptions ?

Exercise

Correct!
False!

What is the value of calculateChange ? Input the number value.

Exercise

Correct!
False!

Why?

Exercise

Correct!
False!

Please fix this code to return the correct change.

var stockOptionsCost = 10.70, paid = 20.80; function calculateChange() { return paid - stockOptionsCost; } function calculateAmountOfStockOptions () { return paid / stockOptionsCost; } var amountStockOptions = calculateAmountOfStockOptions(); var yourChange = calculateChange();