Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>FizzBuzz</title>
- </head>
- <body>
- <!-- A button to begin the program -->
- <button onclick="generator()">Set the limit!</button>
- <br>
- <!-- This is where the strings will appear -->
- <p id="inside"></p>
- <!-- This is the code that excecutes the loop -->
- <script>
- function generator() {
- // Variables that are for the code only
- var text = "";
- var i = 1;
- // Variable that comes from the prompt input
- var limit = prompt("Count until...?", 100);
- var tops = parseInt(limit) + 1;
- if ((tops > 0) && (tops % 1 == 0) && !(tops==NaN)) {
- while (i < tops) {
- if (i % 15 == 0) {
- text += "FizzBuzz<br>";
- i++;
- }
- else if (i % 3 == 0) {
- text += "Fizz<br>";
- i++;
- }
- else if (i % 5 == 0) {
- text += "Buzz<br>";
- i++;
- }
- else {
- text += i + "<br>";
- i++;
- }
- }
- }
- else {
- text = "Only integers above zero please."
- }
- // Printing result in the page
- document.getElementById("inside").innerHTML = text;
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment