Editing FizzBuzz This edit will create a new revision. Your details (optional) Name Email (won’t be displayed; might be used for Gravatar) URL Test case details Title * Published (uncheck if you want to fiddle around before making the page public) Description (in case you feel further explanation is needed)(Markdown syntax is allowed) Testing the performance on four variations of the famous "FizzBuzz" test using JavaScript. All four variations use modulus factorials (`%`) to check against `3` and `5`. The `FizzBuzz` test: "Write a program that outputs numbers from 1 to 100, except when one of the numbers meets one of three criterial conditions: 1) If a number is a multiple of three, print `Fizz` instead of the number; 2) If a number is a multiple of five, print `Buzz` instead of the number; 3) If a number is a multiple of both, print `FizzBuzz` instead of the number. The output should look like this: `1` `2` `Fizz` `4` `Buzz` `Fizz` ... and so-on. Are you a spammer? (just answer the question) Preparation code Preparation code HTML (this will be inserted in the <body> of a valid HTML5 document in standards mode) (useful when testing DOM operations or including libraries) Include JavaScript libraries as follows: <script src="//cdn.ext/library.js"></script> Define setup for all tests (variables, functions, arrays or other objects that will be used in the tests) (runs before each clocked test loop, outside of the timed code region) (e.g. define local test variables, reset global variables, clear canvas, etc.) (see FAQ) // recursive `function` function f(s, n) { if (++n === 102) return; s === '' ? console.log(n - 1) : console.log(s); !! (n % 3) ? !! (n % 5) ? f('', n) : f('Buzz', n) : !! (n % 5) ? f('Fizz', n) : f('FizzBuzz', n); } // `while` loop function b(n) { var i = n; $: while (++i) { if (i % 3) if (i % 5) console.log(i); else console.log('Buzz'); else if (i % 5) console.log('Fizz'); else console.log('FizzBuzz'); if (i >= 100) break $; } return; } // `for` deductive loop function F(n) { var i = n, f = 'Fizz', b = 'Buzz', o = ''; for (; i <= 100; i++) { o = !(i % 3) ? !(i % 5) ? f + b : f : !(i % 5) ? b : i; console.log(o); } return; } // `for` loop function B(n) { var i = n; var fiz = 'Fizz'; var buz = 'Buzz'; for (; i <= 100; i++) if (!(i % 3)) if (!(i % 5)) console.log(fiz + buz); else console.log(fiz); else if (!(i % 5)) console.log(buz); else console.log(i); return; } Define teardown for all tests (runs after each clocked test loop, outside of the timed code region) (see FAQ) Code snippets to compare Test 1 Title Async (check if this is an asynchronous test) Code f('', 1); Test 2 Title Async (check if this is an asynchronous test) Code b(0); Test 3 Title Async (check if this is an asynchronous test) Code F(1); Test 4 Title Async (check if this is an asynchronous test) Code B(1);