需要一些帮助来完成下面的测验。
/*
* Programming Quiz: Ice Cream (3-6)
*
* Write a single if statement that logs out the message:
*
* "I'd like two scoops of __________ ice cream in a __________ with __________."
*
* ...only if:
* - flavor is "vanilla" or "chocolate"
* - vessel is "cone" or "bowl"
* - toppings is "sprinkles" or "peanuts"
*
* We're only testing the if statement and your boolean operators.
* It's okay if the output string doesn't match exactly.
*/
// change the values of `flavor`, `vessel`, and `toppings` to test your code
var flavor = "strawberry";
var vessel = "hand";
var toppings = "cookies";
// Add your code here
if (flavor === "vanilla" || "chocolate" && vessel === "cone" || "bowl" && toppings === "prinkles" || "peanuts"){
console.log("I'd like two scoops of " + flavor + " ice cream in a " + vessel + " with " + toppings + ".");
}
else {
}
我似乎找不到如何仅在满足条件时打印语句的方法。此时,每当我使用条件中未定义的变量时;无论如何它都会在控制台中打印出来。 我想找到一种方法来防止这种情况发生。 希望这一切都有道理。任何帮助将非常感激。 谢谢!
最佳答案
您正在使用条件检查,例如 === 'str1' || 'str2
这是不正确的。
您可以明确指定所有条件,以便于理解。
if ((flavor === "vanilla" || flavor === "chocolate") && (vessel === "cone" || vessel === "bowl") && (toppings === "prinkles" || toppings === "peanuts")){
关于javascript - Udacity 冰淇淋测验 - Javascript 语句/条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50344570/