我正在创建一个hang子手游戏,当玩家输入的答案不正确时,需要将绿色矩形更改为红色矩形。总计计算功能有效,输入!== answers无效,这是我需要帮助的。
var total = 0;
gameboard.fillStyle = 'green';
gameboard.fillRect(10, 30, 30, 30)
gameboard.fillRect(80, 30, 30, 30)
gameboard.fillRect(150, 30, 30, 30)
$('#total_score').on('click', calculate);
function calculate() {
for (var index = 0; index < 14; index = index + 1) {
if ($('#' + index).val() == answers[index]) {
total = total + 1;
}
if ($('#' + index).val() !== answers[index]) {
gameboard.fillStyle = 'red';
gameboard.fillRect(10, 30, 30, 30)
}
}
$('#display_total').html(total);
total = 0;
};