1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Learning javascript. What's wrong with the looping?

Discussion in 'Web Design & Development' started by turbow5, Jul 31, 2012.

Thread Status:
Not open for further replies.
Advertisement
  1. turbow5

    turbow5 Thread Starter

    Joined:
    Jan 2, 2012
    Messages:
    490
    It says line 1 is wrong but I'm just not seeing it.
     

    Attached Files:

  2. Ent

    Ent Josiah Trusted Advisor

    Joined:
    Apr 11, 2009
    Messages:
    5,407
    That would be because you're completely messing up the for syntax.

    There are 3 components to a for loop:
    Where it starts,
    Where it stops,
    and how fast it goes.

    The three should be separated by commas.

    For example, this should log the even numbers up to 10.

    for (number=2; number<10; number=number + 2){
    console.log(number);
    }
     
  3. turbow5

    turbow5 Thread Starter

    Joined:
    Jan 2, 2012
    Messages:
    490
    Can you give me another example to go off of? This looping part isn't clicking with my brain. Also can you use "number" instead of 'counter"?
     
  4. Ent

    Ent Josiah Trusted Advisor

    Joined:
    Apr 11, 2009
    Messages:
    5,407
    "number" and "counter" are just variable names. You could use "i", "bill", or "aojfaeji" if you wanted to.

    Remember it's got 3 parts:
    for (What value the variable has at the start ; When the loop should stop ; How the variable changes each time){
    }

    The code that you need to execute goes inside the {}
     
  5. janikPilot

    janikPilot

    Joined:
    Nov 26, 2010
    Messages:
    141
    I believe this link should be of some help to you:

    www.w3schools.com/js/js_loop_for.asp

    It is important that you learn terms like increment and counter so you can better understand your code.

    And by the way - In the above post, he meant semicolons, not commas :p
     
  6. Ent

    Ent Josiah Trusted Advisor

    Joined:
    Apr 11, 2009
    Messages:
    5,407
    Woops. :eek:
     
  7. turbow5

    turbow5 Thread Starter

    Joined:
    Jan 2, 2012
    Messages:
    490
    I'll just come back to this another time. Maybe with more knowledge on how JavaScript works I can get that loop in my head, It just doesn't click.

    Thanks for help though, It will be a reference.
     
  8. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1063298