javascript - 关于javascript中的if条件

标签 javascript

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/

相关文章:

javascript - 如何在 Flask 项目的 VSCode 中调试 JavaScript?

javascript - 将变量从 Node/Express 传递到 AngularJS

javascript - 使方 block 粘在滚动条上

javascript - Facebook 如何在 AJAX 页面加载期间显示浏览器加载进度?

javascript - 无法在 Cloudflare Worker 脚本上创建 MD5 哈希

javascript - 如何获取使用我的具有 iframe 的网络小部件的网站的统计信息?

javascript - 使用 jQuery 获取根父级

javascript - Vue js 构建失败

javascript - javascript 中的 Scriptlet 和 scriptlet 中的 js 变量

javascript - 显示图像 onclick 工作正常,但如何在再次单击时隐藏它