由于某种原因,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
的工具不要使用全局变量,现在不帮你,但它将在未来 –