Javascript Quiz Code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • C. David Rossen

    Javascript Quiz Code

    Hello:

    I found a script for a simple multiple choice quiz that I would like to
    tailor to a quiz that I want to post on a website. The quiz I want to use
    can be found at :



    Here is my problem. I want to be able to use answers with more than one
    word or number which requires spaces. When I tried doing that, it did not
    recognize the question as being answered. For example, it would not
    recognize an answer of Bob Smith unless I put Bob_Smith which I don't want
    to do. The answers in the example are all either 1 word or 1 number answers
    so I cannot tell from that how to do this. Can someone tell me what I need
    to do to be able to use multiple word answers without having to use an
    underscore? Thanks for your help.

    David


  • McKirahan

    #2
    Re: Javascript Quiz Code

    "C. David Rossen" <cdrossen@cdrma rketing.com> wrote in message
    news:O6WdnYShxc 1nAAmiRVn-jg@comcast.com. ..[color=blue]
    > Hello:
    >
    > I found a script for a simple multiple choice quiz that I would like to
    > tailor to a quiz that I want to post on a website. The quiz I want to use
    > can be found at :
    >
    > http://mtl.math.uiuc.edu/users/C2Schult/quiz2.html
    >
    > Here is my problem. I want to be able to use answers with more than one
    > word or number which requires spaces. When I tried doing that, it did not
    > recognize the question as being answered. For example, it would not
    > recognize an answer of Bob Smith unless I put Bob_Smith which I don't want
    > to do. The answers in the example are all either 1 word or 1 number[/color]
    answers[color=blue]
    > so I cannot tell from that how to do this. Can someone tell me what I[/color]
    need[color=blue]
    > to do to be able to use multiple word answers without having to use an
    > underscore? Thanks for your help.
    >
    > David[/color]

    I don't see the problem.

    The answers are merely hardcoded in the JavaScript :

    var aKey = new Array(3);
    aKey[0]="distributive" ;
    aKey[1]="1/3";
    aKey[2]="24/99";

    Just include a space in your answer; for example,

    aKey[0]="distributi ve property";

    Note, you may have to be concerned with case sensitivity if you allow
    free-form answers.


    Comment

    • C. David Rossen

      #3
      Re: Javascript Quiz Code

      OK..when I change all instances of "distributi ve" to "distributi ve
      property", it does not recognize the answer as a correct answer. Here are
      the places where I changed it:

      aKey[0]="distributi ve property";

      <input type="radio" name="q1" value="distribu tive property"
      onClick=student Ans(1,"distribu tive property") >distributive property<br>

      That choice is a correct answer, but along with the other two correct
      answers, it is only giving me a 67% score instead of a 100% score so it is
      not recognizing "distributi ve property" as a correct answer.

      Any ideas? Thanks.


      "McKirahan" <News@McKirahan .com> wrote in message
      news:vD1lb.5112 18$2x.222587@rw crnsc52.ops.asp .att.net...[color=blue]
      > "C. David Rossen" <cdrossen@cdrma rketing.com> wrote in message
      > news:O6WdnYShxc 1nAAmiRVn-jg@comcast.com. ..[color=green]
      > > Hello:
      > >
      > > I found a script for a simple multiple choice quiz that I would like to
      > > tailor to a quiz that I want to post on a website. The quiz I want to[/color][/color]
      use[color=blue][color=green]
      > > can be found at :
      > >
      > > http://mtl.math.uiuc.edu/users/C2Schult/quiz2.html
      > >
      > > Here is my problem. I want to be able to use answers with more than one
      > > word or number which requires spaces. When I tried doing that, it did[/color][/color]
      not[color=blue][color=green]
      > > recognize the question as being answered. For example, it would not
      > > recognize an answer of Bob Smith unless I put Bob_Smith which I don't[/color][/color]
      want[color=blue][color=green]
      > > to do. The answers in the example are all either 1 word or 1 number[/color]
      > answers[color=green]
      > > so I cannot tell from that how to do this. Can someone tell me what I[/color]
      > need[color=green]
      > > to do to be able to use multiple word answers without having to use an
      > > underscore? Thanks for your help.
      > >
      > > David[/color]
      >
      > I don't see the problem.
      >
      > The answers are merely hardcoded in the JavaScript :
      >
      > var aKey = new Array(3);
      > aKey[0]="distributive" ;
      > aKey[1]="1/3";
      > aKey[2]="24/99";
      >
      > Just include a space in your answer; for example,
      >
      > aKey[0]="distributi ve property";
      >
      > Note, you may have to be concerned with case sensitivity if you allow
      > free-form answers.
      >
      >[/color]


      Comment

      • Lasse Reichstein Nielsen

        #4
        Re: Javascript Quiz Code

        "C. David Rossen" <cdrossen@cdrma rketing.com> writes:
        [color=blue]
        > <input type="radio" name="q1" value="distribu tive property"
        > onClick=student Ans(1,"distribu tive property") >distributive property<br>[/color]

        This is incorrect HTML. You MUST quote attribute values that contain
        spaces for it to work. Otherwise, the value ends right after
        "distributi ve", giving syntactically incorrect Javascript as well.

        According to the HTML definition, you MUST quote attribute values that
        contain anything but letters, digits, and a few select types of
        punctuation. Browsers are more forgiving than the requirement, but still
        fails at spaces, greater-than signs, etc.

        For good coding practice, you SHOULD quote all attribute values. It saves
        yourself from having to remember the exceptions, and it is more stable
        in the cases where you make changes, like here.

        So:
        <label for="q1Id">
        <input type="radio" name="q1" id="q1Id" value="distribu tive property"
        onClick='studen tAns(1,"distrib utive property")'>dis tributive property
        </label></br>

        (use the label tag for the text associated with the radiobutton. Then you
        can click the text as well.)

        /L
        --
        Lasse Reichstein Nielsen - lrn@hotpop.com
        Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
        'Faith without judgement merely degrades the spirit divine.'

        Comment

        • Guy Roydor

          #5
          Re: Javascript Quiz Code



          C. David Rossen a écrit:[color=blue]
          > OK..when I change all instances of "distributi ve" to "distributi ve
          > property", it does not recognize the answer as a correct answer. Here are
          > the places where I changed it:
          >
          > aKey[0]="distributi ve property";
          >
          > <input type="radio" name="q1" value="distribu tive property"
          > onClick=student Ans(1,"distribu tive property") >distributive property<br>
          >
          > That choice is a correct answer, but along with the other two correct
          > answers, it is only giving me a 67% score instead of a 100% score so it is
          > not recognizing "distributi ve property" as a correct answer.
          >
          > Any ideas? Thanks.[/color]

          use method replace ex : string.replace( " ","#") in comparaison and
          inverse for display[color=blue]
          >
          >
          > "McKirahan" <News@McKirahan .com> wrote in message
          > news:vD1lb.5112 18$2x.222587@rw crnsc52.ops.asp .att.net...
          >[color=green]
          >>"C. David Rossen" <cdrossen@cdrma rketing.com> wrote in message
          >>news:O6WdnYSh xc1nAAmiRVn-jg@comcast.com. ..
          >>[color=darkred]
          >>>Hello:
          >>>
          >>>I found a script for a simple multiple choice quiz that I would like to
          >>>tailor to a quiz that I want to post on a website. The quiz I want to[/color]
          >>[/color]
          > use
          >[color=green][color=darkred]
          >>>can be found at :
          >>>
          >>>http://mtl.math.uiuc.edu/users/C2Schult/quiz2.html
          >>>
          >>>Here is my problem. I want to be able to use answers with more than one
          >>>word or number which requires spaces. When I tried doing that, it did[/color]
          >>[/color]
          > not
          >[color=green][color=darkred]
          >>>recognize the question as being answered. For example, it would not
          >>>recognize an answer of Bob Smith unless I put Bob_Smith which I don't[/color]
          >>[/color]
          > want
          >[color=green][color=darkred]
          >>>to do. The answers in the example are all either 1 word or 1 number[/color]
          >>
          >>answers
          >>[color=darkred]
          >>>so I cannot tell from that how to do this. Can someone tell me what I[/color]
          >>
          >>need
          >>[color=darkred]
          >>>to do to be able to use multiple word answers without having to use an
          >>>underscore ? Thanks for your help.
          >>>
          >>>David[/color]
          >>
          >>I don't see the problem.
          >>
          >>The answers are merely hardcoded in the JavaScript :
          >>
          >> var aKey = new Array(3);
          >> aKey[0]="distributive" ;
          >> aKey[1]="1/3";
          >> aKey[2]="24/99";
          >>
          >>Just include a space in your answer; for example,
          >>
          >> aKey[0]="distributi ve property";
          >>
          >>Note, you may have to be concerned with case sensitivity if you allow
          >>free-form answers.
          >>
          >>[/color]
          >
          >
          >[/color]

          Comment

          Working...