我正在寻找一个用javascript编写的公式修复的方法

我正在寻找一个用javascript编写的公式修复的方法,javascript,html,css,Javascript,Html,Css,基本上,我有一个我正在制作的网站,它是通用回形针的一个衍生产品,它叫橡皮夹。当然,在这个过程中,你需要找到一个像样的公式来计算购买你的橡皮筋的人的数量对公众利益的增长。因此,公众利益越高,就有越多的人购买你的橡皮筋 我有一个公式,我正在使用,但它是非常主观和有缺陷的,再加上它不工作,如果你的公众利益超过800%。下面是我使用的100毫秒间隔的公式 setInterval (function() { if (publicinterest < 100) { i

基本上,我有一个我正在制作的网站,它是通用回形针的一个衍生产品,它叫橡皮夹。当然,在这个过程中,你需要找到一个像样的公式来计算购买你的橡皮筋的人的数量对公众利益的增长。因此,公众利益越高,就有越多的人购买你的橡皮筋

我有一个公式,我正在使用,但它是非常主观和有缺陷的,再加上它不工作,如果你的公众利益超过800%。下面是我使用的100毫秒间隔的公式

 setInterval (function() {
       if (publicinterest < 100) {
         if (Math.random() < publicinterest / 200) {
           if (Math.random() < publicinterest / 200) {
             if (unsoldrubberbands > 0) {
               money += sellingprice; 
               publicinterest = publicinterestdecider / 
sellingprice;  
                 unsoldrubberbands -= 1; 
                 document.getElementById('moneytext').innerHTML = 
'Money: $' + money.toFixed(2); 
               document.getElementById('inventory').innerHTML = 
'Inventory: ' + unsoldrubberbands;
               document.getElementById('publicinterest').innerHTML = 
"Public Interest " + publicinterest.toFixed(1) + '%';
           }
         }
       }
     }
   if (publicinterest < 200) {
       if (Math.random() * 2 < publicinterest / 190) {
         if (Math.random() * 2 < publicinterest / 190) {
           if (unsoldrubberbands > 0) {
             money += sellingprice; 
             publicinterest = publicinterestdecider / sellingprice;
             unsoldrubberbands -= 1; 
             document.getElementById('moneytext').innerHTML = 'Money: $' + money.toFixed(2); 
             document.getElementById('inventory').innerHTML = 'Inventory: ' + unsoldrubberbands;
             document.getElementById('publicinterest').innerHTML = "Public Interest " + publicinterest.toFixed(1) + '%';
         }
       }
     }
   }

   if (publicinterest < 300) {
       if (Math.random() * 3 < publicinterest / 180) {
         if (Math.random() * 3 < publicinterest / 180) {
           if (unsoldrubberbands > 0) {
             money += sellingprice; 
             publicinterest = publicinterestdecider / sellingprice;
             unsoldrubberbands -= 1; 
             document.getElementById('moneytext').innerHTML = 'Money: $' + money.toFixed(2); 
             document.getElementById('inventory').innerHTML = 'Inventory: ' + unsoldrubberbands;
             document.getElementById('publicinterest').innerHTML = "Public Interest " + publicinterest.toFixed(1) + '%';
         }
       }
     }
   }

   if (publicinterest < 400) {
       if (Math.random() * 4 < publicinterest / 170) {
         if (Math.random() * 4 < publicinterest / 170) {
           if (unsoldrubberbands > 0) {
             money += sellingprice; 
             publicinterest = publicinterestdecider / sellingprice;
             unsoldrubberbands -= 1; 
             document.getElementById('moneytext').innerHTML = 'Money: $' + money.toFixed(2); 
             document.getElementById('inventory').innerHTML = 'Inventory: ' + unsoldrubberbands;
             document.getElementById('publicinterest').innerHTML = "Public Interest " + publicinterest.toFixed(1) + '%';
         }
       }
     }
   }

   if (publicinterest < 500) {
       if (Math.random() * 5 < publicinterest / 160) {
         if (Math.random() * 5 < publicinterest / 160) {
           if (unsoldrubberbands > 0) {
             money += sellingprice; 
             publicinterest = publicinterestdecider / sellingprice;
             unsoldrubberbands -= 1; 
             document.getElementById('moneytext').innerHTML = 'Money: $' + money.toFixed(2); 
             document.getElementById('inventory').innerHTML = 'Inventory: ' + unsoldrubberbands;
             document.getElementById('publicinterest').innerHTML = "Public Interest " + publicinterest.toFixed(1) + '%';
         }
       }
     }
   }

   if (publicinterest < 600) {
       if (Math.random() * 6 < publicinterest / 150) {
         if (Math.random() * 6 < publicinterest / 150) {
           if (unsoldrubberbands > 0) {
             money += sellingprice; 
             publicinterest = publicinterestdecider / sellingprice;
             unsoldrubberbands -= 1; 
             document.getElementById('moneytext').innerHTML = 'Money: $' + money.toFixed(2); 
             document.getElementById('inventory').innerHTML = 'Inventory: ' + unsoldrubberbands;
             document.getElementById('publicinterest').innerHTML = "Public Interest " + publicinterest.toFixed(1) + '%';
         }
       }
     }
   }

   if (publicinterest < 700) {
       if (Math.random() * 7 < publicinterest / 140) {
         if (Math.random() * 7 < publicinterest / 140) {
           if (unsoldrubberbands > 0) {
             money += sellingprice; 
             publicinterest = publicinterestdecider / sellingprice;
             unsoldrubberbands -= 1; 
             document.getElementById('moneytext').innerHTML = 'Money: $' + money.toFixed(2); 
             document.getElementById('inventory').innerHTML = 'Inventory: ' + unsoldrubberbands;
             document.getElementById('publicinterest').innerHTML = "Public Interest " + publicinterest.toFixed(1) + '%';
         }
       }
     }
   }

   if (publicinterest < 800) {
       if (Math.random() * 8 < publicinterest / 130) {
         if (Math.random() * 8 < publicinterest / 130) {

           if (unsoldrubberbands > 0) {
             money += sellingprice; 
             publicinterest = publicinterestdecider / sellingprice;
             unsoldrubberbands -= 1; 
             document.getElementById('moneytext').innerHTML = 'Money: $' +   money.toFixed(2); 
             document.getElementById('inventory').innerHTML = 'Inventory: ' + unsoldrubberbands;
             document.getElementById('publicinterest').innerHTML = "Public Interest " + publicinterest.toFixed(1) + '%';
         }
       }
     }
   }
     //console.log('sellingpriceint', sellingprice);
     //console.log('publicinterestint', publicinterest);
     //console.log('rubberbandsint', rubberbands)


 },100)
setInterval(函数(){
如果(公共利益<100){
if(Math.random()0){
货币+=销售价格;
公共利益=公共利益决策者/
销售价格;
未焊透的焊盘-=1;
document.getElementById('moneytext')。innerHTML=
‘Money:$’+Money.toFixed(2);
document.getElementById('inventory')。innerHTML=
“库存:”+未售出的Drubberband;
document.getElementById('publicinterest')。innerHTML=
"公众利益"加"公众利益.toFixed(1)加"百分比";;
}
}
}
}
如果(公共利益<200){
if(Math.random()*2<公共利益/190){
if(Math.random()*2<公共利益/190){
如果(未清除的DrubberBands>0){
货币+=销售价格;
公共利益=公共利益决策者/销售价格;
未焊透的焊盘-=1;
document.getElementById('moneytext').innerHTML='Money:$'+Money.toFixed(2);
document.getElementById('inventory')。innerHTML='inventory:'+未售出的DrubberBands;
document.getElementById('publicinterest').innerHTML=“Public Interest”+publicinterest.toFixed(1)+'%';
}
}
}
}
如果(公共利益<300){
if(Math.random()*3<公共利益/180){
if(Math.random()*3<公共利益/180){
如果(未清除的DrubberBands>0){
货币+=销售价格;
公共利益=公共利益决策者/销售价格;
未焊透的焊盘-=1;
document.getElementById('moneytext').innerHTML='Money:$'+Money.toFixed(2);
document.getElementById('inventory')。innerHTML='inventory:'+未售出的DrubberBands;
document.getElementById('publicinterest').innerHTML=“Public Interest”+publicinterest.toFixed(1)+'%';
}
}
}
}
如果(公共利益<400){
if(Math.random()*40){
货币+=销售价格;
公共利益=公共利益决策者/销售价格;
未焊透的焊盘-=1;
document.getElementById('moneytext').innerHTML='Money:$'+Money.toFixed(2);
document.getElementById('inventory')。innerHTML='inventory:'+未售出的DrubberBands;
document.getElementById('publicinterest').innerHTML=“Public Interest”+publicinterest.toFixed(1)+'%';
}
}
}
}
如果(公共利益<500){
if(Math.random()*5<公共利益/160){
if(Math.random()*5<公共利益/160){
如果(未清除的DrubberBands>0){
货币+=销售价格;
公共利益=公共利益决策者/销售价格;
未焊透的焊盘-=1;
document.getElementById('moneytext').innerHTML='Money:$'+Money.toFixed(2);
document.getElementById('inventory')。innerHTML='inventory:'+未售出的DrubberBands;
document.getElementById('publicinterest').innerHTML=“Public Interest”+publicinterest.toFixed(1)+'%';
}
}
}
}
如果(公共利益<600){
if(Math.random()*60){
货币+=销售价格;
公共利益=公共利益决策者/销售价格;
未焊透的焊盘-=1;
document.getElementById('moneytext').innerHTML='Money:$'+Money.toFixed(2);
document.getElementById('inventory')。innerHTML='inventory:'+未售出的DrubberBands;
document.getElementById('publicinterest').innerHTML=“Public Interest”+publicinterest.toFixed(1)+'%';
}
}
}
}
如果(公共利益<700){
if(Math.random()*7<公共利益/140){
if(Math.random()*7<公共利益/140){
如果(未清除的DrubberBands>0){
货币+=销售价格;
公共利益=公共利益决策者/销售价格;
未焊透的焊盘-=1;
document.getElementById('moneytext').innerHTML='Money:$'+Money.toFixed(2);
document.getElementById('inventory')。innerHTML='inventory:'+未售出的DrubberBands;
document.getElementById('publicinterest').innerHTML=“Public Interest”+publicinterest.toFixed(1)+'%';
}
}
}
}
如果(公共利益<800){
if(Math.random()*8<公共利益/130){
if(Math.random()*8<公共利益/130){
如果(未清除的DrubberBands>0){
货币+=销售价格;
公共利益=公共利益决策者/销售价格;
未焊透的焊盘-=1;
document.getElementById('moneytext').innerHTML='Money:$'+Money.toFixed(2);
document.getElementById('inventory')。innerHTML='inventory:'+未售出的DrubberBands;
document.getElementById('publicinterest')。innerHTML=“Public Interest”+publicinterest
setInterval (function() {
    if (publicinterest < 100) {
        if (Math.random() < publicinterest / 200) {
            if (Math.random() < publicinterest / 200) {
                if (unsoldrubberbands > 0) {
                    money += sellingprice; 
                    publicinterest = publicinterestdecider / sellingprice;  
                    unsoldrubberbands -= 1; 
                    document.getElementById('moneytext').innerHTML = 'Money: $' + money.toFixed(2); 
                    document.getElementById('inventory').innerHTML = 'Inventory: ' + unsoldrubberbands;
                    document.getElementById('publicinterest').innerHTML = "Public Interest " + publicinterest.toFixed(1) + '%';
                }
            }
        }
    }

    for(var loop = 0; loop < 7; loop++){
        if(
            publicinterest < loop * 100 + 200
            &&
            Math.random() + (loop + 2) < publicinterest / (190 - 10 * loop)
            &&
            Math.random() + (loop + 2) < publicinterest / (190 - 10 * loop)
            &&
            unsoldrubberbands > 0
        ) {
             money += sellingprice; 
             publicinterest = publicinterestdecider / sellingprice;
             unsoldrubberbands -= 1; 
             document.getElementById('moneytext').innerHTML = 'Money: $' + money.toFixed(2); 
             document.getElementById('inventory').innerHTML = 'Inventory: ' + unsoldrubberbands;
             document.getElementById('publicinterest').innerHTML = "Public Interest " + publicinterest.toFixed(1) + '%';
        }
    }

},100)