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

David Enus
David Enus
646 Points

The document.write method wasn't called? Please help me to understand this statement.

I am not understanding how to correct this statement. The document.write method wasn't called?

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

2 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,004 Points

Hi David,

It looks like you're trying to write the contents of the counter variable to the screen ,but all that would happen here is you'd get 26, written out 25 times.

But there's a few things you need to do here and you only need the one count variable

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

First, you need to use a while expression that tests the count variable. You don't need to make a new variable.

Then, to make sure the value always changes until the expression becomes true, as you correctly guessed you use an operator to increment the value

Finally, document.write wasn't being called because you were passing in a string the code didn't know what to do with.

All you do is pass in the count variable as its argument.

Hope this helps! :-)

David Enus
David Enus
646 Points

Thank you so much, that makes understanding it so much simpler. Have a great day