gpt4 book ai didi

javascript - 我正在寻找我在 javascript 中制作的公式的修复

转载 作者:太空宇宙 更新时间:2023-11-04 06:19:35 24 4
gpt4 key购买 nike

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

我有一个正在使用的公式,但它非常主观且有缺陷,而且如果您的公众利益超过 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)

此代码描述了 4 个变量。公众利益是指根据销售额的高低来增加销售额的事件。售价是您出售橡皮筋的金额,因此价格越低,公众利益就越高。 publicinterestdecider,基本上是 margin 以及我将如何通过升级来增加公众利益。而未售出的橡皮筋只是库存。钱是不言自明的。所以我真正想要的是一个更好的公式,它会根据公众利益成倍地发挥作用,并且无论公众利益是什么都有效。 (请记住,公众利益本身只是一个数字,但在显示器上我在它旁边添加了一个百分比符号)

最佳答案

这里有一种方法可以使您的大部分代码可重用:

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)

我不确定您是否希望每个间隔运行代码 7 次,但如果是这样,就可以了。

关于javascript - 我正在寻找我在 javascript 中制作的公式的修复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55622009/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com