www.webdeveloper.com
Results 1 to 7 of 7

Thread: Javascript Calculator

  1. #1
    Join Date
    Nov 2009
    Posts
    51

    Javascript Calculator

    I am making a Level calculator for a game.

    The only problem is, is that i cant figure out whats wrong.



    PHP Code:
    function fmtPrice(wos,kos
    {
    if (
    wos 0)
    {
    wos 1
    }
    result="";
    result += Math.floor(kos/try);
    return 
    result;
    }
    function 
    compute() {
    var 
    kddocument.forms[0].KOs.value;
    var 
    wddocument.forms[0].WOs.value;
    var 
    Level fmtPrice(wd,kd);
    document.forms[0].Level.value=Level;
    }
    function 
    resetIt() {
    document.forms[0].cost.value="0";
    document.forms[0].tax.value="0";

    New Code Edit.
    Last edited by Kevin's Dog; 12-07-2009 at 11:38 AM.

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,377

    Lightbulb

    Don't indicate what errors are, but my guess is here:
    Code:
    if (wos = 0)
    change to:
    Code:
    if (wos == 0)
    And let us know what happens.

  3. #3
    Join Date
    Nov 2009
    Posts
    51
    Quote Originally Posted by JMRKER View Post
    Don't indicate what errors are, but my guess is here:
    Code:
    if (wos = 0)
    change to:
    Code:
    if (wos == 0)
    And let us know what happens.

    Sorry about the No Errors.
    I dont have a javascript debugging program though D:

    I'll go and see what happens.

  4. #4
    Join Date
    Nov 2009
    Posts
    51
    I just tried that.

    Bottom left corner of my IE says Error on page.


    What should i do know?

    Do you think i should add in:
    Code:
    var Wsd = " " + wos
    ?

    Im not sure, this is my FIRST time experementing with javascript.

  5. #5
    Join Date
    Nov 2009
    Posts
    51
    I added a few "Touches" to my source code, and it STILL dont work.


    PHP Code:
    function fmtPrice(wos,kos
    result="";
    result += Math.floor(kos/try);
    if (
    result == "Infinity")
    {
    result "N0N";
    }
    else 
    {
    result += "/50";
    }
    return 
    result;
    }
    function 
    compute() {
    var 
    kddocument.forms[0].KOs.value;
    var 
    wddocument.forms[0].WOs.value;
    var 
    Level fmtPrice(wd,kd);
    var 
    Reply "Your PWning Level: " Level "/50";
    document.forms[0].Level.value=Level;
    }
    function 
    resetIt() {
    document.forms[0].WOs.value="0";
    document.forms[0].KOs.value="0";


  6. #6
    Join Date
    Apr 2006
    Location
    Houston
    Posts
    1,374
    Quote Originally Posted by Kevin's Dog View Post
    ...I dont have a javascript debugging program though....
    If you have Firefox install the Firebug pluggin - it is the best JavaScript debugger out right now.

    OR

    If you have IE8 just hit F12 to bring up "IE Developers Tools", click on the script tab and start debugging.

    P.S.
    Code:
            function fmtPrice(wos,kos)
    Has no starting "{" to enclose the function

    AND in

    Code:
    result += Math.floor(kos/try);
    The variable "try" is never defined to be anything AND "try" is a reserved JavaScript keyword (try/catch statement - http://www.w3schools.com/js/js_try_catch.asp)

  7. #7
    Join Date
    Nov 2009
    Posts
    51
    Quote Originally Posted by slaughters View Post
    If you have Firefox install the Firebug pluggin - it is the best JavaScript debugger out right now.

    OR

    If you have IE8 just hit F12 to bring up "IE Developers Tools", click on the script tab and start debugging.

    P.S.
    Code:
            function fmtPrice(wos,kos)
    Has no starting "{" to enclose the function

    AND in

    Code:
    result += Math.floor(kos/try);
    The variable "try" is never defined to be anything AND "try" is a reserved JavaScript keyword (try/catch statement - http://www.w3schools.com/js/js_try_catch.asp)

    Thanks, but now This part of the code is woriking incorrectly.

    Code:
    function resetIt() {
    var Blah= "0/50"
    document.forms[0].WOs.value="0";
    document.forms[0].KOs.value="0";
    document.forms[0].Level.value=Blah;
    }
    The Level TextBox remains blank.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles