Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/461.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 如果语句发生更改,则提示符不会通知_Javascript_If Statement_Prompt - Fatal编程技术网

Javascript 如果语句发生更改,则提示符不会通知

Javascript 如果语句发生更改,则提示符不会通知,javascript,if-statement,prompt,Javascript,If Statement,Prompt,请帮忙。当使用console.log语句运行代码时,它会在提示符snd中输入数字,然后单独记录答案,return语句显然无效 prompt("You begin to move but as you evade most of the bullets some of them hit your " + bodyPart + " you begin to feel the blood shushing out, As people realize what happened th

请帮忙。当使用console.log语句运行代码时,它会在提示符snd中输入数字,然后单独记录答案,return语句显然无效

prompt("You begin to move but as you evade most of the bullets some of them hit your " +          bodyPart + " you begin to feel the blood shushing out, As people realize what happened there begins to be chaos. You look at the direction of the bullets to find 3 guys with heavy weaponry. They are almost done reloading. will you take COVER behind a table, RUN out of the place, or... suddenly you hear the girl telling you 'Take cover'... FIGHT them?").toUpperCase()

var bodyPart = Math.random()
                            if (bodyPart > .75){
                                bodyPart = "Right Arm"
                            }
                            else if (bodyPart > .50){
                                bodyPart= "Left Arm"
                            }
                            else if (bodyPart >.25){
                               bodyPart = "Right Leg"
                            }
                            else{
                              bodyPart = "Left Leg"
                            }

更改命令的顺序,以便在拾取身体部位后对其进行pprint。现在您正在打印倒数第二个车身部件

var bodyPartRoll = Math.Random();
var bodyPart;
if (bodyPartRoll > 0.75.){
   bodyPart = "Right Arm";
}else if(...){
   ...
}

prompt(bodyPart)

我还创建了一个单独的varialbe来存储Math.Random的结果。这不是必需的,但我认为将一个变量用于两件事是令人困惑的。此外,如果您不知道自动分号插入在Javascript中是如何工作的,我建议您在行尾添加分号。

也许您应该使用两个变量。一个叫随机数,一个叫身体部位。这样你就不会改变类型,你也应该对两者有一个更清晰的区分

请更具描述性,可能会发布整个代码,甚至可能会发布一个JSFIDLE来实时显示问题。