Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
hello,
i want to make a program that counts numbers from left to right.
i'm not sure which loops to use and how, i was thinking of using a for loop in a for loop statement that prints to the webpage (document.write();)

What I have tried:

JavaScript
for(var i=0;i <=10;i++){
   for(var i=0;i <=10;i++){
     document.write('the number is: ' + i);
    }
}
Posted
Updated 29-Oct-18 20:07pm

1 solution

Not sure what numbers you exactly want to count, but the total loop count is in your case:

JavaScript
for(var i=0;i <=10;i++){
   for(var j=0;j <=10;j++){
     document.write('the number is: ' + (i + j));
    }
}


Your initial code snipet looks wrong because you use i in the outer and inner loop which means that your loops will never end. You even declare i twice weach means that your runtime environment should throw an error without executing the code...

It would be good if you could explain better what numbers you want to count in order to get a better suggestion on how to count them ...
 
Share this answer
 
Comments
Eduardo Lane 30-Oct-18 17:54pm    
hello thanks Dirk for the code but what i want is that when the first loop counts to 10 that the second loop prints 1 until it reaches 10 and that the output is:
1 the number is 1

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900