Programming Test 1: Fizz Buzz

By | 11 April, 2015

Hopefully I’ve not misinterpreted the challenge here. Count to 100, if the number is divisible by three, output Fizz, if divisible by five, output Buzz.

If its Divisible by 5 and 3, FizzBuzz!

Here’s my solution in node.js:

for (var i=0; i < 100 ; i++)
{
  var ans = "";

  if (divByThree(i)){ans = "fizz"}
  if (divByFive(i)){ans = "buzz"}
  if (divByFive(i) && divByThree(i)) {ans = "fizzbuzz"}
  console.log (i + ": " + ans);

}

function divByThree (num)
 {
   if (parseInt(num) % 3 == 0)
 {
  return true;
 }
 else {
   return false;
  }
}

function divByFive (num)
 {
  if (parseInt(num) % 5 == 0)
 {
 return true;
 }
 else {
  return false;
 }

}