Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Web Design & Development Web Design & Development
Search Search
Search for:
Tech Support Guy > > >

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


(!)

turbow5's Avatar
turbow5 turbow5 is offline
Computer Specs
Member with 470 posts.
THREAD STARTER
 
Join Date: Jan 2012
Experience: Intermediate
31-Jul-2012, 11:48 AM #1
Solved: Learning javascript. What's wrong with the looping?
It says line 1 is wrong but I'm just not seeing it.
Attached Thumbnails
Solved: Learning javascript. What's wrong with the looping?-javascript-code.png  
Ent's Avatar
Ent   (Josiah) Ent is offline Ent is a Trusted Advisor with special permissions.
Computer Specs
Trusted Advisor with 5,217 posts.
 
Join Date: Apr 2009
Location: United Kingdom
Experience: Intermediate
31-Jul-2012, 04:18 PM #2
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);
}
turbow5's Avatar
turbow5 turbow5 is offline
Computer Specs
Member with 470 posts.
THREAD STARTER
 
Join Date: Jan 2012
Experience: Intermediate
01-Aug-2012, 10:14 AM #3
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"?
Ent's Avatar
Ent   (Josiah) Ent is offline Ent is a Trusted Advisor with special permissions.
Computer Specs
Trusted Advisor with 5,217 posts.
 
Join Date: Apr 2009
Location: United Kingdom
Experience: Intermediate
01-Aug-2012, 10:20 AM #4
"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 {}
janikPilot's Avatar
janikPilot   (Michael) janikPilot is offline
Computer Specs
Member with 141 posts.
 
Join Date: Nov 2010
Location: South FL
Experience: Advanced
01-Aug-2012, 04:06 PM #5
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
Ent's Avatar
Ent   (Josiah) Ent is offline Ent is a Trusted Advisor with special permissions.
Computer Specs
Trusted Advisor with 5,217 posts.
 
Join Date: Apr 2009
Location: United Kingdom
Experience: Intermediate
01-Aug-2012, 04:08 PM #6
Quote:
Originally Posted by janikPilot View Post
And by the way - In the above post, he meant semicolons, not commas
Woops.
turbow5's Avatar
turbow5 turbow5 is offline
Computer Specs
Member with 470 posts.
THREAD STARTER
 
Join Date: Jan 2012
Experience: Intermediate
06-Aug-2012, 12:28 AM #7
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.
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
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.


Tags
javascript looping

(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑