The Lowest Level of JavaScript Comprehension
FizzBuzz, yes that is the lowest level of comprehension for a JavaScript developer yet 99% of folks can’t get it right. Let me rephrase that, 99% of applicants that apply for programming jobs find it difficult to code the FizzBuzz test say many sources. Surprising, as the demographic of most programmers would find FizzBuzz anything but trivial.
The way I see it many people who apply for jobs are really not qualified, so it’s 99% of programmers who apply for jobs that don’t get it, but not the 99% who are actually holding a job as developers or programmers.
Even if you can solve it and easily at that, don’t give anyone grief over being asked to do such a menial task, as that will count against you. Managers are looking for problem solving skills as opposed to self proclaimed “code monkeys”.
That being said, let’s take a look at some implementations.
Below is probably the simplest implementation using a for
loop:
1 | var fizzbuzz = function() { |
We can build upon this example by declaring a variable
to hold our string
:
1 | var fizzBuzz = function() { |
How about using an IIFE - (function iife () { … } ());
? Not too difficult:
1 | (function () { |
We can also use a variable and store the numbers in an array
as well as print line no’s:
1 | var fizzBuzz = function() { |
There you have the basic implementations of FizzBuzz, probably more than you will need for any whiteboard as an interview question. There is however another implementation that you might get asked to undertake as a development test using the Jasmine testing framework.
For the ever curious, I suggest you take a look at the video just to familiarize yourself with the technique (especially if you haven’t used Jasmine). Some companies look for this level of coding comprehension before they even begin to take you on in an interview.