musings on music and life

August 3, 2015

learning to code…FizzBuzz

Filed under: Coding — Tags: — sankirnam @ 9:51 am

I’m back from a bit of a hiatus… while I’m still not gainfully employed, I’ve been keeping myself busy with a variety of things. Lately, I’ve been learning to code on Codeacademy – I highly recommend this website for other beginners like myself since it is interactive and the lessons are planned out very well, with a gradual introduction of new concepts and periodic refreshers and reviews where necessary.

I’ve been doing the Javascript lessons on Codeacademy, and along the way I had to do the famous FizzBuzz exercise. For those who don’t know:

“[…] questions I call “FizzBuzz Questions” named after a game children often play (or are made to play) in schools in the UK. An example of a Fizz-Buzz question is the following:

Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

Sounds pretty trivial on the surface, right? I mean, anyone can do this on pen and paper, but it takes a little bit of programming knowledge to write code that accomplishes this. The scary part?

The majority of comp sci graduates can’t. I’ve also seen self-proclaimed senior programmers take more than 10-15 minutes to write a solution.” (Source)

Wow. And these people will still be able to get jobs that pay salaries far, far beyond what competent PhD chemists make, due to the robust job growth and demand for computer scientists/programmers.

In any case, here’s my solution (for numbers 1-20):

for(var i=1; i<21; i++) {
if(i%3 === 0 && i%5 === 0) {
} else if (i%5 === 0) {
} else if (i%3 === 0) {
} else {


1 Comment »

  1. […] CS graduates, even those with advanced degrees, who cannot do simple programming exercises like the “FizzBuzz” challenge or simple algorithms. So perhaps there are a large number of mediocre CS students who are […]

    Pingback by ok now, this is getting a little ridiculous | musings on music and life — April 20, 2016 @ 11:26 pm

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at

%d bloggers like this: