나는이 스크립트를 학습용으로 사용하고 있습니다. 이 코드에서, 버튼을 클릭 할 때마다 여러 개의 코드가 실행되도록 시도하고 있습니다. 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>
무엇이 문제입니까? 또한 function declarations에는() 함수가 필요합니다 (예 : function redStam() {} – cernunnos
서식을 편집하기 시작했으나 구문 오류가 너무 많아서 더 잘 만들 수 있을지 잘 모르겠습니다. OP 코드를 올바르게 들여 쓰기하고 구문 적으로 유효한 코드를 게시하는지 확인하십시오. – BLSully
그냥 게시물에 문제를 추가했습니다. 내 함수에서() 내 코드를 변경했지만 코드가 여전히 작동하지 않습니다. –