www.webdeveloper.com
Results 1 to 6 of 6

Thread: JavaScript n00b in dire need of help

  1. #1
    Join Date
    Feb 2009
    Posts
    2

    JavaScript n00b in dire need of help

    Hey guys

    so I'm taking an online JavaScript class at school, but unfortunately, I don't find our textbook very useful, and have been struggling with a lot of stuff in there, largely due to the fact that much guesswork is expected at the end of the chapters on the assignments (Course Technology's )New Perspectives on JavaScript. I don't find guessing to be a very effective learning method, so without further ado, here's the situation.

    The assignment involves basic concepts around using arrays, and the for and while loops. We were supposed to create a database of contact information by inserting an external .js file, and using the arrays from that. Most of this is complete, but I'm stuck trying to figure out how to do the last part here, which is to try and return a numeric value in a side table from a for loop..

    Here is the function part of it in question...

    _______________________________
    <title>The Lighthouse</title>
    <link href="lhouse.css" rel="stylesheet" type="text/css" />
    <script src = "list.js" type = "text/javascript"></script>
    <script type = "text/javascript">

    function amountTotal() {

    var total = 0;

    for(var i=0; i<amount.length;i++);

    {

    total = amount[i];

    }

    return total;

    }
    </script>
    </head>
    ________________________________________

    And here is the table in which the value is supposed to be written.
    ________________________________________

    <div id="totals">
    <script type = "text/javascript">

    document.write ("<table border='1' rules = 'rows' cellspacing='0'>");

    document.write ("<tr>");

    document.write ("<th id='sumTitle' colspan='2'>");

    document.write ("Summary");

    document.write ("</th>");

    document.write ("</tr>");

    document.write ("<tr>");

    document.write ("<th>Contributors</th>");

    document.write ("<td>"+contributions+"</td>");

    document.write ("</tr>");

    document.write ("<tr>");

    document.write ("<th>Amount</th>");

    document.write ("<td>"+total+"</td>");

    document.write ("</tr>");

    document.write ("</table>");

    </script>

    </div>

    </body>
    </html>
    _________________________________

    If it helps, I get an error message in the file saying that "total" and "contributions" is not defined.

    (This is the only text in the file concerning my problem, so I didn't bother posting the whole thing)

    Help?

  2. #2
    Join Date
    Jan 2009
    Posts
    3,346
    From what you posted all I can tell you is that those two variables are not being defined.

  3. #3
    Join Date
    Feb 2009
    Posts
    2
    Yeah, unfortunately, the book isn't very clear on what to do :/ There's a step listed about declaring the total variable, but that's about all they're willing to tell you.

  4. #4
    Join Date
    Jan 2009
    Posts
    3,346
    Is that all the code you have?

  5. #5
    Join Date
    Feb 2009
    Posts
    36
    erm... what's inside list.js? amount array should be defined there...

  6. #6
    Join Date
    Sep 2008
    Location
    On the Interweb
    Posts
    125
    As you find your textbook to be vague in explanations, you may want to suppliment your book/class teachings with an online tutorial or two.

    Such as:
    http://www.w3schools.com/js/default.asp
    http://www.tizag.com/javascriptT/index.php
    http://www.htmlgoodies.com/primers/jsp/

    Even if you don't want to go through whole tutorials, you may at least find explanations of a particular aspect to be helpful.
    "Why must I be surrounded by frikkin' idiots?!" - Dr. Evil

    "Remember: There are no stupid questions, only stupid people." - Mr. Garrison

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