This is an example exercise to count backwards from 10 to 1. Print the numbers on the screen.
and this is my code:
<script type="text/javascript">
i=1
while( 11 > i ) {
document.writeln("<p>" + i + "</p>");
i--;
}
</script>
I don't know what mistake is in the code but the numbers didn't print on the screen. Also, the browser took awhile to load and I had to stop it. Could someone give an explanation so I can understand how to write this the correct way? Thank you.
So, as I understood you are trying to add the "p" tag with iteration number to the your document. There are several mistakes in your code:
let i = 10;
while (i !== 0) {
document.writeln("<p>" + i + "</p>");
i = i - 1;
}