Creating multiple choice quiz

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vandana Rola

    Creating multiple choice quiz

    Hello Everyone,

    I am a beginner in Javascript.I want to create fun quiz tool using
    javascript (no database). The feature of that tool is every question
    has five choices. The user needs to select three best choices. If they
    do, a message window pops up which says good choices or something and
    take them to next question. If they don't choose all of the best
    choices they get another message like try again but these are not the
    best choices and take them back to the same question. Is there any
    tutorial which could help me do this or has anyone done something like
    this before, which could help me.

    VR
  • Andrew Thompson

    #2
    Re: Creating multiple choice quiz

    On 20 Jul 2004 14:01:00 -0700, Vandana Rola wrote:
    [color=blue]
    > or has anyone done something like
    > this before, which could help me.[/color]

    A quiz type thing? No.. I don't think so,
    ...is such a thing even *possible*?





    I am just *kidding*, sheeshhh!! ;-)

    ...hmmm lemme see.. start with these 3900 or so..
    <http://www.google.com/search?q=%22jav ascript+source% 22+quiz>

    But then, you realize that any test written in
    (client side) Javascript can be 'cracked' by the
    students if they can read Javascript? They can
    read the Javascript itself for the answers..

    *Unless*.. the Javascript is server-side (very rare)
    or you have help from a server side database, or
    other server side 'adjudicator' that simply takes
    the answers and tells the student 'right/wrong'.

    HTH

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology

    Comment

    • Lee

      #3
      Re: Creating multiple choice quiz

      Andrew Thompson said:[color=blue]
      >
      >On 20 Jul 2004 14:01:00 -0700, Vandana Rola wrote:
      >[color=green]
      >> or has anyone done something like
      >> this before, which could help me.[/color]
      >
      >A quiz type thing? No.. I don't think so,
      >..is such a thing even *possible*?[/color]
      [color=blue]
      >..hmmm lemme see.. start with these 3900 or so..
      ><http://www.google.com/search?q=%22jav ascript+source% 22+quiz>
      >
      >But then, you realize that any test written in
      >(client side) Javascript can be 'cracked' by the
      >students if they can read Javascript? They can
      >read the Javascript itself for the answers..[/color]

      Not many of those 3900 examples will fill the OP's requirement
      of having three correct answers for each question.

      Here's a simple example that also shows that you can make it
      non-trivial to read the answers from the client-side script.
      In this case, it's not really very hard, but still may be
      more trouble than it's worth.

      The correct answers are encoded in the "key" attribute as:
      Ignore everything except the 5 digits that immediately
      follow the first zero.
      Those 5 digits correspond to the 5 answer choices.
      If the digit is less than 5, then that choice is one
      of the correct answers.



      <html>
      <head>
      <script type="text/javascript">

      quiz = [ {q: "Which are odd numbers?",
      a: ["7", "3", "15", "12", "0"],
      key: "6310132875 75"
      },
      {q: "Which are U.S. States?",
      a: ["Utah", "Apache", "Maine", "Sonora", "Florida"],
      key: "2401738283 "
      },
      {q: "Which are mammals?",
      a: ["skunk", "tarantula" , "dolfin", "human", "aligator"],
      key: "7026339154 ",
      }
      ];

      function nextQuestion(){
      var question=quiz.p op();
      var html="<p>"+ques tion.q+"</p><form>";
      for(var i=0;i<question. a.length;i++){
      html+="<input type='checkbox' >&nbsp;"+questi on.a[i]+"<br>";
      }
      html+="<input type='button' value='Done' onclick='check( this.form,\""
      +question.key+" \")'></form>";
      document.getEle mentById("table t").innerHTML=h tml;
      }
      function check(f,key){
      key=key.replace (/^.*0/,"").substr(0,5 );
      for(var i=0;i<key.lengt h;i++) {
      if ((key.charAt(i) <"5")!=f.elemen ts[i].checked) {
      document.getEle mentById("table t").innerHTM L+=
      "<p>Wrong! Try again.</p>";
      return;
      }
      }
      document.getEle mentById("table t").innerHTML+= "<p>Right!</p>";
      if(quiz.length) {
      setTimeout("nex tQuestion()",50 0);
      } else {
      document.getEle mentById("table t").innerHTML=" <p>Done!</p>";
      }
      }
      </script>
      </head>
      <body onload="nextQue stion()">
      <div id="tablet"></div>
      </body>
      </html>

      Comment

      • Vandana Rola

        #4
        Re: Creating multiple choice quiz

        Lee <REM0VElbspamtr ap@cox.net> wrote in message news:<cdmdfn0o9 c@drn.newsguy.c om>...[color=blue]
        > Andrew Thompson said:[color=green]
        > >
        > >On 20 Jul 2004 14:01:00 -0700, Vandana Rola wrote:
        > >[color=darkred]
        > >> or has anyone done something like
        > >> this before, which could help me.[/color]
        > >
        > >A quiz type thing? No.. I don't think so,
        > >..is such a thing even *possible*?[/color]
        >[color=green]
        > >..hmmm lemme see.. start with these 3900 or so..
        > ><http://www.google.com/search?q=%22jav ascript+source% 22+quiz>
        > >
        > >But then, you realize that any test written in
        > >(client side) Javascript can be 'cracked' by the
        > >students if they can read Javascript? They can
        > >read the Javascript itself for the answers..[/color]
        >
        > Not many of those 3900 examples will fill the OP's requirement
        > of having three correct answers for each question.
        >
        > Here's a simple example that also shows that you can make it
        > non-trivial to read the answers from the client-side script.
        > In this case, it's not really very hard, but still may be
        > more trouble than it's worth.
        >
        > The correct answers are encoded in the "key" attribute as:
        > Ignore everything except the 5 digits that immediately
        > follow the first zero.
        > Those 5 digits correspond to the 5 answer choices.
        > If the digit is less than 5, then that choice is one
        > of the correct answers.
        >
        >
        >
        > <html>
        > <head>
        > <script type="text/javascript">
        >
        > quiz = [ {q: "Which are odd numbers?",
        > a: ["7", "3", "15", "12", "0"],
        > key: "6310132875 75"
        > },
        > {q: "Which are U.S. States?",
        > a: ["Utah", "Apache", "Maine", "Sonora", "Florida"],
        > key: "2401738283 "
        > },
        > {q: "Which are mammals?",
        > a: ["skunk", "tarantula" , "dolfin", "human", "aligator"],
        > key: "7026339154 ",
        > }
        > ];
        >
        > function nextQuestion(){
        > var question=quiz.p op();
        > var html="<p>"+ques tion.q+"</p><form>";
        > for(var i=0;i<question. a.length;i++){
        > html+="<input type='checkbox' >&nbsp;"+questi on.a[i]+"<br>";
        > }
        > html+="<input type='button' value='Done' onclick='check( this.form,\""
        > +question.key+" \")'></form>";
        > document.getEle mentById("table t").innerHTML=h tml;
        > }
        > function check(f,key){
        > key=key.replace (/^.*0/,"").substr(0,5 );
        > for(var i=0;i<key.lengt h;i++) {
        > if ((key.charAt(i) <"5")!=f.elemen ts[i].checked) {
        > document.getEle mentById("table t").innerHTM L+=
        > "<p>Wrong! Try again.</p>";
        > return;
        > }
        > }
        > document.getEle mentById("table t").innerHTML+= "<p>Right!</p>";
        > if(quiz.length) {
        > setTimeout("nex tQuestion()",50 0);
        > } else {
        > document.getEle mentById("table t").innerHTML=" <p>Done!</p>";
        > }
        > }
        > </script>
        > </head>
        > <body onload="nextQue stion()">
        > <div id="tablet"></div>
        > </body>
        > </html>[/color]

        Thank you both for replying my question. Lee, I tried to execute the
        code you wrote here. I am getting an error "object expected" in line
        where we have <body onload="nextQue stion()">. I checked the code but
        couldn't find any error. Could you help me.

        Comment

        • Lee

          #5
          Re: Creating multiple choice quiz

          Vandana Rola said:
          [color=blue]
          >
          >Thank you both for replying my question. Lee, I tried to execute the
          >code you wrote here. I am getting an error "object expected" in line
          >where we have <body onload="nextQue stion()">. I checked the code but
          >couldn't find any error. Could you help me.[/color]

          Sorry, I hadn't tested in IE.
          Remove the comma from the end of this line:

          key: "7026339154 ",

          Mozilla let that mistake slide.

          Comment

          • Vandana Rola

            #6
            Re: Creating multiple choice quiz

            Lee <REM0VElbspamtr ap@cox.net> wrote in message news:<cdopdf01q 6t@drn.newsguy. com>...[color=blue]
            > Vandana Rola said:
            >[color=green]
            > >
            > >Thank you both for replying my question. Lee, I tried to execute the
            > >code you wrote here. I am getting an error "object expected" in line
            > >where we have <body onload="nextQue stion()">. I checked the code but
            > >couldn't find any error. Could you help me.[/color]
            >
            > Sorry, I hadn't tested in IE.
            > Remove the comma from the end of this line:
            >
            > key: "7026339154 ",
            >
            > Mozilla let that mistake slide.[/color]


            I am using the code provided by Lee above to create this tool.
            There is one more improvement I would like to make here:
            I would like to give the feedback for all the checked answers. Like
            in the questions below:
            Which are odd numbers:
            2
            3
            4
            5
            13

            if the user selects 2, 3, 5, then I would like to give feedback as
            below:
            2 Incorrect, 2 is an even number
            3 correct
            5 correct

            I tried to make the improvement in the following function to
            accomplish this:

            function check(f,key){
            var newhtml="";
            key=key.replace (/^.*0/,"").substr(0,5 );
            for(var i=0;i<key.lengt h;i++) {
            if ((key.charAt(i) <"5")==f.elemen ts[i].checked)
            {
            newhtml+= question.a[i] + "<br>Right.<br> ";
            }
            else if ((key.charAt(i) >"5")==f.elemen ts[i].checked)
            {
            newhtml+= question.a[i] + " <br>Wrong.<br>" ;

            }
            else {return};
            }
            document.getEle mentById("table t").innerHTM L= newhtml;

            It gives me correct feedback for the checked answers. But it also
            checks the unchecked answers( which I would like to ignore) and gives
            me reverse feedback. e.g. even if 4 and 13 are unchecked it gives
            feedback 4 is an odd number and 13 is an even number. Is there a way
            to tell JAVAscript to ignore something and do not write it too. I
            tried empty statements, but they didn't work either. I really
            appreciate your help.

            Thanks

            Comment

            Working...