DEV Community

loading...

Discussion on: FizzBuzz challenge in as many languages as possible

Collapse
reinhart1010 profile image
Reinhart Previano K.

Language: JavaScript
Code: gist.github.com/reinhart1010/d2b81...

Other/Info: The above code execute console.log command for each number. And yes, this is compiled on JSFuck based on the original code:

var i;
for (i = 1; i <= 100; i++){
    var fb = 0;
    if (i % 3 == 0){
        console.log("Fizz");
        fb = 1;
    }
    if (i % 5 == 0){
        console.log("Buzz");
        fb = 1;
    }
    if (fb == 0) console.log(i);
}

Trying to decode the first snippet on JSUnFuck will likely to cause browsers to hang.

Interestingly, this one can be exported to C with minimal modifications:

#include <stdio.h>

int main(){
    int i;
    for (i = 1; i <= 100; i++){
        int fb = 0;
        if (i % 3 == 0){
            printf("Fizz");
            fb = 1;
        }
        if (i % 5 == 0){
            printf("Buzz");
            fb = 1;
        }
        if (fb == 0) printf("%d", i);
        printf("\n");
    }
}

JavaScript should be welcoming to my folks who are currently learning C thanks to similarity in syntaxes. (If you're reading this, good luck in facing your mid-term exams next week!)