提示符不会注意语句是否更改

Prompt does not notice if statement change

本文关键字:是否 语句 提示符      更新时间:2023-09-26

请帮忙。当使用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"
                            }

更改命令的顺序,以便在之后打印body部分。现在你正在打印倒数第二个身体部位。

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

我还创建了一个单独的变量来存储Math.Random()的结果。这不是必需的,但我认为用一个变量来做两件事会让人困惑。另外,如果你不知道在Javascript中如何自动插入分号,我建议在行尾添加分号。

也许您应该使用两个变量。一个叫randomNumber,一个叫bodyPart。这样你就不会改变类型,你也应该更清楚地区分这两者。