2014-12-18 5 views
0

자키, css, html 및 jquery로 작성된 퀴즈가있는 웹 사이트의 javascipt에서이 프로젝트를하고 있습니다. 점수를 얻는 데 문제가있었습니다. 결과 섹션을로드 할 때 퀴즈가 끝날 때 문제가 발생합니다. 퀴즈가 끝날 때마다 똑같은 번호로 나옵니다. 1/6.JavaScript 퀴즈 득점 기능

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

희망은 자바 스크립트 퀴즈가 아닙니다! (lighthearted, 실제로는 뜻이 아니다) – tigertrussell

답변

0

당신이 값을 true로 설정하는

var answers = "0"; 
function answerTotals() 
{ 

if (document.getElementById("1A").checked = true) answers++; 
else(console.log("answer was incorrect")); 
} 

이 제품은 또한 페이지에 결과를 표시합니다 : 이것은 내가 지금까지 가지고 무엇을 일치 여부를 확인하지 않습니다. 이것을 사용해보십시오

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

나는 그렇게 어리석은 haha ​​(도와 줘서 고마워)를 느낀다. – Lyon1995Lyon

+0

haha ​​걱정이 없다. 정확하게 작동하는지 확인해주세요 :) –

+0

'document.getElementById ("1A")뿐만 아니라 왜 체크가되어 있는가? +; ++;' – Todd