JavaScript For Loops

Ask a Question related to Macromedia Dynamic HTML, Design and Development.

  1. #1

    Default JavaScript For Loops

    I think this is the correct forum;

    I'm used to using ActionScript, and I think thats where Im making my mistakes
    when scripting with Javascript.

    This is a simplified script of what I need. myNumber3 should output 10, yet
    nothing comes back. Can you see what I'm missing?

    for( x=0; x<5; x++){
    var myNumber[x]=10;
    alert (myNumber3);
    }

    Thanks

    jumpOnCommand

    jumpOnCommand Guest

  2. Similar Questions and Discussions

    1. Nested loops?
      Hi, I've been adapting a script which parses HTML and creates an RSS feed (http://www.perl.com/lpt/a/2001/11/15/creatingrss.html). Now I want...
    2. For While Loops
      Hello, Please, can anyone tell me what is the equivalent in CMFL. Thanks Graham Brown
    3. SQL OR CF loops?
      I'm hoping someone that actually knows what they are doing can assist me. I have a CFLOOP that simply spits out the contents of a table. Problem...
    4. Using 'my' within nested loops
      I am curious about the amount of overhead created with the first example below as compared to the second example below: Example 1: my $this;...
    5. [PHP] nested for loops
      your syntax is correct, just need to change for ($j=0: $j < 5; $j++) to for ($j=0; $j < 5; $j++) Anyone ever do a nested for loop? $i =0; $j...
  3. #2

    Default Re: JavaScript For Loops

    You never create a myNumber3 variable. Your syntax for creating the variable -
    myNumber[x] - is going to generate an array, with each element of the array set
    to 10. You could then have alert(myNumber[3]); however, the script will error
    out on the first loop, as the fourth element of the array (myNumber[3]) won't
    yet exist. Taking the alert out of the loop should work.



    robhuddles Guest

  4. #3

    Default Re: JavaScript For Loops

    You have to declare your variables and ( almost always ) initiate your
    arrays.

    function num(){
    var myNumber = [];
    for( var x=0; x<5; x++){
    myNumber[x]=10;
    }
    alert (myNumber[3]);
    }


    --
    Regards,
    ...Trent Pastrana
    [url]www.fourlevel.com[/url]






    "jumpOnCommand" <dchapman_4@btopenworld.com> wrote in message
    news:ei50rl$325$1@forums.macromedia.com...
    >I think this is the correct forum;
    >
    > I'm used to using ActionScript, and I think thats where Im making my
    > mistakes
    > when scripting with Javascript.
    >
    > This is a simplified script of what I need. myNumber3 should output 10,
    > yet
    > nothing comes back. Can you see what I'm missing?
    >
    > for( x=0; x<5; x++){
    > var myNumber[x]=10;
    > alert (myNumber3);
    > }
    >
    > Thanks
    >
    > jumpOnCommand
    >

    T.Pastrana - 4Level Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139