lundi 21 mai 2018

Javascript Else If Statement is not evaluating second condition?

I'm making a medical calculator and am wondering why the first "else if" statement is not being evaluated. - What I'm trying to do is calculate "if the initialPTT is greater than or equal to 40 AND the bodyweight is over 250, then display "1000 Maximum Dose Reached." It seems to be just doing the calculation on line on the first "if" statement and the first "else if" statement.

<script type="text/javascript">
function calculate()
{
  bodyWeight = document.getElementById("bodyWeight").value;
  initialPTT = document.getElementById("initialPTT").value;

  document.getElementById("resultInfusionUnitsHr").innerHTML = bodyWeight * initialPTT;

  // Start Infusion Units/Hr
  if(initialPTT <= 40){
    document.getElementById("resultInfusionUnitsHr").innerHTML = bodyWeight * 4;
  } else if ((initialPTT <=40) && (bodyWeight > 250)){
    resultInfusionUnitsHr = "1000 Maximum Dose Reached";
  } else if ((initialPTT <=40) && (initialPTT < 51)){
    document.getElementById("resultInfusionUnitsHr").innerHTML = bodyWeight * 2;  
  } else if ((initialPTT <=40) && (initialPTT < 51) && (bodyWeight > 500)){
    document.getElementById("resultInfusionUnitsHr").innerHTML = "1000 Maximum Dose Reached";  
  } else {
    document.getElementById("resultInfusionUnitsHr").innerHTML = bodyWeight * 2;
  }

}

See it on CodePen

Aucun commentaire:

Enregistrer un commentaire