HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavascriptModerate

Such code, Much wow, very FizzBuzz

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
suchmuchwowfizzbuzzverycode

Problem

So, I've written FizzBuzz for a dialect of JavaScript called Dogescript.

It has the same functionality as JavaScript, it simply changes some of the syntax points:


[A few from the language spec]

shh [comment] - // [comment]
very [var] is [value] - var [var] = [value]
[var] is [value] - [var] = [value]
such [name] much [variables] - function [name] ([variables])
wow - }
rly [params] - if ([params])
but rly [params] - else if ([params])
but - else


I have a feeling I'm misusing the language syntax in relation to adding strings to result.

I also have a feeling my underlying structure of:

  • Create result variable



  • Append "Fizz" and "Buzz" based on rules



  • Print result variable if it has content, otherwise the iterator value.



such fizzbuzz much max
    much very i is 0 next i smaller max next i more 1
        very result
        rly i % 3 is 0
            result += "Fizz"
        wow
        rly i % 5 is 0
            result += "Buzz";
        wow
        console.loge(result || i);
    wow
wow


You can run this with:

plz fizzbuzz with 30

Solution

First, use the doge version for everything possible:

such fizzbuzz much max
        much very i is 0 next i smaller max next i more 1
            very result
            rly i % 3 is 0
                result more "Fizz" next
            wow
            rly i % 5 is 0
                result more "Buzz" next
            wow
            console dose with result or i next
        wow
    wow


As it's a fun fun language, making use of but rly is more important than optimizations:

very result
    rly i % 3 is 0
        result is "Fizz" next
    but rly i % 5 is 0
        result is "Buzz" next
    but rly i % 15 is 0
        result is i


Making another function for printing instead keeping the result variable looks even better:

such print much result 
        console dose loge with result
    wow       

    such fizzbuzz much max
        very i is 1
        much next i smaller max next i more 1
          rly i % 15 is 0
              plz print with "FizzBuzz"
          but rly i % 3 is 0
              plz print with "Fizz"
          but rly i % 5 is 0
              plz print with "Buzz"
          but
              plz print with i
          wow
        wow
    wow

Code Snippets

such fizzbuzz much max
        much very i is 0 next i smaller max next i more 1
            very result
            rly i % 3 is 0
                result more "Fizz" next
            wow
            rly i % 5 is 0
                result more "Buzz" next
            wow
            console dose with result or i next
        wow
    wow
very result
    rly i % 3 is 0
        result is "Fizz" next
    but rly i % 5 is 0
        result is "Buzz" next
    but rly i % 15 is 0
        result is i
such print much result 
        console dose loge with result
    wow       


    such fizzbuzz much max
        very i is 1
        much next i smaller max next i more 1
          rly i % 15 is 0
              plz print with "FizzBuzz"
          but rly i % 3 is 0
              plz print with "Fizz"
          but rly i % 5 is 0
              plz print with "Buzz"
          but
              plz print with i
          wow
        wow
    wow

Context

StackExchange Code Review Q#114324, answer score: 12

Revisions (0)

No revisions yet.