Web Analytics Made Easy -
StatCounter function script not working - CodingForum

Announcement

Collapse
No announcement yet.

function script not working

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • function script not working

    Can anyone tell me what is wrong with this script it's tearing my hair out. As you can probably guess by the code I'm a beginner.

    All help appreciated.
    Cheers
    Paul

    <html>
    <head>
    <script>
    <!--
    var numCorrect=0;

    function takeTest() {
    var response="";
    var points=0;

    var q1 = "What is the price of the Teak Elephants?";
    var a1 = "$55.00";

    var q2 = From what type of wood is the lion carved?";
    var a2 = "EBONY";

    var q3 = "What is the last name of both carvers on this page?";
    var a3 = "MANE";

    response = prompt(q1,"$0.00");
    if (response) points=runningTotal ((response==a1) ? 1 : 0);
    alert(points);

    response = prompt(q2,"");
    if (response) points=runningTotal ((response.toUpperCase()==a2) ? 1 : 0);
    alert(points);
    response = prompt(q3,"");
    if (response) points=runningTotal((response.toUpperCase()==a3) ? 1 : 0);
    alert("You answered a total of " + points + " correctly.");
    numCorrect = 0;
    points = 0;
    }

    function runningTotal(i) {
    numCorrect += i;
    return numCorrect;

    }

    //-->
    </script>

    </head>

    <form>
    <input type="button" class="button" value="Quiz" onClick="takeTest();">
    </form>


    </body>
    </html>

  • #2
    it's ok i've sorted it

    -

    Comment


    • #3
      Put an opening quotation mark before "From" on q2.

      Also (as a matter of coding practices), you don't need the form tags. You should add a <body> tag. You don't need the class attribute on the input. And you could give your input a name attribute.

      Comment


      • #4
        Also (as a matter of coding practices), you don't need the form tags.
        Actually, you should have the form tags. NS requires it to display the form.

        Comment


        • #5
          thanks

          I was wondering that myself

          Comment


          • #6
            I stand corrected.

            Comment


            • #7
              sorry to be a pain

              But can anybody spot why this also isn't working?
              Can you also tell me what you all use as an editor when you are coding?

              Many thanks
              Paul

              <html>
              <head>

              <script language = "Javascript">
              <!--

              function returnValue() {
              var sampleVar;
              sampleVar = document.myForm.input1.value * document.myForm.input2.value;
              return sampleVar;
              }
              //-->
              </script>
              </head>

              <body>

              <form name="myForm">
              Multiply <input type="text" name="input1">
              By <input type="text" name="input2">
              <input type ="button" value="Result"
              onClick=
              "alert(The result is ' + returnValue() + '.');">
              </form>

              </body>
              </html>

              Comment


              • #8
                Why not try this:

                Code:
                <html> 
                <head> 
                
                <script language = "Javascript"> 
                <!-- 
                
                function returnValue() { 
                var sampleVar; 
                sampleVar = document.myForm.input1.value * document.myForm.input2.value; 
                alert("Result is: " + sampleVar);
                } 
                //--> 
                </script> 
                </head> 
                
                <body> 
                
                <form name="myForm"> 
                Multiply <input type="text" name="input1"> 
                By <input type="text" name="input2"> 
                <input type ="button" value="Result" onClick="returnValue();"> 
                </form> 
                
                </body> 
                </html>
                I use Edit+2, the best darn editor there is!

                Comment

                Working...
                X