Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Javascript document.write  (Read 3101 times)

0 Members and 1 Guest are viewing this topic.

stevener11

    Topic Starter


    Beginner
    Javascript document.write
    « on: January 23, 2010, 10:08:28 AM »
    Would someone look at this statement and let me know why it won't print. ???
    script type="text/javascript">

    var emissionyear = new Array(7);
    emissionyear(0) = "In 1980,";
    emissionyear(1) = "In 1985,";
    emissionyear(2) = "In 1990,";
    emissionyear(3) = "In 1995,";
    emissionyear(4) = "In 2000,";
    emissionyear(5) = "In 2002,";
    emissionyear(6) = "In 2003,";

    var emissionamount = new Array(7);
    emissionamount(0) = 18313.13;
    emissionamount(1) = 19430.24;
    emissionamount(2) = 21402.22;
    emissionamount(3) = 22034.54;
    emissionamount(4) = 23849;
    emissionamount(5) = 24464.92;
    emissionamount(6) = 25162.07;

    /* <![CDATA[ */
    document.write("<p>" + emissionyear(0) + "the world generated " + emissionamount(0) + " million metric tons of carbon dioxide emissions from fossil fuel consumption. </p>");
    document.write("<p>" + emissionyear(1) + "the world generated " + emissionamount(1) + " million metric tons of carbon dioxide emissions from fossil fuel consumption. </p>");
    document.write("<p>" + emissionyear(2) + "the world generated " + emissionamount(2) + " million metric tons of carbon dioxide emissions from fossil fuel consumption. </p>");
    document.write("<p>" + emissionyear(3) + "the world generated " + emissionamount(3) + " million metric tons of carbon dioxide emissions from fossil fuel consumption. </p>");                                                                                                                                                                      ;
    document.write("<p>" + emissionyear(4) + "the world generated " + emissionamount(4) + " million metric tons of carbon dioxide emissions from fossil fuel consumption. </p>");
    document.write("<p>" + emissionyear(5) + "the world generated " + emissionamount(5) + " million metric tons of carbon dioxide emissions from fossil fuel consumption. </p>");
    document.write("<p>" + emissionyear(6) + "the world generated " + emissionamount(6) + " million metric tons of carbon dioxide emissions from fossil fuel consumption. </p>");
    /* ]]> */
    SBE

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    Re: Javascript document.write
    « Reply #1 on: January 23, 2010, 10:10:30 AM »
    Arrays are indexed in javascript via square brackets ([]) rather then parentheses.
    I was trying to dereference Null Pointers before it was cool.

    kpac

    • Web moderator
    • Moderator


    • Hacker

    • kpac®
    • Thanked: 184
      • Yes
      • Yes
      • Yes
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 7
    Re: Javascript document.write
    « Reply #2 on: January 23, 2010, 10:14:25 AM »