www.webdeveloper.com
Results 1 to 2 of 2

Thread: javascript quiz review button mass confusion

  1. #1
    Join Date
    Jul 2013
    Posts
    24

    javascript quiz review button mass confusion

    hey i need help with this review button i cannot seem to make it work.* sections of code have been removed cause it was too long.*
    im not sure what else to do i searched the forum and found nothing.* im left hopeless on this button maybe i can redo the innerhtml to dom but i dont know how to convert it now.
    thank you in advance
    Code:
    <script type="text/JavaScript">
    function Questions(divname) {
    ** this.QText** = new Array(21); // The questions
    ** this.QAnswer = new Array(21); // The correct answers
    ** this.QChoice = new Array(84); // The possible multi-choice values
    ** this.thisAns = new Array(10); // The answers for this page
    ** this.Answer* = new Array(10); // The user's answers
    ** this.anchor = document.getElementById(divname);
    
    *
    ** // OK, set the questions
    ** this.QText[0] = "?";
    ** this.QText[1] = "?";
    ** this.QText[2] = "?";
    ** this.QText[3] = "?";
    ** this.QText[4] = "?";
    ** this.QText[5] = "?";
    ** this.QText[6] = "?";
    ** this.QText[7] = "?";
    ** this.QText[8] = "?";
    ** this.QText[9] = "?";
    ** this.QText[10] = "?";
    ** this.QText[11] = "?";
    ** this.QText[12] = "?";
    ** this.QText[13] = ".";
    ** this.QText[14] = "?";
    ** this.QText[15] = "?";
    ** this.QText[16] = "?";
    ** this.QText[17] = "?";
    ** this.QText[18] = "?";
    ** this.QText[19] = "?";
    ** this.QText[20] = "?"
    
    ** // possible answers
    ** this.QChoice[0] = "23-15";
    ** this.QChoice[1] = "23-12";
    ** this.QChoice[2] = "34-15";
    ** this.QChoice[3] = "34-12";* //end q0
    ** this.QChoice[4] = "Black";
    ** this.QChoice[5] = "Red";
    ** this.QChoice[6] = "Blue";
    ** this.QChoice[7] = "None of the above";* //end q1
    ** this.QChoice[8] = "2314AA004";
    ** this.QChoice[9] = "2314AA005";
    ** this.QChoice[10] = "3414AA005";
    ** this.QChoice[11] = "3414AA004";* //end q2
    ** this.QChoice[12] = ")";
    ** this.QChoice[13] = ")";
    ** this.QChoice[14] = ")";
    ** this.QChoice[15] = ")"; //end q3
    ** this.QChoice[16] = "HF RT";
    ** this.QChoice[17] = "Power Supply";
    ** this.QChoice[18] = "CCU";
    ** this.QChoice[19] = "APU"; //end q4
    ** this.QChoice[20] = "300 NMI";
    ** this.QChoice[21] = "390 NMI";
    ** this.QChoice[22] = "200 NMI";
    ** this.QChoice[23] = "290 NMI"; //end q5
    ** this.QChoice[24] = "73";
    ** this.QChoice[25] = "53";
    ** this.QChoice[26] = "63";
    ** this.QChoice[27] = "43"; //end q6
    ** this.QChoice[28] = "962-1213 GHz";
    ** this.QChoice[29] = "962-1213 MHz";
    ** this.QChoice[30] = "1025-1150 MHz";
    ** this.QChoice[31] = "1025-1150 GHz"; //end q7
    ** this.QChoice[32] = "1025-1150 MHz";
    ** this.QChoice[33] = "1025-1150 GHz";
    ** this.QChoice[34] = "962-1213 GHz";
    ** this.QChoice[35] = "962-1213 MHz"; //end q8
    ** this.QChoice[36] = "/";
    ** this.QChoice[37] = "/";
    ** this.QChoice[38] = "2/";
    ** this.QChoice[39] = "./"; //end q9
    ** this.QChoice[40] = "VHF and UHF";
    ** this.QChoice[41] = "HF and UHF";
    ** this.QChoice[42] = "VHF and HF";
    ** this.QChoice[43] = "All of the above"; //end q10
    ** this.QChoice[44] = "2  29.999 MHz/30  151.975 MHz";
    ** this.QChoice[45] = "225  399.975 MHz/2  29.999 MHz";
    ** this.QChoice[46] = "30  151.975 MHz/225  399.975 MHz";
    ** this.QChoice[47] = "None of the above"; //end q11
    ** this.QChoice[48] = "CCU";
    ** this.QChoice[49] = "LNA (Low Noise Amplifier)";
    ** this.QChoice[50] = "R/T";
    ** this.QChoice[51] = "HPA (High Power Amplifier)"; //end q12
    ** this.QChoice[52] = "True";
    ** this.QChoice[53] = "False";
    ** this.QChoice[54] = "N/A";
    ** this.QChoice[55] = "N/A"; //end q13
    ** this.QChoice[56] = "****pit Voice Recorder";
    ** this.QChoice[57] = "Common Voice Recorder";
    ** this.QChoice[58] = "Common Vehical Reciever";
    ** this.QChoice[59] = "****pit Voice Reciever"; //end q14
    ** this.QChoice[60] = "<2.5";
    ** this.QChoice[61] = "2.5>";
    ** this.QChoice[62] = "<5";
    ** this.QChoice[63] = "5>"; //end q15
    ** this.QChoice[64] = "Upper Antenna";
    ** this.QChoice[65] = "Switching unit";
    ** this.QChoice[66] = "Lower Antenna";
    ** this.QChoice[67] = "LNA (Low Noise Amplifier)"; //end q16
    ** this.QChoice[68] = "Aft upper fuselage/forward lower fuselage";
    ** this.QChoice[69] = "Forward upper fuselage/aft lower fuselage";
    ** this.QChoice[70] = "Nose radome/tail radome";
    ** this.QChoice[71] = "Forward upper fuselage/forward lower fuselage"; //end q17
    ** this.QChoice[72] = "Textual";
    ** this.QChoice[73] = "Graphic";
    ** this.QChoice[74] = "Both A and B";
    ** this.QChoice[75] = "None of the above"; //end q18
    ** this.QChoice[76] = "320 NMi";
    ** this.QChoice[77] = "20 NMi";
    ** this.QChoice[78] = "150 NMi";
    ** this.QChoice[79] = "80 NMi"; //end q19
    ** this.QChoice[80] = "True";
    ** this.QChoice[81] = "False";
    ** this.QChoice[82] = "N/A";
    ** this.QChoice[83] = "N/A"; //end q20
    ** // Set the correct answers
    ** this.QAnswer[0] = 1;
    ** this.QAnswer[1] = 4;
    ** this.QAnswer[2] = 2;
    ** this.QAnswer[3] = 2;
    ** this.QAnswer[4] = 1;
    ** this.QAnswer[5] = 2;
    ** this.QAnswer[6] = 3;
    ** this.QAnswer[7] = 3;
    ** this.QAnswer[8] = 4;
    ** this.QAnswer[9] = 4;
    ** this.QAnswer[10] = 1; // answers 
    ** this.QAnswer[11] = 3;
    ** this.QAnswer[12] = 2;
    ** this.QAnswer[13] = 1;
    ** this.QAnswer[14] = 1;
    ** this.QAnswer[15] = 3;
    ** this.QAnswer[16] = 2;
    ** this.QAnswer[17] = 1;
    ** this.QAnswer[18] = 3;
    ** this.QAnswer[19] = 3;
    ** this.QAnswer[20] = 2;
    
    }
    
    Questions.prototype.generateQuiz = function() {
    ** var QCount = 0;
    ** var QNumber = 0;
    
    ** // Initialise the "questions available" table
    ** var QUsed = new Array(21);
    ** for (QCount=0; QCount<21; QCount++) {
    ***** QUsed[QCount] = 1; // Marked as available
    ** }
    
    ** // Delete any existing questions
    ** //this.nukeExistingQuiz();
    ** this.anchor.innerHTML = "";
    
    ** var HTMLBlob = "<table>";
    
    ** // Build up the questions
    ** for (QCount=0; QCount<10; ) {
    ***** QNumber = Math.floor(21 * Math.random());
    ***** if (1 == QUsed[QNumber]) { // Still available?
    * HTMLBlob += this.AddQuestion(QNumber, QCount);
    * QCount++;
    ******** QUsed[QNumber] = 0; // Marked as unavailable
    ***** }
    ** }
    ** HTMLBlob += "</table>";
    ** this.anchor.innerHTML = HTMLBlob;
    }
    
    // This nukes the quiz
    Questions.prototype.nukeExistingQuiz = function() {
    ** if (null != this.anchor && null != this.anchor.childCount) {
    ***** while (this.anchor.childCount > 0) {
    ******** this.anchor.removeChild(this.anchor.childNodes[0]);
    ***** }
    ** }
    }
    
    * // Add this to the DOM
    Questions.prototype.AddQuestion = function(QNum, EntryNum) {
    ** //* you should use DOM stuff, and not non-standard innerHtml ...
    *
    
    ** var Ix;
    ** var HTMLBlob = "<tr><td><input type=\"checkbox\" id=\"check" + EntryNum + "\" checked=\"checked\"></td><td><br/>"
    *********************************************************************************************************************************** // (((( + "Question #" + QNum + " + QNum + ":</td><td>"))) inserts question lableling
    ********************** + "<strong>" + this.QText[QNum] + "</strong></td><td><select id=\"answer" + EntryNum + "\" size=\"1\">"
    ********************** + "<option selected=\"selected\" value=\"0\">-- Select an answer --</option>"
    ****** 
    ******** 
    ** for (Ix=0; Ix<4; Ix++) {
    ***** HTMLBlob = HTMLBlob + "<option value=\"" + Ix + "\">" + this.QChoice[QNum*4+Ix] + "</option>";
    ** }
    ** HTMLBlob = HTMLBlob + "</select></td></tr>";0
    ** 
    ** this.thisAns[EntryNum] = this.QAnswer[QNum];
    ** return HTMLBlob;
    
    }
    
    
    // Verify that all questions have been answered
    Questions.prototype.AreQuestionsAnswered = function() {
    ** var unanswered = 0;
    ** for (var Ix=0; Ix<10; Ix++) {
    ***** this.Answer[Ix] = document.getElementById("answer" + Ix).selectedIndex;
    ***** if (this.Answer[Ix] == 0) {
    ******** unanswered++;
    ***** }
    ** }
    ** return unanswered;
    }
    
    // Score the results
    Questions.prototype.ScoreIt = function() {
    ** var count = this.AreQuestionsAnswered();
    ** if (count > 0) {
    ***** alert("You didn't answer " + count + " questions. Please try again.");
    ***** count = 0;
    ** } else {
    ***** for (var Ix=0; Ix<10; Ix++) {
    ******** if (this.Answer[Ix] == this.thisAns[Ix]) {
    *********** document.getElementById("check" + Ix).checked = true;
    *********** count++;
    ******** } else {
    *********** document.getElementById("check" + Ix).checked = false;
    ******** }
    ***** }
    ***** alert("You got " + count + " correct."); alert("Questions with check marks are correct.\n***** Please click the review button \n********** for more information.");
    ** }
    ** return count;
    
    }
    
    
    *//review the results
    Questions.prototype.review = function() {
    * 
    alert ("this button is not currently functioning");
    ********
    
    *
    
    }
    ** //makes the invisible buttons appear
    
    function visibleButton() {
    
    var buttonToShow = document.getElementById("invisiButton");
    buttonToShow.style.visibility = "visible";
    
    }
    
    function visibleButtona() {
    var buttonToShow = document.getElementById("invisiButtona");
    buttonToShow.style.visibility = "visible";
    }
    
    
    </script>
    
    </head><body>
    
    ** <div id="quizblock"></div>
    
    ** <script type="text/JavaScript">
    ***** var MyQuiz = new Questions("quizblock");
    ***** MyQuiz.generateQuiz();
    ** </script>

  2. #2
    Join Date
    Jul 2013
    Posts
    24
    JUst realised i did Not type it all. I need the button to display the wrong answer the tester choose and the correct answer. I also want to display a url reference for the right answer

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles