SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Hybrid View

  1. #1
    PHP Developer W1LL's Avatar
    Join Date
    Apr 2001
    Location
    Leicester, UK
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    For anyone who knows JS and VBS

    Code:
    <script language="VBScript">
    dim i
     For i = 104 to 101 Step -1
      document.write("Number:" & i & "<br /><br />")
     Next
    </script>
    I need the same effect with JavaScript. The numbers must go down from 104 to 101. Not from 101 to 104. This is essential.

    - Will

  2. #2
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do it as you normally would, but instead of making i equal 104 to 101 (which you can't do, most likely), make it equal to 0 through 3. Then just subtract i from 104.

  3. #3
    PHP Developer W1LL's Avatar
    Join Date
    Apr 2001
    Location
    Leicester, UK
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, I need it to print out like this, for example:

    Number: 4
    Number: 3
    Number: 2
    Number: 1
    Number: 0

    What you are saying to do prints out like this:

    Number: 0
    Number: 1
    Number: 2
    Number: 3
    Number: 4

    - Will

  4. #4
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:

    Code:
        for (var i = 104; i >= 101; i--) {
          document.write("Number: " + i + "<br /><br />")
        }

  5. #5
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you misunderstood what I'm saying.

    my $i = 0;
    while($i <= 3) {
    print 'Number: '.(104 - $i)."\n";
    $i++;
    }

    That prints out:
    Number: 104
    Number: 103
    Number: 102
    Number: 101

    Adapt that to JS. Should be pretty easy. I just used Perl because I don't really know JS...but the concepts are the same.

  6. #6
    PHP Developer W1LL's Avatar
    Join Date
    Apr 2001
    Location
    Leicester, UK
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    TWTCommish: Thanks, that works perfect.

    qslack: Thanks for your effort, but I tried the JS and it didnt work. I just got an error.

    - Will

  7. #7
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by W1LL
    qslack: Thanks for your effort, but I tried the JS and it didnt work. I just got an error.
    Well...whatever. The code I wrote was in Perl. But I'm glad you found a solution.

  8. #8
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, yeah, of course his code didn't work. (Quinn: learn JS! It's easy. Perl is boring in comparison at times). Glad I could help though.


Bookmarks

Posting Permissions

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