lundi 14 juin 2021

if/else statement in Javascript with multiple intervals

I am having trouble creating an if/else statement with multiple variables which must match some threshold values and numerical intervals.

Here are the variables (they are numerical values entered by user through input fields with specific id-s):

var ValoareaGlicemiei = parseInt(document.getElementById("glicemiavalue").value);
var ValoareaGlicozilata = parseInt(document.getElementById("glicozilata").value);
var ValoareaGlicozilata1 = parseInt(document.getElementById("glicozilata1").value);
var ValoareaTTOG0h = parseInt(document.getElementById("0h").value);
var ValoareaTTOG2h = parseInt(document.getElementById("2h").value);    
  • ValoareaGlicemiei must be between 109 – 125;
  • ValoareaGlicozilata must be between 6 – 6.4;
  • ValoareaGlicozilata1 must be < 6;
  • ValoareaTTOG0h must be < 109;
  • ValoareaTTOG2h must be < 140;

All conditions must be validated before the PreDiabet function executes!

if/else statements in Javascript with the conditions below are not working!

if (ValoareaTTOG0h < 109 && 
    ValoareaTTOG2h < 140 && 
    ValoareaGlicozilata1 <= 6.0 && 
     (ValoareaGlicemiei >= 109 && ValoareaGlicemiei <= 125) && 
     (ValoareaGlicozilata > 6 && ValoareaGlicozilata <= 6.4) 
) {PreDiabet();}
else {somecode}

or

if ( (ValoareaGlicemiei >= 109 && ValoareaGlicemiei <= 125) && 
     (ValoareaGlicozilata > 6 && ValoareaGlicozilata <= 6.4) && 
      ValoareaTTOG0h < 109 && 
      ValoareaTTOG2h < 140 && 
      ValoareaGlicozilata1 <= 6.0 &&  ) 
       {PreDiabet();}
else {somecode}

What is wrong here with these conditions?

Aucun commentaire:

Enregistrer un commentaire