【发布时间】:2020-05-21 10:18:46
【问题描述】:
我正在制作一个测验网站,我目前正在编写一个函数来确定给定答案是否正确。我有两种不同的声音,一种是正确的,一种是错误的,有时它们会同时播放。例如,如果我的第一个问题正确,它只会播放正确的声音,但如果我的第二个问题不正确,它会同时播放两个问题,然后继续播放剩下的 3 个问题。我对 javascript 比较陌生,不知道为什么要这样做。这是我遇到问题的代码:
function correctOrIncorrect() {
score = 0;
var audioCorrect = new Audio('assets/audio/correct.mp3');
var audioIncorrect = new Audio('assets/audio/incorrect.mp3');
if (amount == 5 ) {
if (document.querySelector('input[name="answer-1"]:checked').value === myQuestions[0].correct_answer) {
score++;
audioCorrect.play();
} else {
audioIncorrect.play();
}
if (document.querySelector('input[name="answer-2"]:checked').value === myQuestions[1].correct_answer) {
score++;
audioCorrect.play();
} else {
audioIncorrect.play();
}
if (document.querySelector('input[name="answer-3"]:checked').value === myQuestions[2].correct_answer) {
score++;
audioCorrect.play();
} else {
audioIncorrect.play();
}
if (document.querySelector('input[name="answer-4"]:checked').value === myQuestions[3].correct_answer) {
score++;
audioCorrect.play();
} else {
audioIncorrect.play();
}
if (document.querySelector('input[name="answer-5"]:checked').value === myQuestions[4].correct_answer) {
score++;
audioCorrect.play();
} else {
audioIncorrect.play();
}
}
非常感谢您的任何帮助,并提前感谢您。
【问题讨论】:
标签: javascript