学习JavaScript,如果以下陈述为真,如何打印出这一行

Ato*_*ity 1 javascript

我有太多写了一系列复杂的逻辑表达式,打印仅当下列条件为:

如果风味设置为香草或巧克力,如果容器设置为锥形或碗,如果浇头设置为洒或花生如果上述条件是,然后打印出:

我想__________带有两勺__________冰淇淋__________.

所以我输入了以下代码

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)

并获得以下反馈

再试一次

什么都好

  • 您的代码应具有可变的味道
  • 您的代码应该有一个可变容器
  • 您的代码应该有一个变量顶部
  • 您的代码应该有一个if语句
  • 您的代码应使用逻辑表达式
  • 你的代码应该与flavor = vanilla,vessel = cone和toppings = sprinkles一起使用
  • 你的代码应该与flavor = vanilla,vessel = cone和toppings = peanuts一起使用
  • 你的代码应该与flavor = vanilla,vessel = bowl和toppings = sprinkles一起使用
  • 你的代码应该与flavor = vanilla,vessel = bowl和toppings = peanuts一起使用
  • 你的代码应该使用flavor = chocolate,vessel = cone和toppings = sprinkles
  • 你的代码应该与flavor = chocolate,vessel = cone和toppings = peanuts一起使用
  • 你的代码应该与flavor = chocolate,vessel = bowl和toppings = sprinkles一起使用
  • 你的代码应该与flavor = chocolate,vessel = bowl和toppings = peanuts一起使用
  • 项目清单

什么地方出了错

  • 当"草莓"用作风味时,您的代码不应该通过.
  • 当"手"用作容器时,您的代码不应通过.
  • 当"核桃"用作浇头时,您的代码不应通过.

小智 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,程序将查看代码的第一部分:好的,我们在这里得到了什么?味道是否等于巧克力?不.接下来,味道是否等于香草?不.好的,这是必需的条件,所以不需要进一步检查,我将停止执行.

希望能帮助到你.