JavaScript 测验评分函数

JavaScript Quiz Scoring Functions

本文关键字:函数 JavaScript      更新时间:2023-09-26

好的,所以我正在用javascipt为一个带有测验的网站做这个项目,用Javascript,css,html和jquery制作,我在获得评分时遇到了问题。问题是在加载结果部分时在测验结束时获得总计。每次我结束测验时,它都会不断出现相同的数字,1/6。这是我到目前为止得到的:

var answers = "0";
function answerTotals()
{
if (document.getElementById("1A").checked = true) answers++;
else(console.log("answerswer was incorrect"));
}

此部分在页面上显示结果:

function showScore()
{
document.getElementById("Score").innerHTML = "You Got " +  answers + "/6";
console.log("Score is displayed.");
}

还有问题:

<div id="questions1">
<h1>Question 1.</h1>
<br>
Why are there data types in JavaScript?
<br>
<br><input type="radio" name="q1" value="A" id="1A" onchange="question1()">As it helps a computer    differentiate between different data.
<br><input type="radio" name="q1" value="B" id="1B" onchange="question1Wrong1()">There aren't.
<br><input type="radio" name="q1" value="C" id="1C" onchange="question1Wrong2()">To help it interact with Java.
<br><input type="radio" name="q1" value="D" id="1D" onchange="question1Wrong3()">To allow it to             complete a task.
<br>
<input type="button" value="Next" onclick="nextQuestion();answerTotals()">
<br>
<br>
<p onclick="hint1()">
</div>

您将值设置为 true,而不是检查一致性。试试这个

if (document.getElementById("1A").checked === true) answers++;