/    Sign up×
Community /Pin to ProfileBookmark

Javascript Quiz

  • 1. Which of the following is the binary equivalent of the decimal number 186?
    A. 10100110
    [COLOR=”DarkOrange”]B. 10111010 [/COLOR][COLOR=”Magenta”]Correct![/COLOR]
    C. 11000010
    D. 10101100
  • Question 1 of 3 Questions total.

    Number of Tries 0
    Number of Correct Answers 0

    My problem is that I want the correct answer (? is to be in red color when I click on it, and others will be in light blue or fade or blur, so that the user will be able to see only the correct answer more clearer than any other answers.

    And if the correct answer was clicked, means that user has chose the correct answer for that question, then those A, B, C or D answer will not allow to click again.

    How can I get the grade, such as if user got the right answer for each question, then he will earn 1%, 2% and so on until he got 100% if he got all 100 questions.

    Thank you so much for your help on this..
    ———————

    <HTML>
    <HEAD>
    <META http-equiv=Content-Type content=”text/html; charset=windows-1252″>

    <SCRIPT language=Javascript>

    var qu = new Array();
    var n = 0;

    var chA = new Array();
    var fbA = new Array();
    var caA = new Array();

    var chB = new Array();
    var fbB = new Array();
    var caB = new Array();

    var chC = new Array();
    var fbC = new Array();
    var caC = new Array();

    var chD = new Array();
    var fbD = new Array();
    var caD = new Array();

    var chE = new Array();
    var fbE = new Array();
    var caE = new Array();

    //—-
    n++
    qu[n] = “Which of the following is the binary equivalent of the decimal number 186?”
    chA[n] = “10100110”
    chB[n] = “10111010”
    chC[n] = “11000010”
    chD[n] = “10101100”
    caB[n] = “10111010 (Correct!)”

    fbA[n] = “Wrong.Try again”
    fbB[n] = “Fantastic! B is correct!”
    fbC[n] = “Wrong!”
    fbD[n] = “Wrong!”
    //—-
    n++
    qu[n] = “Which of the following is the decimal equivalent of the binary number 10110011?”
    chA[n] = “113”
    chB[n] = “179”
    chC[n] = “205”
    chD[n] = “263”
    caB[n] = “179 —> is correct!”

    fbA[n] = “Nope!”
    fbB[n] = “Fantastic! 179 is correct.”
    fbC[n] = “Nah!”
    fbD[n] = “Noooh!”
    //—-
    n++
    qu[n] = “What is the hexadecimal equivalent of the binary number 11000011?”
    chA[n] = “A9”
    chB[n] = “B1”
    chC[n] = “B3”
    chD[n] = “C3”
    caD[n] = “C3 —> is correct.”

    fbA[n] = “No, your answer is wrong. Try again!”
    fbB[n] = “Sorry, that is not the correct answer. Try again!”
    fbC[n] = “Oops! Your answer is incorrect. Try again!”
    fbD[n] = “Excellent!, D. is the right answer”
    //—-

    //–END DATA–
    A_Correct01 = “Congratuation!”
    B_Correct01 = “Fantastic!”
    C_Correct01 = “Good!”
    D_Correct01 = “Excellent!”
    E_Correct01 = “Great!”

    var SC = 0;
    var Tr = 0;
    var UA = 0;
    var UB = 0;
    var UC = 0;
    var NQ = 0;

    //——————————————————————– ———
    function CA()
    {
    Tr++;
    document.feedback.tries.value = Tr;
    if (fbA[NQ].indexOf(A_Correct01, 0) == 0)
    {
    SC++ //Correct Answer.
    document.mc.ca.value = caA[NQ];
    }
    document.feedback.score.value = SC;
    }
    //——————————————————————– ———
    function CB()
    {
    Tr++; // Question Counter.
    document.feedback.tries.value = Tr;
    if (fbB[NQ].indexOf(B_Correct01, 0) == 0)
    {
    SC++;
    document.mc.cb.value = caB[NQ];
    }
    document.feedback.score.value = SC;
    }
    //——————————————————————– ———
    function CC()
    {
    Tr++;
    document.feedback.tries.value = Tr;
    if (fbC[NQ].indexOf(C_Correct01, 0) == 0)
    {
    SC++;
    document.mc.cc.value = caC[NQ];
    }
    document.feedback.score.value = SC
    }
    //——————————————————————– ———
    function CD()
    {
    Tr++;
    document.feedback.tries.value = Tr;
    if (fbD[NQ].indexOf(D_Correct01, 0) == 0)
    {
    SC++;
    document.mc.cd.value = caD[NQ];
    }
    document.feedback.score.value = SC
    }
    //——————————————————————– ———
    function CE()
    {
    Tr++;
    document.feedback.tries.value = Tr;
    if (fbE[NQ].indexOf(E_Correct01, 0) == 0)
    {
    SC++
    }
    document.feedback.score.value = SC
    }
    //——————————————————————– ———
    function FA()
    {
    document.feedback.fb.value = fbA[NQ];
    if (UA == 0)
    {
    CA();
    }
    UA = 1
    }
    //——————————————————————– ———
    function FB()
    {
    document.feedback.fb.value = fbB[NQ];
    if (UB == 0)
    {
    CB();
    }
    UB = 1
    }
    //——————————————————————– ———
    function FC()
    {
    document.feedback.fb.value = fbC[NQ];
    if (UC == 0)
    {
    CC();
    }
    UC = 1
    }
    //——————————————————————– ———
    function FD()
    {
    document.feedback.fb.value = fbD[NQ];
    if (UD == 0)
    {
    CD();
    }
    UD = 1; //Allows one try only.
    }
    //——————————————————————– ———
    function FE()
    {
    document.feedback.fb.value = fbE[NQ];
    if (UE == 0)
    {
    CE();
    }
    UE = 1
    }
    //——————————————————————– ———
    function SQ(QN)
    {
    UA = 0;
    UB = 0;
    UC = 0;
    UD = 0;
    UE = 0;

    NQ = NQ + QN;
    if (qu[NQ] == null)
    {
    document.mc.q.value = “No more questions!nYou need to RELOAD to do the exercises again.”;
    NQ = 1;
    document.feedback.score.value = SC;
    document.feedback.fb.value = “You have done a Good Work!”;
    document.mc.ca.value = “”;
    document.mc.cb.value = “”;
    document.mc.cc.value = “”;
    document.mc.cd.value = “”;
    document.mc.ce.value = “”
    }
    else if (qu[NQ] == “”)
    {
    document.mc.q.value = “This question is being modify…”;
    document.feedback.score.value = SC;
    document.feedback.fb.value = “”;
    document.mc.ca.value = “Empty”;
    document.mc.cb.value = “Empty”;
    document.mc.cc.value = “Empty”;
    document.mc.cd.value = “Empty”;
    document.mc.ce.value = “Empty”
    }

    else
    {
    document.feedback.score.value = SC;
    if (QN == 1)
    {
    document.feedback.fb.value = “Question ” + NQ+ ” of ” + n + ” “+”Questions total.”;
    }
    else
    {
    document.feedback.fb.value = “This option will Skip 10 questions at a time.”
    };
    document.mc.q.value = NQ + “. ” + qu[NQ];
    document.mc.ca.value = chA[NQ];
    document.mc.cb.value = chB[NQ];
    document.mc.cc.value = chC[NQ];
    document.mc.cd.value = chD[NQ];
    document.mc.ce.value = chE[NQ]

    }
    }
    //——————————————————————– ———
    //–>
    </SCRIPT>

    </HEAD>

    <body bgcolor=”#005050″ scroll=”no” onload=SQ(1)>

    <div align=”center”>

    <table >
    <tr>
    <td CLASS=menuBar0001 height=”5″>
    <CENTER><font color=”#ffffff”>Quiz</font></CENTER>
    </td>
    </tr>

    <tr>
    <td>

    <FORM name = mc>

    <CENTER>

    <TEXTAREA style=”overflow: hidden” name = q rows = 3 wrap = Virtual cols = 120></TEXTAREA>

    <BR><INPUT onclick =” FA()” type = button value = A.> <INPUT size = 116 name = ca>
    <BR><INPUT onclick =” FB()” type = button value = B.> <INPUT size = 116 name = cb>
    <BR><INPUT onclick =” FC()” type = button value = C.> <INPUT size = 116 name = cc>
    <BR><INPUT onclick =” FD()” type = button value = D.> <INPUT size = 116 name = cd>
    <BR>
    </CENTER>
    <INPUT onclick = SQ(-10) type = button value = “<<<” name = show01>

    <INPUT onclick = SQ(-1) type = button value = “<<” name = show02>

    <INPUT onclick = SQ(1) type = button value = “>>” name = show03>
    <INPUT onclick = SQ(10) type = button value = “>>>” name = show04>

    </FORM>

    <FORM name = feedback>
    <TEXTAREA style=”overflow: hidden” name = fb rows = 5 wrap = Virtual cols = 120></TEXTAREA>
    <BR>Number of Tries : <INPUT onfocus=this.blur() size = 4 name = tries ;>
    &nbsp;&nbsp;&nbsp;Number of Correct Answers : <INPUT onfocus=this.blur() size = 4 name = score ;>

    </FORM>

    </td>
    </tr>

    </table>

    </DIV>

    </BODY>

    </HTML>

    to post a comment
    JavaScript

    1 Comments(s)

    Copy linkTweet thisAlerts:
    @Tweak4Mar 06.2007 — Before you get too far along in this, you realize that Javascript is a terrible language for conducting any sort of quiz, right? Users can just look at the source code, and all but the most inexperienced of users can use that to decipher the correct answers within a matter of minutes.
    ×

    Success!

    Help @cunoc spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.19,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...