这是我的输入:
var slaying = true;
var youHit = Math.floor(Math.random()*2);
var damageThisRound = Math.floor(Math.random()*5 + 1);
var totalDamage = 0;
while (slaying){
if(youHit){
console.log("You hit!");
}
else{
console.log("You missed!");
}
slaying = false;
}
我的出局:
You hit!
false
我需要知道从哪里来的这个"假"在我出来的话?我知道我输出的第一行。我也清楚你的伤害和伤害这个圆形的功能。我只是想知道它是如何在执行时工作的。
答案 0 :(得分:0)
当您在控制台中运行脚本时,while include会显示布尔值,就像放置
时一样var foo = 'bar';
你的结果将是未定义的。
但是在您的网页中,您将无法获得结果。