Visualizzazione dei risultati da 1 a 4 su 4

Discussione: Quiz script

  1. #1

    Quiz script

    Salve vorrei utilizzare un quiz nel mio sito.
    Ho trovato questo che funziona molto bene, ma vorrei che la lista di domande si generasse casualmente ad ogni aggiornamento di pagina. Come posso fare?
    codice:
    <head>
    <script language="JavaScript" type="text/javascript">
    //<![CDATA[
    <!--
    // Prelevato su http://www.web-link.it
    
    var ans = new Array;
    var done = new Array;
    var score = 0;
    
    ans[1] = "c";
    ans[2] = "d";
    ans[3] = "a";
    ans[4] = "a";
    ans[5] = "b";
    ans[6] = "c";
    ans[7] = "a";
    ans[8] = "a";
    ans[9] = "c";
    ans[10] = "d";
    
    function Engine(question, answer) {
    
            if (answer != ans[question]) {
                    if (!done[question]) {
                            done[question] = -1;
                            alert("Sbagliato!\n\nIl tuo punteggio è: " + score);
                            }
                    else {
                            alert("Hai gia risposto a questa domanda!");
                            }
                    }
            else {
                    if (!done[question]) {
                            done[question] = -1;
                            score++;
                            alert("Esatto!\n\nIl tuo punteggio è: " + score);
                            }
                    else {          
                            alert("Hai gia risposto a questa domanda!");
                            }
                    }
    }
                    
    function NextLevel () 
    {
            if (score == 1) {
                    alert("Hai totalizzato 1 punti.");
                    }
    if (score == 2) {
                    alert("Hai totalizzato 2 punti.");
                    }
    if (score == 3) {
                    alert("Hai totalizzato 3 punti.");
                    }
    if (score == 4) {
                    alert("Hai totalizzato 4 punti.");
                    }
    if (score == 5) {
                    alert("Hai totalizzato 5 punti.");
                    }
    if (score == 6) {
                    alert("Hai totalizzato 6 punti.");
                    }
    if (score == 7) {
                    alert("Hai totalizzato 7 punti.");
                    }
    if (score == 8) {
                    alert("Hai totalizzato 8 punti.");
                    }
    if (score == 9) {
                    alert("Hai totalizzato 9 punti.");
                    }
    if (score == 10) {
                    alert("Hai totalizzato 10 punti.");
                    }
                    }
            if (score >= 7 && score <= 10) {
                    alert("Impegnati di più e raggiungerai migliori traguardi!")
                    location=""
                    }
            else {
                    alert("Accesso negato!  Ci vogliono almeno 7 risposte esatte per accedere alla prossima pagina.")
                    self.location=""
                    }
    }
    
    // -->
    </script>
    </head>
    <body>
    
    <form action="">
        
    
    
            <font color="#1E90FF">xxxxxxx</font>
        </p>
        <input type="radio" value="a" name="1" onclick="Engine(1, this.value)" />xxxx
    
        <input type="radio" value="b" name="1" onclick="Engine(1, this.value)" />xxxx
    
        <input type="radio" value="c" name="1" onclick="Engine(1, this.value)" />xxxx
    
        <input type="radio" value="d" name="1" onclick="Engine(1, this.value)" />xxxxxx
    
        
    
    
    </form>
    
    
    
    <form>
        <input type="button" style="background-color: yellow" onclick="NextLevel()" value="Quiz completato!" />
    </form>
    </body>

  2. #2
    Moderatore di Annunci siti web, Offro lavoro/collaborazione, Cerco lavoro L'avatar di cavicchiandrea
    Registrato dal
    Aug 2001
    Messaggi
    26,131
    Ciao e benvenuto, per apportare le modifiche che chiedi bisognerebbe stravolgere (eseguire grosse modifiche) allo script che richiedo buone conoscenze, se non le hai (che immagino) prosegui le ricerche "quiz random javascript" le modifiche sarebbe più complesse
    Cavicchi Andrea
    Problemi con javascript, jquery, ajax clicca qui

  3. #3
    Grazie per la risposta. Ho trovato questo.
    Ora vorrei integrare gli alert in relazioni ai punteggi delle funzioni if e else presenti nel quiz precedente.
    codice:
    <html>  	   
    <head>  	
    <meta http-equiv="Content-Language" content="en-us">  	
    <title>Quanto sei bravo?</title>  	
    <script type="text/Javascript">  
    	var rightAnswer=new Array();  	
    var questPerPage=2;  	
    var quests=Array("Quest0","Quest1","Quest2","Quest3","Quest4","Quest5","Quest6","Quest7");  	
    var answers=Array();  	
    answers[0]=Array(1,"answer1","answer2","answer3","answer4")  	
    answers[1]=Array(2,"answer5","answer6","answer7","answer8")  	
    answers[2]=Array(3,"answer9","answer10","answer11","answer12")  
    
    answers[3]=Array(4,"answer13","answer14","answer15","answer16")  	answers[4]=Array(4,"answer17","answer18","answer19","answer20")  	answers[5]=Array(3,"answer21","answer22","answer23","answer24")  	answers[6]=Array(2,"answer25","answer26","answer27","answer28")  	answers[7]=Array(1,"answer29","answer30","answer31","answer32")  	   	function showQuestion(){  	htmlStr="";  	for(qpp=0;qpp<questPerPage;qpp++){  	   	q=Math.floor(Math.random()*quests.length)  	htmlStr+="Q#"+qpp+": "+quests[q]+"
    A: ";  	   	rightAnswer[qpp]=answers[q][0]-1;  	   	for(a=1;a<answers[q].length;a++){  	htmlStr+="<input name='ansr"+qpp+"' type='radio' value=''><label>"+answers[q][a]+"</label>  "  	}  	htmlStr+="
    
    ";  	}  	document.getElementById("myQuiz").innerHTML=htmlStr  	}  	   	function Nextlevel(){  	for (ra=0;ra<rightAnswer.length;ra++){  	radios=document.getElementsByName("ansr"+ra)  	if (radios[rightAnswer[ra]].checked){  	alert("The Answer#"+ra+" is correct");  	}else{  	alert("The Answer#"+ra+" is incorrect");  	}  	}  	showQuestion()  	}  	</script>  	</head>  	   	<body>  	   	<h1>Quiz:</h1>  	<form id="myQuiz" action="">  	   	   	</form>  	<form action="">   <input type="button" style="background-color: yellow" onclick="Nextlevel()" name="button1" value="Quiz completato!" />    	<script>  	showQuestion()  	
    </script>  	   	
    </body>  	   	
    </html>

  4. #4
    Vorrei inserire la variabile score in questo nuovo script.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.