Petit quiz

Contenu du snippet

Petit quiz avec 10 questions et résultat

Source / Exemple :


<html>
<head>
<title>GameQuiz</title>

<script>

//script nicolas (nicolas@abacho.fr)

var ans = new Array;
var done = new Array;
var score = 0;

ans[1] = "#";
ans[2] = "#";
ans[3] = "#";
ans[4] = "#";
ans[5] = "#";
ans[6] = "#";
ans[7] = "#";
ans[8] = "#";
ans[9] = "#";
ans[10] = "#";

function Engine(question, answer) {

	if (answer != ans[question]) {
		if (!done[question]) {
			done[question] = -1;
			alert("Faux, votre score: " + score);
		    	}
		else {
			alert("Vous avez déjà répondu");
			}
		}
	else {
		if (!done[question]) {
			done[question] = -1;
			score++;
			alert("Bonne réponse, score " + score);
		    	}
		else {		
			alert("Vous avez déjà répondu");
			}
		}
}
		
function NextLevel () {
	if (score > 10) {
		alert("Cheater!");
		}
	if (score >= 7 && score <= 11) {
		alert("Bravo")
		
		}
	else {
		alert("Pas terrible!")
		}
}

</script>
<BODY BGCOLOR="#FFFFFF">
<center><font size=6 face=Arial>Quiz</font><br>
</center>
<noscript>JavaScript is <b><i>disabled</b></i>.  Get Netscape 3.0 or turn it on!</noscript>

<form>
1.<p>
<input type=radio value="a" onClick="Engine(1, this.value)"><br>
<input type=radio value="b" onClick="Engine(1, this.value)"><br>
<input type=radio value="c" onClick="Engine(1, this.value)"><br>
<input type=radio value="d" onClick="Engine(1, this.value)"><p>

2.<p>
<input type=radio value="a" onClick="Engine(2, this.value)"><br>
<input type=radio value="b" onClick="Engine(2, this.value)"><br>
<input type=radio value="c" onClick="Engine(2, this.value)"><br>
<input type=radio value="d" onClick="Engine(2, this.value)"><p>

3.<p>
<input type=radio value="a" onClick="Engine(3, this.value)"><br>
<input type=radio value="b" onClick="Engine(3, this.value)"><br>
<input type=radio value="c" onClick="Engine(3, this.value)"><br>
<input type=radio value="d" onClick="Engine(3, this.value)"><p>

4.<p>
<input type=radio value="a" onClick="Engine(4, this.value)"><br>
<input type=radio value="b" onClick="Engine(4, this.value)"><br>
<input type=radio value="c" onClick="Engine(4, this.value)"><br>
<input type=radio value="d" onClick="Engine(4, this.value)"><p>

5.<p>
<input type=radio value="a" onClick="Engine(5, this.value)"><br>
<input type=radio value="b" onClick="Engine(5, this.value)"><br>
<input type=radio value="c" onClick="Engine(5, this.value)"><br>
<input type=radio value="d" onClick="Engine(5, this.value)"><p>

6.<p>
<input type=radio value="a" onClick="Engine(6, this.value)"><br>
<input type=radio value="b" onClick="Engine(6, this.value)"><br>
<input type=radio value="c" onClick="Engine(6, this.value)"><br>
<input type=radio value="d" onClick="Engine(6, this.value)"><p>

7.<p>
<input type=radio value="a" onClick="Engine(7, this.value)"><br>
<input type=radio value="b" onClick="Engine(7, this.value)"><br>
<input type=radio value="c" onClick="Engine(7, this.value)"><br>
<input type=radio value="d" onClick="Engine(7, this.value)"><p>

8.<p>
<input type=radio value="a" onClick="Engine(8, this.value)"><br>
<input type=radio value="b" onClick="Engine(8, this.value)"><br>
<input type=radio value="c" onClick="Engine(8, this.value)"><br>
<input type=radio value="d" onClick="Engine(8, this.value)"><p>

9.<p>
<input type=radio value="a" onClick="Engine(9, this.value)"><br>
<input type=radio value="b" onClick="Engine(9, this.value)"><br>
<input type=radio value="c" onClick="Engine(9, this.value)"><br>
<input type=radio value="d" onClick="Engine(9, this.value)"><p>

10.<p>
<input type=radio value="a" onClick="Engine(10, this.value)"><br>
<input type=radio value="b" onClick="Engine(10, this.value)"><br>
<input type=radio value="c" onClick="Engine(10, this.value)"><br>
<input type=radio value="d" onClick="Engine(10, this.value)"><p>

<center>
<input type=button onClick="NextLevel()" value="Résultat">
</center>
</form>
<!-- END OF SCRIPT -->

</body>
</html>

Conclusion :


Explications :

Trouvez ces lignes :

1.QUESTION A POSER<p>
<input type=radio value="a" onClick="Engine(1, this.value)">REPONSE A<br>
<input type=radio value="b" onClick="Engine(1, this.value)">REPONSE B<br>
<input type=radio value="c" onClick="Engine(1, this.value)">REPONSE C<br>
<input type=radio value="d" onClick="Engine(1, this.value)">REPONSE D<p>

Mettons que pour la question 1, la bonne réponse est "C", Mettre dans le javascript :

ans[1] = "c"; //la réponse de la question 1 est "c" comme indiqué dans le js
ans[2] = "#";//faire de même avec les autres questions
ans[3] = "#";
ans[4] = "#";
ans[5] = "#";
ans[6] = "#";
ans[7] = "#";
ans[8] = "#";
ans[9] = "#";
ans[10] = "#";

Faire de même avec les autres questions

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.