Submit Your Article Forum Rules

Results 1 to 5 of 5

Thread: branch condition statement if...else

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    2

    branch condition statement if...else

    Hi can anyone please help me solve this problem?

    Using branch condition statement if n<=30, use onclick event to call the function and display the calculation result;
    otherwise, display the message: “Please input a number between 0 to 30!”

    Many thanks in advance



    <head><title></title>

    <script language=javascript type=text/javascript>



    <!--



    function calculation() {



    var yourNumber = window.prompt("Enter a number","");

    if (yourNumber == "n<=30"){

    alert(result);

    }else{

    document.write("Please input a number between 0 to 30!<BR>");

    }





    //--->

    </script>

    </head>

    <body>



    <form>

    Input:<INPUT TYPE=TEXT NAME="inpt" SIZE=20 >


    <BR><BR><input type="button" value="Calculate" onClick="calculation()">

    </form>



    </body>

    </html>

  2. #2
    WebProWorld MVP williamc's Avatar
    Join Date
    Jul 2003
    Location
    On a really big hill in Kentucky
    Posts
    4,721
    I hope your joking here, or I am missing something....

    if (yourNumber == "n<=30"){

    if (yourNumber <= 30){
    William Cross
    Web Development by Those Damn Coders
    Firearm Friendly Websites because our constitution matters

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Location
    Hong Kong
    Posts
    17
    You if statement should be:

    if (yourNumber <=30) && (yourNumber >= 0 ){
    alert(result);
    }

    You may also want to check if the yourNumber is indeed a number and not a text string.
    Last edited by hk2011; 11-14-2011 at 08:19 PM.
    Academy Sigma Maths Tutors Hong Kong | Tuition, Exam Prep, Learning Support
    Articles, Tips and Lessons

  4. #4
    Banned
    Join Date
    Nov 2011
    Location
    India
    Posts
    3
    Hi There !

    No, even if the number choosen is negative ,message should be displayed but the problem is that variable is not defined .
    Last edited by deepsand; 11-25-2011 at 06:48 PM. Reason: removed faux Signature

  5. #5
    WebProWorld MVP deepsand's Avatar
    Join Date
    May 2004
    Location
    State College, PA
    Posts
    16,446
    Quote Originally Posted by RXR Stroke View Post
    No, even if the number choosen is negative ,message should be displayed but the problem is that variable is not defined .
    Did anyone say otherwise?

Tags for this Thread

Posting Permissions

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