我的脚本运行,但是当它到达 setTimeout 部分时,它只是不喜欢它:( 浏览器崩溃,我必须退出。浏览器是错误的还是我搞砸了?
var health=100;
var ehealth=100;
var atk;
var eatk;
function attack(x){
x=Math.floor(Math.random()*11);
atk=x;
ehealth=ehealth-atk
document.write('Enemy Health:' + ' ' + ehealth + ' ')
}
function eattack(x){
x=Math.floor(Math.random()*11);
eatk=x;
health=health-eatk
document.write('Health:' + ' ' + health )
}
function dead(){
if(health<=0){
document.write('You Lose');
}else{
if(ehealth<=0){
document.write('You Win');
}
}
}
function battle(){
document.write('Enemy Health:' + ' ' + ehealth + ' Health: ' + health + '<br/>\n')
while(health>=0&&ehealth>=0){
setTimeout(function(){
attack(0)
},400)
setTimeout(function(){
eattack(0)
},400)
document.write("<br/>\n");
dead();
}
}
我是什么做的 :(