vendredi 22 mai 2015

Strange behavior on JavaScript Function

I'm working on JavaScript code to get the string of the correct image to show but is not working, I'get an empty string on the las console log.

function jsmBatteryLevelIMG(lvl)
{
var icono ="";
      console.log(lvl);

       if(lvl < 3.60) {
           icono= "/track/images/Batt000.png";
           console.log("000");
       } 
       else if(lvl <= 3.60) {
           console.log("025");
           icono= "/track/images/Batt025.png";
       }
console.log(icono); //<---Empty string ???
return icono;
};

But if I do

function jsmBatteryLevelIMG(lvl)
{
    var icono ="";
    console.log(lvl);
    icono= "/track/images/Batt025.png";
    console.log(icono); //<---Not empty string ???
    return icono;
};

it works OK.

What I'm missing?

Aucun commentaire:

Enregistrer un commentaire