Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops Create a while Loop

Don't understand why document.write() is not being called...

Hi,

I'm really not sure what I am getting wrong here. I get the following message: Bummer: The document.write() method wasn't called.

Can anyone solve this please and explain why?

Thank you!

script.js
var count = 0;
while (count > 26) {
 document.write("Testing Loops");
}

I realised I needed to add:

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

but it is still not working

2 Answers

hello kit the loop doesn't run because you are saying that count is greater than 26 which is false because count = 0

and then you have to increase count before you print it to the page. if you print it to the page and then increase it. then the first time the loop runs count is going to be 0 and when the loop ends count is going to be 25 not 26;

var count = 0;

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

hope this helps

Hi Anthony,

Oh now I understand! Thank you so much!