Click here to Skip to main content
15,890,897 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to figure out what is wrong with this following code. The code searches for value in a table and assigns mxCost. The IF..ELSE condition works for all values except 1 and is also reading the table. The IF condition makes the page crash and i am not able to figure out why? Can someone please help me figure out what i am doing wrong here. Any help will be appreciated. Thank you.

What I have tried:

$jq("#airTableValues tbody tr").each(function() {
         var monthName  = months[parseInt(dateSplit[1])-1]+" "+dateSplit[0];
         if(monthName==$jq(this).find("td:eq(0)").text().trim())
          {
              mxCost = $jq(this).find("td:eq(6)").text().trim();
          }
      });
 
    if (mxCost)
      mxCost = (mxCost.substring(1, mxCost.length));
    else {
      mxCost = 0;
    }


  
    var MxStat = document.getElementById("MxStat").value;
    MxStat = MxStat/100;
    var InflationRate1 = document.getElementById("InflationRate1").value;
    InflationRate1 = InflationRate1/100;

    var rate3 = document.getElementById("rate3").value;
    rate3 =   Math.pow(1+rate3/100,1/365)-1;
    var mxAdj;
    if (MxStat == 1){
       mxAdj = mxCost;
    } //NOT WORKING!
    else (MxStat != 1) {
      var TotalCost = mxCost * 2; 
       mxAdj = (TotalCost * MxStat) - mxCost; 
    }


    var ReturnVal = (mxAdj * InflationRate1) + mxAdj;
    var ReturnCalc = ReturnVal * 1000000;
    var ReturnPV = Math.floor(ReturnCalc/Math.pow(1+rate3,periods));
    document.getElementById("ReturnCondition").value = 
    (ReturnPV/1000000).toFixed(2);
    ReturnCondition = ReturnVal.toFixed(2);
Posted
Updated 18-May-18 8:50am
v3

If you want to specify a condition, you need to use else if:
if (MxStat == 1){
   mxAdj = mxCost;
}
else if (MxStat != 1) {
   var TotalCost = mxCost * 2;
   mxAdj = (TotalCost * MxStat) - mxCost;
}


or simply:
if (MxStat == 1){
   mxAdj = mxCost;
}
else {
   var TotalCost = mxCost * 2;
   mxAdj = (TotalCost * MxStat) - mxCost;
}
 
Share this answer
 
Comments
Member 13289364 18-May-18 14:50pm    
Yes. I actually missed that while typing. But i tried that, it didn't work for me.
This worked for me.

if (MxStat != 1){
       var mxAdj = (TotalCost * MxStat) - mxCost;
       var ReturnVal = (mxAdj * InflationRate1) + mxAdj;
       aReturnCondition = ReturnVal.toFixed(2);
   }
   if (MxStat == 1){
       var mxAdj =  mxCost*InflationRate1;
       var ReturnVal = parseFloat(mxAdj + mxCost);
       aReturnCondition = parseFloat(ReturnVal).toFixed(2);
   }
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900