:
var total=0;
var yourmark="your score is ";
if(document.getElementById('q12').checked) {
total=total+1;
}else {
total=total;
}
, . total, , 0. , , , "total . At no point are you updating the value of total" .
, PM 77-1, , total , .
<!DOCTYPE html>
<html>sssdsdsdsd
<head>Mypage.com
<title> myPage</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<script>
function showScore() {
var total=0;
var yourmark="your score is ";
if(document.getElementById('q12').checked) {
total=total+1;
}else {
total=total;
}
alert(yourmark + total );
}
</script>
</br>
<input type="radio" name="question1" id="q11" value="false">Question 1-first option <br>
<input type="radio" name="question1" id="q12" value="true" > Question 1- second option<br>
<input type="radio" name="question1" value="false">Question 1- third option<br>
<button onclick="showScore()">Show my score</button>
</body>
</html>
Run codeHide result source
share