我有一个简单的多问题测验,当选择正确或不正确的答案时,它会显示某些文本。现在我正在尝试添加增量分数,但没有成功。我添加了一个警报,无论答案正确还是错误都会触发警报,但分数不会增加。
我的代码中缺少什么?
完整的代码如下。为了简单起见,只包含一个问题。
function questionMarkers() {
let labels = document.querySelectorAll(
"div[class*='rsform-block-question'] .formControlLabel"
);
let count = labels.length;
for (let i = 0; i < count; i++) {
let marker = `<span class="question-marker">${i + 1}</span>`;
labels[i].insertAdjacentHTML("beforebegin", marker);
}
}
const runQuiz = (() => {
questionMarkers();
let score = 0;
let answers = document.querySelectorAll(".rsform-radio");
answers.forEach(function(answer) {
answer.addEventListener("click", (e) => {
let target = e.target;
let container = target.closest(".formContainer");
let correct = container.querySelector("div[class$='true']");
let wrong = container.querySelector("div[class$='false']");
let feedback = container.querySelector("div[class$='feedback']");
let question = container.querySelector(
"div[class*='rsform-block-question']"
);
let next = container.querySelector(".js-btn--next.success");
let submit = container.querySelector(
".js-btn--submit.rsform-submit-button"
);
if (e.target.value == "t") {
correct.style.display = "block";
wrong.style.display = "none";
feedback.style.display = "block";
alert("Correct!");
score++;
} else {
correct.style.display = "none";
wrong.style.display = "block";
feedback.style.display = "block";
alert("Incorrect");
}
question.style.display = "none";
});
document.getElementById("score").innerText = score;
});
})();
慕婉清6462132
慕容708150
相关分类