Guest User

Looping a Triangle

a guest
Jun 8th, 2018
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.08 KB | None | 0 0
  1. <!DOCTYPE html>
  2.  
  3. <html>
  4.  
  5.   <head>
  6.     <meta charset="utf-8">
  7.     <title>Looping a Triangle</title>
  8.   </head>
  9.  
  10.   <body>
  11.  
  12.     <!-- A button to begin the program -->
  13.  
  14.     <button onclick="generator()">Lets make a ladder with #s!</button>
  15.     <br>
  16.  
  17.     <!-- This is where the # will appear -->
  18.  
  19.     <p id="ladder"></p>
  20.  
  21.     <!-- This is the code that excecutes the loop -->
  22.  
  23.     <script>
  24.  
  25.       function generator() {
  26.  
  27.         // Variables that are for the code only
  28.  
  29.         var text = "";
  30.         var michi = "";
  31.         var i = 0;
  32.  
  33.         // Variable that comes from the prompt input
  34.  
  35.         var limit = prompt("How many steps?", 7);
  36.  
  37.         if ((limit > 0) && (limit % 1 == 0) && !(limit==NaN)) {
  38.          while (i < limit) {
  39.            michi += "#";
  40.             text += michi + "<br>";
  41.             i++;
  42.           }
  43.         }
  44.         else {
  45.           text = "Thats not a step number!"
  46.         }
  47.  
  48.         // Printing result in the page
  49.  
  50.         document.getElementById("ladder").innerHTML = text;
  51.       }
  52.  
  53.     </script>
  54.  
  55.   </body>
  56.  
  57. </html>
Advertisement
Add Comment
Please, Sign In to add comment