console.log("Batman glares at you.");
var userAnswer = prompt("Are you feeling lucky, punk?");
if (userAnswer==="yes")
{
console.log("Batman hits you very hard. It's Batman and you're you! Of course Batman wins!");
}
else
{
console.log("You did not say yes to feeling lucky. Good choice! You are a winner in the game of not getting beaten up by Batman.");
}
在这里,我想运行命令,以便如果 userAnswer 对于第一个 console.log 语句采用除 yes 之外的多个值 IE 我想将“ya”也指定为第一个 console.log 语句的 userAnswer
最佳答案
console.log("Batman glares at you.");
var userAnswer = prompt("Are you feeling lucky, punk?");
if (["yes","ya","yo","yeaaaa","list goes on here"].indexOf(userAnswer)!=-1)
{
console.log("Batman hits you very hard. It's Batman and you're you! Of course Batman wins!");
}
else
{
console.log("You did not say yes to feeling lucky. Good choice! You are a winner in the game of not getting beaten up by Batman.");
}
关于javascript - 关于javascript中的if条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20840996/