patternjavascriptModerate
Such code, Much wow, very FizzBuzz
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]
I have a feeling I'm misusing the language syntax in relation to adding strings to
I also have a feeling my underlying structure of:
You can run this with:
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 - elseI 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
wowYou can run this with:
plz fizzbuzz with 30Solution
First, use the doge version for everything possible:
As it's a fun fun language, making use of
Making another function for printing instead keeping the
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
wowAs 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 iMaking 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
wowCode 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
wowvery 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 isuch 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
wowContext
StackExchange Code Review Q#114324, answer score: 12
Revisions (0)
No revisions yet.