Search code examples
javascriptmathfinancial

Financial calculation with JavaScript (What´s wrong?)


I'm trying to make a financial calculation, but there's something wrong.

JS Code:

function count (){

var coda = 1.500;
var codb = 15;
var codc = 0.06;
var codx = 1;

var result = (codc/codx(codx-((codx+codc)*-codb)))*coda;

alert(result);


}

Message: undefined


Solution

  • You are missing a * operator, so the compiler tries to call codx as a function.

    To fix your computation, add the * operator as follow:

    function count (){
    
        var coda = 1.500;
        var codb = 15;
        var codc = 0.06;
        var codx = 1;
    
        var result = (codc/codx * (codx - ((codx+codc)*-codb)))*coda;
        //                      ^
    
        alert(result);
    }