javascript - how to calculate the number to increment the variable -
how can calculate missing number, when add variable result equal or greater other variable.
- promoter: 10
- detractor: 2
- total: 12
- average: 66.67
- target: 75
- you need ??? promoters reach target.
i want find how many promoters need if average less target. how can calculate missing number when add promoter results of average equal or greater target.
thank you!
function missingnum() { var xpromoter = ''; var x = 10; var y = 2; var target = 75; var z = x + y; var v = ((x - y) / z) * 100; average = math.round(v * 100) / 100; if (average<target) //how increment x average => target document.write("promoter:" + "\n" + x + "<br>"); document.write("detractor:" + "\n" + y + "<br>" ); document.write("total:" + "\n" + z + "<br>" ); document.write("average:" + "\n" + average + "<br>" ); document.write("target:" + "\n" + target + "<br>" ); document.write("you need " + "\n" + xpromoter + "promoters reach target." ); }
you make simple function.. calculation might better..
function calculateneededpromoters (promo, detrac) { var percentage = 0.00; var currentpromo = promo; while (percentage < 75) { currentpromo++; var total = currentpromo + detrac; var v = ((currentpromo - detrac) / total) * 100; percentage = math.round(v * 100) / 100; } return currentpromo; }
Comments
Post a Comment