Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2002
    Location
    South East Queensland
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question ONCLICK="check()" problems

    How come when I put the correct answer into the text box it comes up with "No. Please try again."?

    Code:
    <HTML>
    
    <HEAD>
    <TITLE></TITLE>
    <META NAME="GENERATOR" CONTENT="Sothink HTML Editor">
    <SCRIPT LANGUAGE="JavaScript">
    var answer,		//
    number1,		//
    number2;		//
    
    number1 = Math.round(1+Math.random()*10);
    number2 = Math.round(1+Math.random()*10);
    
    //Prompting the user 
    window.alert("How much is " + number1 + " times " + number2 + " ?");
    
    function check() {
    //Calculating the answer
    answer = number1 * number2;
    
    //If answer is correct
    if (studentAnswer == answer) {
    window.status = "Very good!";
    }
    
    //If answer is wrong
    if (studentAnswer != answer) {
    window.status = "No. Please try again.";
    }
    }
    
    function newQuestion(){
    number1 = Math.round(1+Math.random()*10);
    number2 = Math.round(1+Math.random()*10);
    //Prompting the user 
    window.alert("How much is " + number1 + " times " + number2 + " ?");
    }
    </SCRIPT>
    </HEAD>
    
    <BODY>
    <CENTER>
    <FORM NAME="studentAnswer">
    <INPUT NAME="Submit your answer:" TYPE="text">
    <INPUT TYPE="button" VALUE="Submit" ONCLICK="check()">
    </FORM>
    </CENTER>
    </BODY>
    </HTML>

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Code:
    <HTML>
    <HEAD>
    <TITLE></TITLE>
    <META NAME="GENERATOR" CONTENT="Sothink HTML Editor">
    <SCRIPT LANGUAGE="JavaScript">
    var answer,		//
    number1,		//
    number2;		//
    
    number1 = Math.round(1+Math.random()*10);
    number2 = Math.round(1+Math.random()*10);
    
    //Prompting the user 
    window.alert("How much is " + number1 + " times " + number2 + " ?");
    
    function check() {
    //Calculating the answer
    answer = number1 * number2;
    
    studAnswer = document.studentAnswer.ans.value;
    
    //If answer is correct
    if (studAnswer == answer) {
    window.status = "Very good!";
    }
    //If answer is wrong
    else if (studAnswer != answer) {
    window.status = "No. Please try again.";
    }
    }
    
    function newQuestion(){
    number1 = Math.round(1+Math.random()*10);
    number2 = Math.round(1+Math.random()*10);
    //Prompting the user 
    window.alert("How much is " + number1 + " times " + number2 + " ?");
    }
    </SCRIPT>
    </HEAD>
    
    <BODY>
    <CENTER>
    <FORM NAME="studentAnswer">
    <INPUT NAME="ans" TYPE="text">
    <INPUT TYPE="button" VALUE="Submit" ONCLICK="check()">
    </FORM>
    </CENTER>
    </BODY>
    </HTML>

  • #3
    New to the CF scene
    Join Date
    Oct 2002
    Location
    South East Queensland
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks problem solved!


  •  

    Posting Permissions

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