Javascript – Exercise – Fizzbuzz

 

Fizzbuzz

 

 
//Fizbuzz Exercise – Interview Algorithm

 

//Divisible by 3 => Fizz
//Divisible by 5 => Buzz
//Divisible by both 3 and 5 => Fizzbuzz
//Not divisible by 3 or 5 => input
//Not a number => ‘Not a number’

 

let input = 9 //Input number here to check
let F1 = ‘Fizz’
let B1 = ‘Buzz’
let FB1 = ‘Fizzbuzz’
let NotN1 = ‘Not a number’

 

const output = fizzBuzz(input);

 

function fizzBuzz (input) {
if (typeof(input)==‘string’) return NotN1; // Not a number if a string
if ((input % 3 === 0) && (input % 5 === 0)) return FB1; //Fizzbuzz
if (input % 3 === 0) return F1; //Fizz
if (input % 5 === 0) return B1; //Buzz
else return input;
}

 

console.log(output);