doesItHit
및 doTheyHit
은 항상 실행되는 것처럼 보이지만 dealDamage
은 전역 변수에 아무런 영향을주지 않습니다.코드가 전역 변수를 업데이트하지 않는 것처럼 보입니다.
var hitPercentage=Math.floor(Math.random() * 101) + 1
function doesItHit(){
if(toHit * hitPercentage >= enemyEvasion){itHits = true}
else("You miss.")
}
function doTheyHit(){
if(enemyToHit * (Math.floor(Math.random() * 101) + 1) >= evasion){enemyToHit = true}}
function dealDamage(){enemyHealth= enemyHealth-lasers;}
function recieveDamage(){health= health - enemyLasers;}
function playerTurn(){
doesItHit();
if (itHits===true){
dealDamage()
console.log("You deal "+ lasers + " points of damage to the enemy.")
lasersFired=false
}
}
사용 세미콜론을! [JSHint] (http://www.jshint.com/)와 같은 도구를 사용하십시오. – epascarello
전역을 사용하지 마십시오. 지금은 도움이되지 않지만 앞으로는 유용 할 것입니다. –