salve
andando in giro per internet ho messo insieme questo quiz che ha le seguenti caratteristiche
- ti avverte se hai gia selezionato la risposta
- risultato finale con numero risposte giuste sul numero di domande e il resoconto delle risposte date dall'utente se esse sono errate o corrette...in più tra parentesi la risposta giusta del quiz..
ho una domanda...vorrei affiancare accanto alla risposta giusta del quiz anche quella data dall'utente in modo da permettergli il confronto...
un resoconto del tipo
risposta x: esatta; hai risposto: a; la risposta esatta è: a.
come si può fare?
ho girato parecchio ma non ci ho capito gran che..mi aiutate?
intanto posto il codice
questo è il file quiz1.js
var name= prompt("per favore inserisci il tuo nome","");
// Prelevato su http://www.web-link.it
var ans = new Array;
var done = new Array;
var stat = new Array;
var score = 0;
var count = 0;
ans[1] = "d";
ans[2] = "b";
ans[3] = "b";
ans[4] = "d";
ans[5] = "a";
ans[6] = "c";
ans[7] = "c";
ans[8] = "d";
ans[9] = "a";
ans[10] = "c";
function Engine( question, answer ) {
if ( answer != ans[ question ] ) {
if ( ! done[ question ] ) {
done[ question ] = -1;
stat[ question ] = false;
count++;
} else {
alert( "Hai gia risposto a questa domanda!" );
}
} else {
if ( ! done[ question ] ) {
done[ question ] = -1;
score++;
stat[ question ] = true;
count++;
} else {
alert( "Hai gia risposto a questa domanda!" );
}
}
if ( count == ans.length ) { NextLevel()}
}
function NextLevel () {
var htm = "<span style='color:#BCF2ED'>Ciao "+name+", il tuo punteggio è di<span style='color:white'> " + score + "</span> su <span style='color: white'>" + (ans.length-1) +"</span>" +
"
";
htm += " <span style='color:white'>Resoconto risposte (tra parentesi le risposte esatte del quiz)</span>
";
for ( var j = 1; j < stat.length; j++) {
htm += "<span style='color:white'>Risposta " + j+":</span> <span style='color:"+ ( stat[ j ] ? "#BCF2ED'>esatta" : "#BCF2ED'>errata")+"</span><span style='color:#BCF2ED'> ("+ans[j]+")</span>
";
}
htm += "vedi risposte";
document.getElementById( 'risultato' ).innerHTML = htm;
}
questo è presente nel html
per comodità metto solo 3 domande invece di 10
<form name="form">
Domanda 1 ?</p>
<input type=radio value="a" name="1" id="1" onClick="Engine(1, this.value)">risposta 1
<input type=radio value="b" name="1" id="1" onClick="Engine(1, this.value)">risposta 2
<input type=radio value="c" name="1" id="1" onClick="Engine(1, this.value)">risposta 3
<input type=radio value="d" name="1" id="1" onClick="Engine(1, this.value)">risposta 4
Domanda 2 ?</p>
<input type=radio value="a" name="2" id="2" onClick="Engine(2, this.value)">risposta 1
<input type=radio value="b" name="2" id="2" onClick="Engine(2, this.value)">risposta 2
<input type=radio value="c" name="2" id="2" onClick="Engine(2, this.value)">risposta 3
<input type=radio value="d" name="2" id="2" onClick="Engine(2, this.value)">risposta 4
Domanda 3 ?</p>
<input type=radio value="a" name="3" id="3" onClick="Engine(3, this.value)">risposta 1
<input type=radio value="b" name="3" id="3" onClick="Engine(3, this.value)">risposta 2
<input type=radio value="c" name="3" id="3" onClick="Engine(3, this.value)">risposta 3
<input type=radio value="d" name="3" id="3" onClick="Engine(3, this.value)">risposta 4
<input type=button onClick="NextLevel()" value="Test finito, accedi alla pagina"></p>
</form>
<div id='risultato'></div>
spero nel vostro aiuto