// Count from 1 to 20 // Analysis while(counter <=20) { document.writeln(counter + "<br>"); counter++; }This section of code creates the loop that does the work of the program. The first line is the conditional; while it evaluates to True, the statements within the brackets will be executed.
The first statement uses the writeln() method to print the value of the counter variable to the screen, followed by the string "<br>". <br> is the HTML tag for a line break, which causes each number to be printed on its own line.
The next line uses the unary increment operator (++) to increment the counter variable. Without this line, the value of counter would remain 1 forever, and the script would continuously print a column of 1s, rendering your computer useless until the browser crashes or you manually stop it.