Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

71 characters (129 points) with JavaScript. I actually wrote this quite a while back (and have also posted it on HN before) - code golf is pretty fun every now and then!

    for(var i=0;i++<100;console.log(((i%3?'':'Fizz')+(i%5?'':'Buzz'))||i));
For anyone else interested in doing code golf with JavaScript, here's a goldmine of byte-saving techniques:

https://github.com/jed/140bytes/wiki/Byte-saving-techniques



I came up with

    for(i=0;i<100;)console.log((++i%3?"":"Fizz")+(i%5?"":"Buzz")||i)
earlier. 64 characters, because I don't have "var ", an extra set of parens, and a semicolon. Worse syntax, but hey, it's code golf.


I knew I could also drop the "var ", but I like to operate within the 140bytes challenge rules that say you're not allowed to leak into the global scope. I'll give you the 3 chars from the parens and semicolon, though - I got caught up with the idea of "hey, you can do this whole thing inside the for statement itself!" back when I did this!


Mine was almost identical, except with i++<100 instead of ++i%3? etc. Also 64 characters.

But is there really no way to end the ternary operators without parenthesis?


Good, now everyone can just copy & paste it and the competition is a tie ;)




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: