## Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

### Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

PLUS

# Javascript while loop challenge task 1 confusion

Q) In this challenge, you will create a while loop that prints to the document 26 times. We've added a variable named count, use it to track the number of times the loop runs. Don't forget to use the document.write() method inside the loop.

My code goes here :

```var count = 0;
while(count<26) {
count+=1;
document.write("Hello");
}
```

The code prints 26 lines of Hello and passes the challenge. In my code inside the loop, I have first incremented the counter by 1. Then below it is actual printing of Hello done. So, shouldn't the first value of counter be 1 inside the loop and print only 25 times since my while loop counts less than 26. But, I am not clear why is the first value of count 0 and not 1.

Can anybody explain it? Thanks

script.js
```var count = 0;
while(count<26) {
count+=1;
document.write(count);
}
```

It doesn't matter to the number of loops if you increment the count before the write or after the write.

What matters is that the count is tested (in the while) before it is incremented.

Your second piece of code is the perfect proof of what's happening. Even though your loop runs while count < 26, the write statement prints out numbers from 1 to 26. That's 26 numbers (including 26!).

Thank you Steven Parker . Can you provide the link to the resource where I can find information about how to use those cool pointers like you have written on the second line in your answer?

Sure thing. I have way too much fun with them myself

They can be found on the Emoji Cheat Sheet

Not all of them work here, but the vast majority do.

Hi Nicolas, thank you for reference. My real question was about how the first value of count becomes 0 and prints the first line when I increment in the first step as the value of count as 1. I figured out that even though I incremented value of count by 1, the printing is done when count = 0.

var count = 0; while(count<26) { count+=1; document.write(count); }