这是一款分数不断增加但没有显示任何内容的游戏,因此我想添加一条提醒消息,显示您在获得 5 分后获胜。我怎样才能做到这一点?
cycleColor = function() {
++curColor;
if (curColor == colors.length) {
curColor = 0;
}
jello.className = "jello " + colors[curColor];
},
checkColorMatch = function() {
if (curColor == nextMatchColor) {
++streak;
dur -= 10;
if (dur < minDur) {
dur = minDur;
}
streakCounter.innerHTML = streak;
} else {
streak = 0;
dur = 2000;
streakCounter.innerHTML = "";
}
prevMatchColor = nextMatchColor;
nextMatchColor = chooseColor();
boxes[0].className = "box " + colors[prevMatchColor];
boxes[1].className = "box " + colors[nextMatchColor];
rerun();
setTimeout(checkColorMatch, dur);
};
main.classList.add("run");
jello.classList.add(colors[curColor]);
boxes[0].classList.add(colors[prevMatchColor]);
boxes[1].classList.add(colors[nextMatchColor]);
for (b in boxes) {
if (b < boxes.length) {
boxes[b].classList.add(colors[chooseColor()]);
}
}
最佳答案
如果您只需要一个简单的弹出消息,只需使用 alert()
方法即可。
alert("You won!");
编辑:
将 ++streak;
替换为如下内容:
if(++streak === 5){
alert("You won!");
//whatever other things you need to do when the player wins
return;
}
关于javascript - 显示警报消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55872260/