我有太多写了一系列复杂的逻辑表达式,打印仅当下列条件为真:
如果风味设置为香草或巧克力,如果容器设置为锥形或碗,如果浇头设置为洒或花生如果上述条件是真,然后打印出:
我想__________带有两勺__________冰淇淋__________.
所以我输入了以下代码
var flavor = "chocolate";
var vessel = "bowl";
var toppings = "peanuts";
if (flavor === "chocolate" || flavor === "vanilla" && flavor != "strawberry" &&
vessel === "cone" ||
vessel === "bowl" && vessel != "hand" && toppings === "peanuts" ||
toppings === "sprinkles" && toppings != "walnuts") {
console.log("I'd like two scoops of " + flavor + " ice cream in a " +
vessel + " with " + toppings + " .");
}Run Code Online (Sandbox Code Playgroud)
并获得以下反馈
再试一次
什么都好
什么地方出了错
小智 5
这应该工作.
var flavor = "chocolate";
var vessel = "bowl";
var toppings = "peanuts";
if (
(flavor === "chocolate" || flavor === "vanilla") &&
(vessel === "cone" || vessel === "bowl") &&
(toppings === "peanuts" || toppings === "sprinkles")
) {
console.log("I'd like two scoops of " +
flavor + " ice cream in a " +
vessel + " with " +
toppings + " .");
}Run Code Online (Sandbox Code Playgroud)
我们不需要指定我们不需要使用的所有口味,容器和浇头.因此,如果你设置风味strawberry,程序将查看代码的第一部分:好的,我们在这里得到了什么?味道是否等于巧克力?不.接下来,味道是否等于香草?不.好的,这是必需的条件,所以不需要进一步检查,我将停止执行.
希望能帮助到你.
| 归档时间: |
|
| 查看次数: |
381 次 |
| 最近记录: |