Maybe you have seen this kind of viral picture about a guy who gets asked to program FizzBuzz in a job interview.
- Print numbers from 1 to 100
- If a number is divisible by 3, print “Fizz” instead
- If a number is divisible by 5, print “Buzz” instead
- If a number is divisible by 3 and 5, print “FizzBuzz” instead
- Print using console.log
First Try (101 characters)
Uses a simple if-else clause and appends the strings "Fizz" and "Buzz", so we don't need an extra "FizzBuzz" in our code.
Second Try (69 characters)
Third Try (64 characters)
Have a look at the for-loop on this one. Using the pre-increment operator ++ we don't need the last argument in our for-loop. We were also able to remove the parentheses in the ternary statements.
Can you make it even shorter? Reply down below!