Visualizzazione dei risultati da 1 a 3 su 3

Discussione: Script Random Quiz

  1. #1

    Script Random Quiz

    Ciao, vorrei modificare questo script.
    Il problema è che a volte le domande si ripetono, e vorrei che non succedesse. Qualcuno ha una soluzione?
    codice:
    <html>   <head>  <meta http-equiv="Content-Language" content="en-us">  <title></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>

  2. #2
    Moderatore di CSS L'avatar di KillerWorm
    Registrato dal
    Apr 2004
    Messaggi
    5,771
    Ciao,
    potresti utilizzare il metodo splice alla fine del ciclo for (o dove meglio credi) per eliminare di volta in volta le voci di quests e di answers che vengono utilizzate.

    Una cosa del genere (in rosso le parti aggiunte):

    codice:
    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+="
    
    ";
      quests.splice(q,1);
      answers.splice(q,1);
    }
    Ovviamente ho riportato giusto la parte di script interessata, che sta dentro la funzione showQuestion.
    Installa Forum HTML.it Toolset per una fruizione ottimale del Forum

  3. #3

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 © 2025 vBulletin Solutions, Inc. All rights reserved.