好的,所以我正在javascipt为一个带有测验的网站做这个项目,用Javascript,css,html和jquery制作,我有一个问题就是让得分起作用。问题是在加载结果部分时在测验结束时获得总计。每次我结束测验时,它只会持续出现相同的数字,1/6。这是我到目前为止所得到的:
var answers = "0";
function answerTotals()
{
if (document.getElementById("1A").checked = true) answers++;
else(console.log("answer 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>
答案 0 :(得分:0)
您将值设置为true,而不是检查一致性。试试这个
if (document.getElementById("1A").checked === true) answers++;