提示符不会注意语句是否更改
Prompt does not notice if statement change
请帮忙。当使用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。这样你就不会改变类型,你也应该更清楚地区分这两者。
相关文章:
- 如何知道javascript for语句中的所有结果是否都是错误的
- ES6是否引入了一种机制来生成块范围的函数语句(而不是表达式)
- jade/pug是否可以在include语句中使用变量
- 在JavaScript / jQuery中,是否有一种更短的方法可以编写在同一个测试变量上具有许多OR的“if”语句
- 异步函数调用是否可以在两个同步语句之间完成
- if语句中的第4行是否从第2行开始
- 如何在函数中编写 if/else 语句,告诉我一个数字是否可以被 2 整除(在 javascript 中)
- 是否可以将条件语句或其他javascript作为参数传递到ember句柄中
- If.else语句检查NaN和空字符串是否在JavaScript中不起作用
- 检测是否按下了if语句的数字键
- 在条件(if)结构的条件语句中是否有定义变量的有效方法
- 节点.js是否支持“let”语句
- 是否可以创建涉及按钮的 if 语句
- 检查布尔键是否存在并将其包含在 if 语句中的最有效方法
- 用于确定是否存在多个变量的 if 语句简写
- 确定是否已在 if 语句中选择任何选项
- 创建 if 语句以指示是否应使用 if 语句
- 如何在纯 javascript 中检查元素是否有 ID?和条件语句问题
- 在 JS 中使用 if else 语句来检查 HTML 表单元素是否等于某个数字
- 是否可以使用 JavaScript 的 “if” 语句的值