我有这个脚本,我把它用作学习的东西。在此代码中,我试图拥有它,以便每次单击按钮时,它将运行多个代码。比如每次它会失去 1 点体力,改变 3 件事中的 1 件(金钱、体力或健康),然后更新屏幕上的数字。不幸的是..我的号码没有更新。我以前只调用一个函数就可以运行这个程序,但现在我有多个,它会导致问题。
<html>
<head>
<script>
var stam=100;
var cash=0;
var health=100;
var rNumber=Math.random();
function explore(){ //2<- This function gets called and runs two functions
if(stam>1){
redStam();
refresh();
//<-- will add a function to use a random number later to decide whether health, money or stamina gets changed.
};
else{alert("You have no stamina")}}
function refresh(){ //3<-This function gets called, which refreshes the current variables
document.getElementById('number').innerHTML=stam;
};
function redStam(){ //3<This function also gets called.
stam--;
};
</script>
<button onclick="explore()">Explore</button> 1<- button gets clicked
</head>
<body>
<p id='number'>100</P>
</body>
</html>