mercredi 28 juillet 2021

How to make variable equations inside conditionals work in jQuery?

I have been trying to make a tool that processes an input value via arithmetic equations depending on its value range.

After many iterations, being unable to declare variables within an if..else statement, and combing through online resources, I am completely stuck at the following, a bulky workaround which depends on having id'd every cell of the table I am outputting into.

Could there be any way I can make a sequence of formulas such as the ones at the bottom functional? Currently, the only part that works are the top three lines. Thank you so very much. (*゚ー゚)

  $('#submit').click(function(){
     
      var hc = $("#healthcare_cost").val();
      $("#cost2").text(hc);
      $("#cost").text(hc);

      var ai = $("#annual_income").val();
      var o = $("#0").val();
      var x = $("#25000").val();
      var xx = $("#50000").val();
      var xxx = $("#75000").val();
      var xxxx = $("#100000").val();
      var xxxxx = $("#200000").val();

      var yy = $("#3450").val();
      var yyy = $("#7695").val();
      var yyyy = $("#12275").val();
      var yyyyy = $("#33875").val();
    
        var xmr = $("#.138").val();
        var xxmr = $("#.169").val();
        var xxxmr = $("#.184").val();
        var xxxxmr = $("#.216").val();
        var xxxxxmr = $("#.246").val();
      
      if (ai<x){
          $("#mr").text(o);
          $("#tta").text((ai-o)*o+o);
          $("#er").text(((ai-o)*o+o)/ai);
          $("#yp").text(((ai-o)*o+o)*.2);
          $("#ner").text((((ai-o)*o+o)*.2)/ai);
      };
      
      else if (ai>=x && ai<xx){
            $("#mr").text(xmr);
          $("#tta").text((ai-x)*xmr+o);
          $("#er").text(((ai-x)*xmr+o)/ai);
          $("#yp").text(((ai-x)*xmr+o)*.2);
          $("#ner").text((((ai-x)*xmr+o)*.2)/ai);
  };
         else if (ai>=xx && ai<xxx){
            $("#mr").text(xxmr);
          $("#tta").text((ai-xx)*xxmr+y);
          $("#er").text(((ai-xx)*xxmr+y)/ai);
          $("#yp").text(((ai-xx)*xxmr+y)*.2);
          $("#ner").text((((ai-xx)*xxmr+y)*.2)/ai);
      };
         else (ai>=xx && ai<xxx){
            $("#mr").text(xxmr);
          $("#tta").text((ai-xx)*xxmr+y);
          $("#er").text(((ai-xx)*xxmr+y)/ai);
          $("#yp").text(((ai-xx)*xxmr+y)*.2);
          $("#ner").text((((ai-xx)*xxmr+y)*.2)/ai);
      };

});
});

Aucun commentaire:

Enregistrer un commentaire