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 trialMUZ140884 Maxwell Makumucha
6,291 Pointswhy document.write may not be called in js file ? help
help me to make the code run and prints something 26 times on the document.write
var count = 0;
while (counter < 26){
var counter= counter (26);
document.write(counter + ' ');
counter += 1;
}
3 Answers
Curtis Murley
2,766 PointsLine one refers to "count" while line two refers to "counter"
Sanjay Tailor
8,443 PointsTry this code:
for( var i = 0; i < 26; i = i + 1 ) {
document.write("Printing something");
}
Sanjay Tailor
8,443 PointsUsing while loop, you can do following:
var counter = 0;
while (counter < 26){
document.write('Print Something ');
counter += 1;
}
initialize the counter to 0; while loop (26 iteration); print; increase the counter
Hope this helps!
Morten Larsen
12,275 Pointsfunction randomNumber(upper) { return Math.floor( Math.random() * upper ) + 1; }
var counter = 0; while(counter < 100) { var randNum = randomNumber(6); document.write(randNum + " "); counter += 1; }