Skip to content

Instantly share code, notes, and snippets.

@adyngom
Created January 27, 2017 03:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adyngom/647e0b25c7c5a32b58ea685fca34a5b7 to your computer and use it in GitHub Desktop.
Save adyngom/647e0b25c7c5a32b58ea685fca34a5b7 to your computer and use it in GitHub Desktop.
FizzBuzz Challenge
<ul id="fizzbuzz">
</ul>
<script type="text/javascript" src="fizzbuzz.js"></script>
/**
* 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