index.html 490 B

123456789101112131415161718192021222324
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4. <h2>JavaScript While Loop</h2>
  5. <p id="demo"></p>
  6. <script>
  7. // Creating two variables here text a string and i a integer
  8. let text = "";
  9. let i = 0;
  10. // The code will loop until a condition is met. This is what while loops do.
  11. // In this case when i is less than 10
  12. while (i < 10) {
  13. text += "<br>The number is " + i;
  14. // ++ is incrementing the value of i so 1 -> 2 -> 3 etc
  15. i++;
  16. }
  17. document.getElementById("demo").innerHTML = text;
  18. </script>
  19. </body>
  20. </html>