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

Help. I can't call the document.write more than 1 time. Almost any way I try to fix it comes back with an error.

I'm stuck on adding the document.write to the code. All the ways I have tried have either said error or that it was only called once.

pi R
pi R
12,720 Points

Hi ! Show us your code so we can look at it !

This is my code:

var count = 0; while ( count > 26) { count =+1; }

3 Answers

Julian Aramburu
Julian Aramburu
11,368 Points

Hey Madison! As pi R suggested, paste your code here so we can help you out! However on this challenge you are asked to create a while loop that prints using document.write() something 26 times, and you are hinted to use var count = 0; in order to track the times that the loop runs, are you familiar with while loops? are you having problems coding the while loop?

var count = 0; while ( count > 26) { count =+1; }

pi R
pi R
12,720 Points

Well, you're asking it to do the loop while count is SUPERIOR to 26. But count = 0.. so it will never run ! And you need to put document.write() inside your loop {} !

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

My problem is that I don't know where to put the document.write in my loop.

pi R
pi R
12,720 Points

the parentheses () are only to evaluate the condition, so yeah you put the count < 26 in this. The code you want to run while the condition is true needs to be inside the curly braces { }

Julian Aramburu
Julian Aramburu
11,368 Points

You want to document.write() while count is less than 26 so check that! You already added what will break the while loop with count = + 1 , so you only have to execute document.write inside your while loop :).

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

I got this, I just don't know where the document.write is supposed to go in the while loop.

Julian Aramburu
Julian Aramburu
11,368 Points

inside the while loop curly braces

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

in a while loop you set the condition for the loop to run between the parentesis () and inside the curly braces {} you set what the loop would run if the condition is met... also you need to add something that will cause the loop to break eventually or you will create an infinite loop that will crash your browser. In this case, you are setting the next condition = "do something while count is less than 26" , if that condition is met then the document.write() runs and count gets 1 ...that last part the count += 1 is what will cause the loop to break because at some point count will be greater than 26 so the loop won't run.