Results 1 to 3 of 3

Thread: Coding for Calculating Exponents?

  1. #1
    Join Date
    Jan 2005
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Coding for Calculating Exponents?

    I'm trying to create a little calculator for myself that will calculate a baseball team's expected win-loss record.

    The formula is (Runs Scored per game + Runs Allowed per game) ^ .287

    Since I don't have their runs scored/allowed per game, but I do have their total runs scored/allowed, I'm just going to add those together and divide it by the number of games they've played.

    If you don't understand baseball, that probably doesn't make much sense, but I feel I'm pretty close to having this working, and I feel I know where my errors lie, but I'm not sure how to correct them.

    Here's what I have:

    Code:
    <html>
    
    <head>
    
    SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    function solvepy(form) {
    a = parseInt(form.a.value);
    b = parseInt(form.b.value);
    d = parseInt(form.d.value);
    form.c.value = Math.pow(((a+b)/d), .287)
    }
    //  End -->
    </script>
    
    </head>
    
    <body>
    <a href="http://www.hardballtimes.com/main/statpages/glossary/#pyth" target="newwin">PythagenPat</a><br><br>
    (Runs Scored per Game + Runs Allowed per Game) ^ .287<br><br>
    
    In short, (RS/G+RA/G)^.287<br><br>
    
    <form>
    <input type=text name=a size=5> - Total Runs Scored<br>
    <input type=text name=b size=5> - Total Runs Allowed<br>
    <input type=text name=d size=5> - Total Games Played
    <br><br>
    <input type=button value="Calculate PWL" onClick="solvepy(this.form)">
    <br><br>
    <input type=text name=c size=5> - PWL
    
    </form>
    
    </body>
    
    </html>
    The bolded part is where I think my problems lie.

    Thanks for any help that you can provide.

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    You haven't mentioned whether you get any error or you are looking for a checking of your output.

    If you look at the source code you've provided

    Code:
    SCRIPT LANGUAGE="JavaScript">
    You missed one "<" which must be

    Code:
    <SCRIPT LANGUAGE="JavaScript">
    or
    Code:
    <script type="text/javascript">
    I don't know baseball

  3. #3
    Join Date
    Jan 2005
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I just forgot to include that bracket when I was copying. It's there in my file.

    Everything works, except I don't think it's calculating correctly, which is why I think the error is with the part I bolded.

    I'm not sure if I should include all those parentheses, or if I can Math.pow multiple variables (like a+b/d), etc.

    I have no clue about JavaScript... I just wanted to make this for my own convenience.

    Thanks.

    EDIT: Well, I got it... but for a different calculation. I did a different Pythagorean formula for calculating a baseball team's expected win-loss record, and here's how I did it... hopefully I can learn from it, and maybe some other people will, too.

    The problem was in the part I bolded above.

    Code:
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    function solvepy(form) {
    a = parseInt(form.a.value);
    b = parseInt(form.b.value);
    form.c.value = (Math.pow(a,1.83)/(Math.pow(a,1.83)+Math.pow(b,1.83)))
    }
    //  End -->
    </script>
    I had to Math.pow separately.

    EDIT: How would I round the following to three digits? I tried the Math.round, multiply by 1000, divide by 1000 thing, but it just screwed the whole thing up.

    Code:
    form.c.value = (Math.pow(a,1.83)/(Math.pow(a,1.83)+Math.pow(b,1.83)))
    Code:
    form.j.value = (Math.pow(a,i)/(Math.pow(a,i)+Math.pow(b,i)));
    Last edited by UltraMegaOK1988; 07-30-2007 at 01:00 PM. Reason: Updating

Bookmarks

Posting Permissions

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