gpt4 book ai didi

javascript - 外卖系统为什么不能用

转载 作者:行者123 更新时间:2023-12-03 05:00:18 24 4
gpt4 key购买 nike

我尝试开发一款游戏,但系统并不总是有效(它测试你是否有足够的金币)。我无法理解它,它只有时适用于较大的数字,但不适用于所有。代码如下:

<!--- Game Of War: Ice Age -->

<!DOCTYPE html>
<html>
<head>
<title>Game Of War: Ice Age</title>
</head>
<h4 id="gold"></h4>
<!-- Gain Gold -->
<img src="file:///C:/Users/Hacker/Pictures/GOW%20-%20Ice%20Age/goldButton.png" height="50" style="border: solid; 5px; black;" width="50" onclick="gainGold()"></img>

<!-- Barracks -->
<img src="file:///C:/Users/Hacker/Pictures/GOW%20-%20Ice%20Age/barracks.png" height="50" style="border: solid; 5px; black;" width="50" onclick="training()"></img>
<body>
<script type="text/javascript">
var gold = 1000000;
var goldPC = 1;

<!-- Troop Training Variables -->
var mammothCost = 5;
var dinosaurCost = 100;
var mammoths = 0;

function gainGold(){
gold += goldPC;

}

function training(){
train = prompt("Train Troops!")
if (train == "Mammoths") {
alert("Train Mammoths")
amount = prompt("How Many Mammoths Do You Want To Train?")
takeaway = mammothCost * amount;
if (gold - takeaway <= 0){
alert("You Do Not Have Enough Gold!")
training()
}
mammoths = amount += mammoths

gold -= takeaway


}
}

<!-- SetIntervalSettings -->

setInterval(function renderGold (){
document.getElementById('gold').innerHTML = "Gold: " + gold;
});


</script>

</body>
</html>

最佳答案

我的猜测是 prompt() 函数返回一个字符串,这会混淆接下来的数学。通过 parseInt() 运行结果将返回一个整数。

Javascript 在自动变量类型转换方面非常挑剔。

关于javascript - 外卖系统为什么不能用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42257604/

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