Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>Looping a Triangle</title>
- </head>
- <body>
- <!-- A button to begin the program -->
- <button onclick="generator()">Lets make a ladder with #s!</button>
- <br>
- <!-- This is where the # will appear -->
- <p id="ladder"></p>
- <!-- This is the code that excecutes the loop -->
- <script>
- function generator() {
- // Variables that are for the code only
- var text = "";
- var michi = "";
- var i = 0;
- // Variable that comes from the prompt input
- var limit = prompt("How many steps?", 7);
- if ((limit > 0) && (limit % 1 == 0) && !(limit==NaN)) {
- while (i < limit) {
- michi += "#";
- text += michi + "<br>";
- i++;
- }
- }
- else {
- text = "Thats not a step number!"
- }
- // Printing result in the page
- document.getElementById("ladder").innerHTML = text;
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment