Created
January 27, 2017 03:18
-
-
Save adyngom/647e0b25c7c5a32b58ea685fca34a5b7 to your computer and use it in GitHub Desktop.
FizzBuzz Challenge
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
<ul id="fizzbuzz"> | |
</ul> | |
<script type="text/javascript" src="fizzbuzz.js"></script> |
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
/** | |
* Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number | |
* and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz". | |
* See the working example on JS Fiddle | |
* https://jsfiddle.net/adyngom/afpvq0na/ | |
*/ | |
let list = ""; | |
let str = ""; | |
for(var j = 1; j <= 100; j++) { | |
let f = (j % 3 == 0), b = (j % 5 == 0); | |
str = f ? b ? "FizzBuzz" : "Fizz" : b ? "Buzz" : j; | |
list += "<li>" + str + "</li>"; | |
} | |
document.getElementById('fizzbuzz').innerHTML = list; | |
/** | |
let list = ""; | |
let str = ""; | |
for(var j = 1; j <= 100; j++) { | |
str = j; | |
if(j % 3 == 0) | |
str = "Fizz"; | |
if(j % 5 == 0) | |
str = "Buzz" | |
if(j % 15 == 0) | |
str = "FizzBuzz" | |
list += "<li>" + str + "</li>"; | |
} | |
document.getElementById('fizzbuzz').innerHTML = list; | |
**/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment