77 users online (1 members and 76 guests)  

Thread: quest(ion)


  Results 1 to 7 of 7

Related

  1. background graphic quest.    Forum: Graphics Forum
    Replies: 10
  1. #1
    RnB's Avatar
    New User

    Status
    Offline
    Join Date
    Jun 2004
    Location
    nomad
    Posts
    4

    quest(ion)

    i need to do some math, and i decided the qiuckest way i knew of doing this
    (of course there are other ways. microsoft money could propobly do it, but this is more fun)
    was with javascript, now ive found that, in my case, its not...

    im not giving up though, since i figure ill need this soon (id like to learn to wright javascript).
    But this irritates me, i cant get it to work... ive tried... it may be a simple mistake...
    anyways i figure ill put the lot(script) here (including html, just in case...':/)

    <html>

    <title>
    my money
    </title>

    <head>
    <script language="JavaScript">

    //wow, even notepad has smilies

    <!--
    variable=0
    //-->

    </script>
    </head>

    <body>
    <script language="JavaScript">

    <!--
    for (count=0; count<52; count++)
    { variable+90; variable*1.05 }

    document.write("you have "+variable+"$ on your account.");
    //-->
    </script>


    </body>

    </html>

    now as you may have guessed i dont want "you have 0$ on your account." to be displayed in my browser

    (im using notepad and MSIE, in case you need to know...)

    what have i done wrong?
    Last edited by RnB; 06-16-2004 at 04:11 PM.

  2. #2
    coothead's Avatar
    bald headed old fart

    Status
    Offline
    Join Date
    Aug 2003
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    732
    Hi there RnB,

    and a warm welcome to these forums

    Looking through your code I was not entirely certain
    what it was that you were trying to achieve, but old coothead
    is always willing to hazard a guess

    So try this for size...
    Code:
    <html>
    <head>
    <title>my money</title>
    
    <script type="text/javascript">
    <!--
    function calc() {
        var i;
        var allowance='90.00';
    for(i=0;i<52;i++) {
        document.write("You have $ <span style='font-weight:bold;color:#0000ff;'> "+allowance+"</span> on your account.<br /><br />");
        allowance=parseFloat(allowance*1.05).toFixed(2);
     }
        document.write("<span style='font-size:56px;color:#ff0000'>Now ain\'t that cool</span>");
    }
    onload=calc;
    //-->
    </script>
    
    </head>
    <body>
    </body>
    </html>
    If it is not what you were after try and change it...then come back if you have problems

    coothead

  3. #3
    RnB's Avatar
    New User

    Status
    Offline
    Join Date
    Jun 2004
    Location
    nomad
    Posts
    4
    thx for replying ^^

    something (an error of mine) that might have confused you is
    that the variable "variable" and the variable "allowance" are
    identical (or suposed to be ><)(i have fixed this now)

    your codes result was partly what i was trying to achive
    but i would like to know why my own did'nt work, it may not be as fancy,
    but from what i understand, important to know

    what i was trying to achive with this code,
    was to add 90 to a variable, and then add 5%, +90 again, +5%
    and for this to repeat it self (so i used a loop)
    Last edited by RnB; 06-16-2004 at 04:20 PM.

  4. #4
    coothead's Avatar
    bald headed old fart

    Status
    Offline
    Join Date
    Aug 2003
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    732
    Hi there RnB,

    Declare a variable like this...

    var allowance='90.00';

    What you want the 'for statement' to execute must be placed within curly braces like this...
    Code:
    for(i=0;i>52;i++)  {
    
    document.write("my variable is "+allowance+" dollars<br />");
    
     }
    The <br /> is included so that the document.write is executed on a new line at each count


    coothead

  5. #5
    RnB's Avatar
    New User

    Status
    Offline
    Join Date
    Jun 2004
    Location
    nomad
    Posts
    4
    u misunderstand

    i want javascript to add 90 to a variable and then add 5%, 52 times.
    this would take some time with a calculator...
    so where you told the script to wright a tekst, i want it to do math,
    add 90 and add 5% to a variable, i only need the tekst once.

    the reason i need this, is that for complicated reasons i havent been told how much money i have,
    for several years... this is provoking...

  6. #6
    coothead's Avatar
    bald headed old fart

    Status
    Offline
    Join Date
    Aug 2003
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    732
    but i would like to know why my own did'nt work,

    This is not a case of my misunderstanding.
    You asked me why your' code did not work ' ( sic ) and that is what I pointed out.

    The code that I gave you originally, adds 5% compound interest to a principal sum of $90.00, fifty one times

    Of course, you may have a differrent definition of compound interest to mine
    Here is the code for compound interest...
    Code:
    <script type="text/javascript">
    <!--
        var startPrincipal=90.00;
        var interest=5;
        var period=51;
        var finishPrincipal=parseFloat(startPrincipal*Math.pow((1+interest/100),period)).toFixed(2);
        document.write("$ "+startPrincipal+" grows to $ "+finishPrincipal+" after  "+period+" (weeks/months/years or whatever !)");
    //-->
    </script>


    coothead

  7. #7
    RnB's Avatar
    New User

    Status
    Offline
    Join Date
    Jun 2004
    Location
    nomad
    Posts
    4
    i am sorry

    will you please show me how to do what i have asked with the use of a statement? (well, at least nothing more advanced
    this should be possible, right?)
    i'd like to learn these properly before objects and functions.



Tags for this Thread