function returning NaN failing to perform the calculation

0

In a solar calculator, everything works, minus the final value that returns NaN. Where is my error?

function calcular(valorInformado) {

    ResultPotencia = parseFloat(valorInformado * 8.28 / 1000).toFixed(2);

    ResultModulos = parseInt(ResultPotencia * 8.28 / 1000);

    ResultArea = parseFloat(ResultModulos * 2);

    Result1 = parseFloat(11 * ResultPotencia * 0.85 * 1000).toFixed(3);

    Result2 = parseFloat(11 * ResultPotencia * 1.10 * 1000).toFixed(3);



    var elemResult = document.getElementById("resultadopotencia");
    elemResult.innerText = " " + ResultPotencia + " KWp" ;

    var elemResult = document.getElementById("resultadomodulos");
    elemResult.innerText = " " + parseInt(ResultPotencia * 1000 / 265) + " Módulos"; 

    var elemResult = document.getElementById("resultadometros");
    elemResult.innerText = " " + (ResultPotencia * 1000 / 265 * 2).toFixed(1) + " M²"; 

    var elemResult = document.getElementById("valorsistema");
    elemResult.innerText = " " + (ResultIntermediario * ResultPotencia * 0.85 * 1000).toFixed(2).formatMoney();

    var elemResult = document.getElementById("valorsistema2");
    elemResult.innerText = " " + (ResultIntermediario * ResultPotencia * 1.10 * 1000).toFixed(2).formatMoney();

}

ResultIntermediario = function() {
    var ResultIntermediario = this;

    if(ResultPotencia <= 3)
    ResultIntermediario = 11;

    if(ResultPotencia >= 3)
    ResultIntermediario = 9;

}
    
asked by anonymous 21.10.2016 / 03:26

1 answer

0

Well I managed to find the errors, refactored the code to debug it in the browser, you committed a simple misunderstanding in the function:

ResultIntermediario = function() {
var ResultIntermediario = this;

if(ResultPotencia <= 3)
ResultIntermediario = 11;

if(ResultPotencia >= 3)
ResultIntermediario = 9;}

You did not specify any parameters and no returns, so at the time of calculation you got NaN, which is the reference for null. I modified it as follows:

ResultIntermediario = function(ResultPotencia) {

if(ResultPotencia <= 3) return 11 * ResultPotencia;

if(ResultPotencia >= 3) return 9 * ResultPotencia;}

Now it gets a parameter and returns a value * o Result of power (I saw that you had used the function * result power in Inner HTML and figured this out.)

function calcular(valorInformado) {

ResultPotencia = parseFloat(valorInformado * 8.28 / 1000).toFixed(2);

ResultModulos = parseInt(ResultPotencia * 8.28 / 1000);

ResultArea = parseFloat(ResultModulos * 2);

Result1 = parseFloat(11 * ResultPotencia * 0.85 * 1000).toFixed(3);

Result2 = parseFloat(11 * ResultPotencia * 1.10 * 1000).toFixed(3);

var elemResult = document.getElementById("resultadopotencia");
console.log(ResultPotencia + " KWp" );

var elemResult = document.getElementById("resultadomodulos");
console.log(parseInt(ResultPotencia * 1000 / 265) + " Módulos"); 

var elemResult = document.getElementById("resultadometros");
console.log((ResultPotencia * 1000 / 265 * 2).toFixed(1) + " M²"); 

var elemResult = document.getElementById("valorsistema");
console.log((ResultIntermediario(ResultPotencia) * 0.85 * 1000));

var elemResult = document.getElementById("valorsistema2");
console.log(ResultIntermediario(ResultPotencia) * 1.10 * 1000);}
    
21.10.2016 / 04:05