<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>
body {width:700px;margin:auto;font-family:calibri}
div {padding:5px}
input {padding:5px;}
.tastoverifica {width:100%;text-align:center;background-color:#74bb29;color:white;padding:20px;font-size:24px;border-radius:5px;}
</style>
<script type="text/javascript">
function gradeTest() {

//var alertText;
var i;
var bloccoAcorrectAnswers = 0

// Controllo che almeno una delle due risposte al quesito A1 sia corretta
var a1 = document.getElementById('q1').value.toLowerCase();
var a2 = document.getElementById('q2').value.toLowerCase();
if (a1 == 'soggetto' || a2 == 'oggetto') {
bloccoAcorrectAnswers++;
}

// Controllo che almeno due delle tre risposte al quesito A2 siano corrette
var checkCorrect = 0;
var a3 = document.getElementsByName('q3');
if (a3[1].checked) {
++checkCorrect;
}
var a4 = document.getElementsByName('q4');
if (a3[0].checked) {
++checkCorrect;
}
var a5 = document.getElementsByName('q5');
if (a3[1].checked) {
++checkCorrect;
}
if (checkCorrect >= 2) {
bloccoAcorrectAnswers++;
}

// Visualizzo il risultato solo se l'utente ha risposto a tutti i quesiti
if (
a1 != ""
&& a2 != ""
&& (
(a3[0].checked || a3[1].checked)
&& (a4[0].checked || a4[1].checked)
&& (a5[0].checked || a5[1].checked)
)
) {
alert(bloccoAcorrectAnswers)
}

}
</script>
</head>
<body>
<form id="test">
<div><b>A1. Rispondi a queste due domande di grammatica:</b></div>
<div>Qual è la funzione logica che indica chi compie un'azione? Il <input name="q1" type="text" id="q1" size="15" maxlength="20" /></div>
<div>Qual è il complemento che indica ciò su cui ricade l'azione? Il complemento<input name="q2" type="text" id="q2" size="15" maxlength="20" /></div>
<br>
<hr>
<br>
<div><b>A2. Indica se le seguenti affermazioni sono vere o false</b></div>
<table>
<tr>
<td></td>
<td>Vero</td>
<td>Falso</td>
</tr>
<tr>
<td>A) Milano è il capoluogo del Piemonte</td>
<td><input name="q3" type="radio" id="q3" value="1" /></td>
<td><input name="q3" type="radio" id="q3" value="2" /></td>
</tr>
<tr>
<td>B) Il presidente della Repubblica italiana è Mattarella</td>
<td><input name="q4" type="radio" id="q4" value="1" /></td>
<td><input name="q4" type="radio" id="q4" value="2" /></td>
</tr>
<tr>
<td>C) Roger Federer è un tennista tedesco</td>
<td><input name="q5" type="radio" id="q5" value="1" /></td>
<td><input name="q5" type="radio" id="q5" value="2" /></td>
</tr>
</table>
<br>
<br>
<br>
<input class="tastoverifica" name="submit" type="button" onClick="gradeTest()" value="Verifica le tue risposte" />
</form>
</body>
</html>