Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript I';我从JS开始,我可以';我不理解这个错误_Javascript - Fatal编程技术网

Javascript I';我从JS开始,我可以';我不理解这个错误

Javascript I';我从JS开始,我可以';我不理解这个错误,javascript,Javascript,我不明白,我把一个JS测试,告诉我,否则是无效的。 重要的是,请帮助尝试使用此标识查看,您将亲自了解问题所在: var slaying = true; var youHit = Math.floor(Math.random()*2);//Do not touch, DARK MAGIC var totalDamage = 0; while(slaying) { if(youHit) { console.log("Congrats you hitted the d

我不明白,我把一个JS测试,告诉我,否则是无效的。
重要的是,请帮助

尝试使用此标识查看,您将亲自了解问题所在:

var slaying = true;
var youHit = Math.floor(Math.random()*2);//Do not touch, DARK MAGIC
var totalDamage = 0;

while(slaying)
{
    if(youHit)
    {
        console.log("Congrats you hitted the dragon");
    totalDamage += damageThisRound;

   if (totalDamage >= 4)
   {
       console.log("You Win!");
       slaying = false;
       }
    }
       else
       {
       youHit = Math.floor(Math.random()*2);
       }

} else {
        console.log("You weren't able to hit the Dragon");
    var slaying = false;}
}
始终保持代码正确缩进,这样可以避免许多问题


顺便说一下:黑魔法部分随机选择0或1,这相当于真或假

我相信这就是你想要做的:

var-slaying=true;
var youHit=Math.floor(Math.random()*2)//不要碰,黑魔法
var totalDamage=0;
当(杀戮){
如果(你击中){
log(“恭喜你打了龙”);
总损伤+=本轮损伤;
如果(总损坏>=4){
log(“你赢了!”);
杀戮=虚假;
}否则{
youHit=Math.floor(Math.random()*2);
}否则{
log(“你打不到龙”);
var-slaying=false;
}
}

}
JS测试人员说了什么?检查花括号你的格式很糟糕,代码中有一个多余的大括号欢迎堆栈溢出!请看一下,仔细阅读,特别是“没有明确问题陈述的问题对其他读者没有用处。”“不要碰,黑魔法”哈哈哈,毫无疑问你真的是“从JS开始”
    var slaying = true;
    var youHit = Math.floor(Math.random()*2);//Do not touch, DARK MAGIC
    var totalDamage = 0;

    while(slaying) {
        if (youHit) {
            console.log("Congrats you hitted the dragon");
            totalDamage += damageThisRound;

            if (totalDamage >= 4) {
                console.log("You Win!");
                slaying = false;
            }
        } else {
            youHit = Math.floor(Math.random()*2);
        }

    } else {
        console.log("You weren't able to hit the Dragon");
        var slaying = false;
    }
}