javascript - 如何暂停某个代码并运行另一个代码直到需要
问题描述
我正在尝试从头开始制作一个口袋妖怪游戏,直到每次单击我的攻击选项时,它都会运行第一个 if 语句,然后运行下一个 if 语句替换第一张图片,然后让我有机会运行下次他们是我可以运行第一个 if 语句而不与第二个 if 语句冲突的方式吗?我发布了我的代码的链接
if (humanchoice === "effective") {
let BOT = document.createElement("img")
BOT.src = 'https://lh3.googleusercontent.com/Jys5bTaWg_ZRBr9GwE1CJ-4XzNWOsgp64aX0g1yXJ5UaMBE0vuuLO-OcIDDN7LNfKbH2ovFhwkyb2cKuiyhbKYUtuRDy-OOxNWVz6pEMIgRMim-LF0HHg-gMj1x-n8fJMAqaf8Y_=w246-h41-p-k'
BOT.className = 'overlappedEnemyHealth'
document.body.appendChild(BOT)
console.log(BOT)
if (BOT.src === 'https://lh3.googleusercontent.com/Jys5bTaWg_ZRBr9GwE1CJ-4XzNWOsgp64aX0g1yXJ5UaMBE0vuuLO-OcIDDN7LNfKbH2ovFhwkyb2cKuiyhbKYUtuRDy-OOxNWVz6pEMIgRMim-LF0HHg-gMj1x-n8fJMAqaf8Y_=w246-h41-p-k' && humanchoice === "effective") {
BOT.src = "https://lh3.googleusercontent.com/Yy8PPjNdJqTl8cmGTD81PzPBt3arn4358tGjNOR4iEkpe9s6c5beV7UBN-QPeSNypgMt2-nJKGwn0T46g4HkJtwx9e4lCk_fV8LPNq0OR0k7CmE5Wg_6eq0-I56M4zAjZp1-Vk86=w246-h41-p-k"
console.log(BOT)
}
} else if (botchoice === "super effective") {}
else if (humanchoice === "not effective") {}
console.log(humanchoice)
console.log(botchoice)
}
function fightch() {
}
function fightchance() {
return Math.floor(Math.random() * 3)
}
function fightchoiceYou(choice) {
return ["effective", "super effective", "not effective"][choice]
}
function fightchanceBot() {
return Math.floor(Math.random() * 3)
}
function fightchoiceBot(choice) {
return ["effective", "super effective", "not effective"][choice]
}
解决方案
推荐阅读
- python - python有条件代码解释吗?
- c++ - 为什么 C/++ scanf 函数需要引用变量作为参数?
- r - 如何在一张图中绘制多条 ecdf 线
- c# - 为什么反转方法调用顺序也会反转执行时间?
- c++ - 类模板的友元函数是否应该成为所有实例化的友元?
- security - 为什么在 JWT Token 中包含 Header 和 Payload?
- python - 我应该如何根据 Tkinter 中的变量更改图像
- reactjs - 如何在 React Native 中移除 Touchable Opacity 组件之间的空格
- node.js - 如何通过控制台登录 Sail.js 以获取访问路线或页眉输出?
- java - 删除旁边但出站的项目