SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Calculator

Hybrid View

  1. #1
    Spam Can Kill!!! Disk-t's Avatar
    Join Date
    Jul 2001
    Location
    n/a
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Calculator

    I can't seem to find the error in this script. The error is "Object doesn't support this property or method" and is most likely in the "average" function:

    <script>
    function getit() {
    var attack = document.former.attack.value;
    var defense = document.former.defense.value;
    var strength = document.former.strength.value;
    var hits = document.former.hits.value;
    var magic = document.former.magic.value;
    var ranged = document.former.ranged.value;
    var prayer = document.former.prayer.value;

    var cooking = document.former.cooking.value;
    var woodcutting = document.former.woodcutting.value;
    var fletching = document.former.fletching.value;
    var fishing = document.former.fishing.value;
    var firemaking = document.former.firemaking.value;
    var crafting = document.former.crafting.value;
    var smithing = document.former.smithing.value;
    var mining = document.former.mining.value;
    var herblaw = document.former.herblaw.value;
    var quest = document.former.quest.value;

    if (attack == "" || defense == "" || strength == "" || hits == "" || magic == "" || prayer == ""){alert("You must fill ALL of the required text boxes!")}
    else{
    document.former.result.value=(((parseInt(attack) + parseInt(strength) + parseInt(defense) + parseInt(hits)) / 4) + (parseInt(magic) + parseInt(prayer)) / 8)

    }
    }
    function allstats() {
    var attack = document.former.attack.value;
    var defense = document.former.defense.value;
    var strength = document.former.strength.value;
    var hits = document.former.hits.value;
    var magic = document.former.magic.value;
    var ranged = document.former.ranged.value;
    var prayer = document.former.prayer.value;

    var cooking = document.former.cooking.value;
    var woodcutting = document.former.woodcutting.value;
    var fletching = document.former.fletching.value;
    var fishing = document.former.fishing.value;
    var firemaking = document.former.firemaking.value;
    var crafting = document.former.crafting.value;
    var smithing = document.former.smithing.value;
    var mining = document.former.mining.value;
    var herblaw = document.former.herblaw.value;
    var quest = document.former.quest.value;
    if (attack == "" || defense == "" || strength == "" || hits == "" || magic == "" || ranged == "" || prayer == "" || cooking == "" || woodcutting == "" || fletching == "" || fishing == "" || firemaking == "" || crafting == "" || smithing == "" || mining == "" || herblaw == "" || quest == "") {alert("You must fill ALL of the text boxes!")}
    else{
    document.former.total.value=parseInt(attack) + parseInt(defense) + parseInt(strength) + parseInt(hits) + parseInt(magic) + parseInt(ranged) + parseInt(prayer) + parseInt(cooking) + parseInt(woodcutting) + parseInt(fletching) + parseInt(fishing) + parseInt(firemaking) + parseInt(crafting) + parseInt(smithing) + parseInt(mining) + parseInt(herblaw) + parseInt(quest)
    }
    }

    function average() {
    var attack = document.former.attack.value;
    var defense = document.former.defense.value;
    var strength = document.former.strength.value;
    var hits = document.former.hits.value;
    var magic = document.former.magic.value;
    var ranged = document.former.ranged.value;
    var prayer = document.former.prayer.value;

    var cooking = document.former.cooking.value;
    var woodcutting = document.former.woodcutting.value;
    var fletching = document.former.fletching.value;
    var fishing = document.former.fishing.value;
    var firemaking = document.former.firemaking.value;
    var crafting = document.former.crafting.value;
    var smithing = document.former.smithing.value;
    var mining = document.former.mining.value;
    var herblaw = document.former.herblaw.value;
    var quest = document.former.quest.value;
    if (attack == "" || defense == "" || strength == "" || hits == "" || magic == "" || ranged == "" || prayer == "" || cooking == "" || woodcutting == "" || fletching == "" || fishing == "" || firemaking == "" || crafting == "" || smithing == "" || mining == "" || herblaw == "" || quest == "") {alert("You must fill ALL of the text boxes!")}
    else {
    document.former.average.value=((parseInt(attack) + parseInt(defense) + parseInt(strength) + parseInt(hits) + parseInt(magic) + parseInt(ranged) + parseInt(prayer) + parseInt(cooking) + parseInt(woodcutting) + parseInt(fletching) + parseInt(fishing) + parseInt(firemaking) + parseInt(crafting) + parseInt(smithing) + parseInt(mining) + parseInt(herblaw) + parseInt(quest)) / 17)
    }

    }

    </script>

    <form name="former">
    Attack: <input type="text" name="attack">
    <p>Strength: <input type="text" name="strength">
    </p>
    <p>Defense: <input type="text" name="defense">
    </p>
    <p>Hits: <input type="text" name="hits">
    </p>
    <p>Ranged: <input type="text" name="ranged">
    </p>
    <p>Prayer: <input type="text" name="prayer">
    </p>
    <p>Magic: <input type="text" name="magic">
    </p>
    <p>&nbsp;
    </p>
    <p>Cooking: <input type="text" name="cooking">
    </p>
    <p>Woodcutting: <input type="text" name="woodcutting">
    </p>
    <p>Fletching: <input type="text" name="fletching">
    </p>
    <p>Fishing: <input type="text" name="fishing">
    </p>
    <p>Firemaking: <input type="text" name="firemaking">
    </p>
    <p>Crafting: <input type="text" name="crafting">
    </p>
    <p>Smithing: <input type="text" name="smithing">
    </p>
    <p>Mining: <input type="text" name="mining">
    </p>
    <p>Herblaw: <input type="text" name="herblaw">
    </p>
    <p>Quest Points: <input type="text" name="quest">
    </p>


    <p>&nbsp;&nbsp;</p>


    <p> Fighting Stats: <input type="text" name="result">&nbsp; </p>
    <p>&nbsp;&nbsp;
    <p> Total Points: <input type="text" name="total"> </p>


    &nbsp;
    <p>Average: <input type="text" name="average">
    <br>


    </p>
    <p>


    <input type="button" name="sub" onClick="getit()" value="Calculate PK Level">
    <input type="button" name="sub2" onClick="allstats()" value="Calculate ALL Stats">
    <input type="button" name="sub3" onClick="average()" value="Calculate Average">

    </form>
    </p>

  2. #2
    Spam Can Kill!!! Disk-t's Avatar
    Join Date
    Jul 2001
    Location
    n/a
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    NVM

    Nevermind! Average is a reserved word!

  3. #3
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    That's why a personal naming convention is a good thing:

    calcAverage

    would have been great
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright


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
  •