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.

Start your free trial

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,253 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