Created
March 12, 2015 17:08
-
-
Save elizabrock/07ef63d2f976a1587027 to your computer and use it in GitHub Desktop.
FizzBuzz in Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta charset="utf-8" /> | |
<title></title> | |
<script type="text/javascript"> | |
var fizzbuzz = function (i) { | |
output = ""; | |
if (i % 3 === 0) { | |
output += "Fizz" | |
} | |
if (i % 5 === 0) { | |
output += "Buzz" | |
} | |
if (!output) { | |
output += i | |
} | |
return output; | |
} | |
var fizzbuzz1 = function (i) { | |
if (i % 15 === 0) { | |
return "FizzBuzz"; | |
} else if (i % 3 === 0) { | |
return "Fizz"; | |
} else if (i % 5 === 0) { | |
return "Buzz"; | |
} | |
else { | |
return i; | |
} | |
} | |
var printFizzBuzz = function(){ | |
var ul = document.getElementById("FizzBuzz"); | |
for (var i = 1; i <= 100; i++) { | |
li = document.createElement("li"); | |
li.textContent = fizzbuzz(i); | |
ul.appendChild(li); | |
} | |
}; | |
document.addEventListener("DOMContentLoaded", printFizzBuzz); | |
</script> | |
</head> | |
<body> | |
<ul id="FizzBuzz"> | |
</ul> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment