Skip to content

Instantly share code, notes, and snippets.

@richardpilgrim
Created October 27, 2013 09:34
Show Gist options
  • Save richardpilgrim/7179651 to your computer and use it in GitHub Desktop.
Save richardpilgrim/7179651 to your computer and use it in GitHub Desktop.
Fizzbuzz in Javascript. I made it to keep myself entertained.
<html>
<head>
<title>FizzBuzz</title>
</head>
<body>
<div id="test"></div>
<script>
var div = document.getElementById('test');
for(var i=1;i<=100;i++)
{
if(i % 3 == 0)
{
div.innerHTML = div.innerHTML + 'Fizz';
}
if(i % 5 == 0)
{
div.innerHTML = div.innerHTML + 'Buzz';
}
if(i % 5 != 0 && i % 3 != 0)
{
div.innerHTML = div.innerHTML + i;
}
div.innerHTML = div.innerHTML + '<p>';
}
</script>
</body>
</html>
@trisreed
Copy link

I could be wrong (and am picking at semantics anyway) but on line 28 shouldn't that be a
rather than a

? Either way - it's good to see a fizzbuzz solution that is actually understandable :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment