Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    trying to make random questions

    Iam trying to help out a friend with this code below, its working and all,so it might be usufull to others, but iam trying to make the questions random ie: a random 10 out of 20
    Code:
    <html>
    
    <head>
    <meta http-equiv="Content-Type"
    content="text/html; charset=iso-8859-1">
    <title> PC Test </title>
    
    <script LANGUAGE="JavaScript">
    
    
    <!-- hide this script tag's contents from old browsers --->
    
    function jumpBox(list) {
       location.href = list.options[list.selectedIndex].value
       }
    
    function init() 
                  {
    
                                 
    
                  questions = new Array()
                  questions[1] = "A Network must consist of which two of the following components?"
                  questions[2] = "Geographically, a Metropolitan based network typically spans how far?"
                  questions[3] = "Geographically, a WAN typically spans how far?"
                  questions[4] = "Geographically, a LAN typically spans how far?"
                  questions[5] = "Which of the following is not a layer in the TCP/IP model?"
                  questions[6] = "Which layer is responsible for the delivery of packets from source to destination?"
                  questions[7] = "Which of the following is associated with SMTP, Telnet, FTP &HTTP?"
                  questions[8] = "Which of the following is most suited for high bandwidth backbone requirements?"
                  questions[9] = "Which of the following is most suited for low bandwidth backbone?"
                  questions[10] = "A MESH topology is most suited for?"
                  questions[11] = "An advantage of MESH topology would be?"
                  questions[12] = "A typical desktop connects to the network using which cables?"
                  questions[13] = "Which of the following is unsuitable cabling for a backbone system?"
                  questions[14] = "Can you use a LAN in a flying aircraft?"
                  questions[15] = "What does TCP/IP Stand for?"
                  questions[16] = "What is an ADSL Modems primary function?"
                  questions[17] = "How Susceptible are Fibre optics to EMI?"
                  questions[18] = " "
                  questions[19] = " "
                  questions[20] = " "
    
                  answerA = new Array()
                  answerA[1] = "At least 2 Computing devices."
                  answerA[2] = "Up to 1 Mile"
                  answerA[3] = "Up to 1 Mile"
                  answerA[4] = "Up to 1KM(Campus Based)"
                  answerA[5] = "Presentation"
                  answerA[6] = "Transport"
                  answerA[7] = "Transport"
                  answerA[8] = "Twisted Pair(UTP)"
                  answerA[9] = "Twisted Pair(UTP)"
                  answerA[10] = "A LAN"
                  answerA[11] = "It is easy to configure"
                  answerA[12] = "Twisted pair"
                  answerA[13] = "Twisted Pair"
                  answerA[14] = "Yes"
                  answerA[15] = "Transfer control protocol / Internet Process"
                  answerA[16] = "To provide the end user with a fast Internet connection"
                  answerA[17] = " "
                  answerA[18] = " "
                  answerA[19] = " "
                  answerA[20] = " "
    
                  answerB = new Array()
                  answerB[1] = "Software (Protocols)"
                  answerB[2] = "Up to 100KM"
                  answerB[3] = "Normally 10KM to 1000KM"
                  answerB[4] = "Global"
                  answerB[5] = "Transport"
                  answerB[6] = "Network"
                  answerB[7] = "Network"
                  answerB[8] = "Twisted pair(STP)"
                  answerB[9] = "Twisted pair(STP)"
                  answerB[10] = "A WAN"
                  answerB[11] = "It is cheap"
                  answerB[12] = "Optical Fibre"
                  answerB[13] = "Coaxial Cable"
                  answerB[14] = "No"
                  answerB[15] = "Transport control protocol / Internet Protocol"
                  answerB[16] = "To provide the end user with networking capabilities"
                  answerB[17] = " "
                  answerB[18] = " "
                  answerB[19] = " "
                  answerB[20] = " "
    
                  answerC = new Array()
                  answerC[1] = "A Router"
                  answerC[2] = "Up to 10KM (City based)"
                  answerC[3] = "Global"
                  answerC[4] = "Up to 100KM(Campus based)"
                  answerC[5] = "Network"
                  answerC[6] = "Application"
                  answerC[7] = "Data link"
                  answerC[8] = "Optical Fibre"
                  answerC[9] = "Coaxial cable"
                  answerC[10] = "A MAN"
                  answerC[11] = "It provides resiliency"
                  answerC[12] = "Coaxial Cable"
                  answerC[13] = "Optical Fibre"
                  answerC[14] = "Maybe"
                  answerC[15] = "Transformer cooling process / Internal Protocol"
                  answerC[16] = "To act as a server"
                  answerC[17] = " "
                  answerC[18] = " "
                  answerC[19] = " "
                  answerC[20] = " "
    
                  answerD = new Array()
                  answerD[1] = "A PDA Device"
                  answerD[2] = "Global"
                  answerD[3] = "Up to 1KM"
                  answerD[4] = "Up to 10 km(city based)"
                  answerD[5] = "Data link"
                  answerD[6] = "Data link"
                  answerD[7] = "Application"
                  answerD[8] = "Coaxial cable"
                  answerD[9] = "Optical fibre"
                  answerD[10] = "A Home Network"
                  answerD[11] = "None of the above"
                  answerD[12] = "None of the above"
                  answerD[13] = "None of the above"
                  answerD[14] = "In the near Future"
                  answerD[15] = "Transformers control protocol / Intranet Protocol"
                  answerD[16] = "To act as a back up power source"
                  answerD[17] = " "
                  answerD[18] = " "
                  answerD[19] = " "
                  answerD[20] = " "
    
                  rightAns = new Array
                  rightAns[1] = "a"
                  rightAns[2] = "c"
                  rightAns[3] = "b"
                  rightAns[4] = "a"
                  rightAns[5] = "a"
                  rightAns[6] = "b"
                  rightAns[7] = "d"
                  rightAns[8] = "c"
                  rightAns[9] = "c"
                  rightAns[10] = "b"
                  rightAns[11] = "c"
                  rightAns[12] = "a"
                  rightAns[13] = "d"
                  rightAns[14] = "a"
                  rightAns[15] = "b"
                  rightAns[16] = "a"
                  rightAns[17] = "d"
                  rightAns[18] = " "
                  rightAns[19] = " "
                  rightAns[20] = " "
    
                  reference = new Array()
                  reference[1] = ""
                  reference[2] = ""
                  reference[3] = ""
                  reference[4] = ""
                  reference[5] = ""
                  reference[6] = ""
                  reference[7] = ""
                  reference[8] = ""
                  reference[9] = ""
                  reference[10] = ""
                  reference[11] = ""
                  reference[12] = ""
                  reference[13] = ""
                  reference[14] = ""
                  reference[15] = ""
                  reference[16] = ""
                  reference[17] = ""
                  reference[18] = ""
                  reference[19] = ""
                  reference[20] = ""
    
                  } 
    
    function nextQuestion(form)
    
    //set the total number of questions equal to quizend
    
    {   var quizEnd = eval(10 * 1);
    
        if(form.questNo.value == quizEnd) {
    
           form.question.value = "";
    
           form.choiceA.value = "";
    
           form.choiceB.value = "";
    
           form.choiceC.value = "";
    
           form.choiceD.value = "";
    
           form.yourChoice.value = "";
    
           form.results.value = "End of Quiz.  Your final results are listed below."; } else {
    
        if(form.questNo.value == "") {form.questNo.value = 1} else {
        
           form.questNo.value = eval(form.questNo.value) + 1;
    
        }
    
        form.question.value = questions[form.questNo.value];
    
        form.choiceA.value = answerA[form.questNo.value];
    
        form.choiceB.value = answerB[form.questNo.value];
    
        form.choiceC.value = answerC[form.questNo.value];
    
        form.choiceD.value = answerD[form.questNo.value];
    
        form.yourChoice.value = "";
    
        form.results.value = "";
    
        if(form.myScore.value == "") {form.myScore.value = 0; } else {
                                                      form.myScore.value = form.myScore.value; }
    
       }
    
    }
    
       function checkAnswer(form) {
          
          var myScore = 0;
          var curve = 0;
    
          if(form.results.value != "") {form.results.value = "Sorry, no guessing allowed.  In order to retry this question you will have to start the quiz over.  Click on ''Next Question'' to continue."; }
    
          else if(form.yourChoice.value == rightAns[form.questNo.value]) {
          form.myScore.value = eval(form.myScore.value) + eval(1);
          form.results.value = "Conratulations!  You are correct. That brings your cumulative score to " + form.myScore.value + " out of a possible " + form.questNo.value + ".  Click on ''Next Question'' to continue."; } else {
          
          form.results.value = "Sorry, you are incorrect. Please refer to " + reference[form.questNo.value] + " before retaking the quiz.  This brings your cumulative score to " + form.myScore.value + " out of a possible " + form.questNo.value + ".  Click on ''Next Question'' to continue." }
    
       
       curve = form.myScore.value / form.questNo.value;
    
       form.percent.value = parseInt(curve * 100,10);
       
       if(curve > .90) {form.grade.value = "A"; } else if(curve > .80) {form.grade.value = "B"; } else if(curve > .70) {form.grade.value = "C"; } else if(curve > .60) {form.grade.value = "D"; } else {form.grade.value = "F"; }
        }
    
    
    function clearForm(form)
    
    {
    
        
        form.questNo.value = "";
        form.question.value = "";
        form.choiceA.value = "";
        form.choiceB.value = "";
        form.choiceC.value = "";
        form.choiceD.value = "";
        form.yourChoice.value = "";
        form.results.value = "";
        form.myScore.value = "";
        form.percent.value = "";
        form.grade.value = "";
        
    
    }
    
    
    
    <!-- done hiding from old browsers -->
    
    
    
    
    </script>
    </head>
    
    
    
    <body>
    
    
    <body onLoad="init()">
    
    <form method="POST">
      <div align="center"><center><table BORDER="1">
        <tr>
          <td COLSPAN="2" BGCOLOR="#574631"><div align="center"><center><p><font SIZE="+3"
          COLOR="#FFFFFF">Boris PC Test</font></td>
        </tr>
        <tr>
          <td COLSPAN="2" BGCOLOR="#574631"><div align="center"><center><p> </p>
          </center></div><div align="center"><center><p><font COLOR="#FFFFFF">Click on &quot;Next
          Question&quot; to start quiz. Be sure to use small letters (no caps) when entering your
          letter choice. Also, in order to get credit for each right answer, be sure to click on
          &quot;Check Current Answer&quot; before going on to the next question.</font> </td>
        </tr>
        <tr>
          <td><b>Question&nbsp;#:</b></td>
          <td ALIGN="LEFT"><input TYPE="TEXT" NAME="questNo" SIZE="4"></td>
        </tr>
        <tr>
          <td><b>Question:</b></td>
          <td><div align="center"><center><p><textarea COLS="70" ROWS="2" name="question"
          wrap="virtual"></textarea></td>
        </tr>
        <tr>
          <td ALIGN="RIGHT"><b>a)</b></td>
          <td><div align="center"><center><p><input TYPE="TEXT" NAME="choiceA" SIZE="75"></td>
        </tr>
        <tr>
          <td ALIGN="RIGHT"><b>b)</b></td>
          <td><div align="center"><center><p><input TYPE="TEXT" NAME="choiceB" SIZE="75"></td>
        </tr>
        <tr>
          <td ALIGN="RIGHT"><b>c)</b></td>
          <td><div align="center"><center><p><input TYPE="TEXT" NAME="choiceC" SIZE="75"></td>
        </tr>
        <tr>
          <td ALIGN="RIGHT"><b>d)</b></td>
          <td><div align="center"><center><p><input TYPE="TEXT" NAME="choiceD" SIZE="75"></td>
        </tr>
        <tr>
          <td ALIGN="RIGHT"><b>Your choice:</b></td>
          <td><input TYPE="TEXT" NAME="yourChoice" SIZE="4"></td>
        </tr>
        <tr>
          <td COLSPAN="2"><div align="center"><center><p><input TYPE="button"
          VALUE="Check Current Answer" onClick="checkAnswer(this.form)"><input TYPE="button"
          VALUE="Next Question" onClick="nextQuestion(this.form)"> <input TYPE="reset"
          VALUE="Start Over" onClick="clearForm(this.form)"></td>
        </tr>
        <tr>
          <td ALIGN="RIGHT"><b>Results:</b></td>
          <td><div align="center"><center><p><textarea COLS="70" ROWS="3" name="results"
          wrap="virtual"></textarea></td>
        </tr>
        <tr>
          <td ALIGN="RIGHT"><b>Current Score:</b></td>
          <td><b>Points:</b><input TYPE="TEXT" NAME="myScore" SIZE="4">&nbsp;&nbsp;<b>Percentage:</b><input
    
          TYPE="TEXT" NAME="percent" SIZE="6">&nbsp;&nbsp;<b>Letter Grade:</b><input TYPE="TEXT"
          NAME="grade" SIZE="6"></td>
        </tr>
      </table>
      </center></div>
    </form>
    
    </body>
    Last edited by Marty; 03-05-2005 at 02:20 PM.

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    First step is a proper organization of your data
    Code:
    var questions=[
      { text: "Question 1",
        answers:[{text:"Choice 1", isCorrect:true},
                 {text:"Choice 2", isCorrect:false},
                 {text:"Choice 3", isCorrect:false}]
      },
    ....
    ];
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •