Results 1 to 18 of 18

Thread: [RESOLVED] New to javascript but...

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Resolved [RESOLVED] New to javascript but...

    This is an assignment. I know the rules about not doing people's assignments, but i do need help.

    I'm new to javascript (this is my very first script).

    I have the following code:

    <html>
    <head>
    <title>
    Heartrate calculation program
    </title>
    </head>

    <body bgcolor="#000000">
    <font color="#FFFFFF"><big>
    Please follow the prompts.

    <script>

    //Java goes here.

    function funcalculate (form)
    {
    var vage = form.agetxt.value;
    var vrhr = form.rhrtxt.value;
    var mhr = 0;
    var vpmhr = 0;
    var vcmhr = 0;
    var vlstc = 0;

    // Here is the calculations
    mhr = (220-vage);
    vcmhr = (vrhr-mhr);
    vpmhr = (1.60*vcmhr);
    vlstc = parseInt(vpmhr)+parseInt(vrhr);

    // alert (vlstc);
    funwritetopage(vlstc);
    }


    // document.write(vage);

    </script>
    <br>
    <br>
    <br>
    <FORM NAME="frmheartrate" ACTION="" METHOD="GET">Please enter your age: <BR>
    <INPUT TYPE="value" NAME="agetxt" VALUE="20"><P>
    Please enter your RHR (<b>R</b>esting <b>H</b>eart <b>R</b>ate):<br>
    <INPUT TYPE="value" NAME="rhrtxt" VALUE="70"><P>
    <INPUT TYPE="button" NAME="cmdcalculcate" Value="Calculate" onClick="funcalculate(this.form)">

    Your THR (<b>T</b>raining <b>H</b>eart <b>R</b>ate) is: <br>


    <script>

    funwritetopage(vvalue)
    {
    // document.write("HI!");
    document.write(vvalue);
    }

    </script>

    <br>
    <br>
    <br>
    Yeah.
    </big></font>
    </body>

    </html>
    Could someone please tell me why the bolded functions do not execute? I thought it had something to do with them both being in different script tags, but when i put them into the same one, nothing worked because the function that the button fires off is below the actual button.

    So if this is the case, then how do i make a 'global' sub that can be called such as what i'm trying to do.

    Also, i think the second problem is an error on my part but...
    If you enter in 20 into the age and 70 as the RHR you get -138.
    On the assignment sheet it says the answer should be 148.

    Here are the steps that say how it should be calculated:

    a) calculate the maximum heart rate as 220 – age,
    b) subtract the RHR from the maximum heart rate,
    c) multiply the result in step b) by 60% and then add the RHR.


    Is this an error on my part, or is the assignment sheet wrong?
    In the code you can see how i've coded this Look for the comment "Here are the calculations"
    Last edited by Slyke; Feb 15th, 2008 at 10:45 PM.

Posting Permissions

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



Click Here to Expand Forum to Full Width