gpt4 book ai didi

JavaScript 测验评分函数

转载 作者:行者123 更新时间:2023-11-28 08:46:35 25 4
gpt4 key购买 nike

好的,所以我在 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>

最佳答案

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

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

关于JavaScript 测验评分函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27557581/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com