如何获取变量cool以便我可以在 的函数之外使用它gotSpeech()?我想将它用于guessedCorrect()单击按钮时也会运行的功能。那可能吗?
let speechRec = new p5.SpeechRec('en-US', gotSpeech);
function gotSpeech() {
if (speechRec.resultValue) {
cool = speechRec.resultString;
if (cool == "0") {
zero.style.color = "#dc3545";
}
if (cool == "5") {
five.style.color = "#dc3545";
}
if (cool == "10") {
ten.style.color = "#dc3545";
}
if (cool == "15") {
fifteen.style.color = "#dc3545";
}
if (cool == "20") {
twenty.style.color = "#dc3545";
}
}
}
button.addEventListener("click", function(event) {
resetround();
speechRec.start();
setTimeout("getComputerChoice()", 3000);
setTimeout("identifyHands()", 3000);
clearInterval(myInterval);
myInterval = setInterval(function() {
time--;
if (time == -1) {
button.innerHTML = "Again";
clearInterval(myInterval);
time = 4;
} else {
button.innerHTML = "Start";
numbers.innerHTML = time;
}
}, 1000);
setTimeout("guessedCorrect()", 5000);
})
输出undefined在超出范围时返回。
红糖糍粑
LEATH
相关分类