Codecademy Project FizzBuzz Answer
1 min read

Codecademy Project FizzBuzz Answer

I have been playing with Codecacademy to brush up on my Javascript. I’m now posting my source code to help anyone who is having trouble. Answered by Michael Le.

Fizzing and Buzzing 5 : Never Gonna Stop Source Code

/*
Michael Le
Codecademy username: mikele
Javascript Introduction Project: Fizz Buzz
Fizzing and Bizzing 5: Never Gonna Stop
*/

// for the numbers 1 through 20,
for (i=1; i<=100; i++) { 
  
  // if the number is divisible by 3, write "Fizz"
  if ( i % 3 === 0 ) { 
      if(i % 5 === 0)
        console.log("FizzBuzz");
      else
        console.log("Fizz");
  }
  
  // if the number is divisible by 5, write "Buzz"
  else if( i % 5 === 0){
      console.log("Buzz");
  }
  
  // otherwise, write just the number
  else {
    console.log(i);
  }
}