Created
December 19, 2014 01:52
-
-
Save julianvargasalvarez/89d8db19ebb878fdfb57 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Fizz Buzz Bazz | |
hacer una funcion que receba un numero e imprima: | |
- fizz si es multiplo de 3 | |
- buzz si es multiplo de 5 | |
- bazz si es miltiplo de 3 y 5 | |
- n si no es multiplo de 3 ni 5 | |
========================================================= | |
*/ | |
function x_es_modulo_de_y(x, y) { | |
return x % y == 0; | |
} | |
function esModuloDeCinco(x) { | |
return x_es_modulo_de_y(x, 5); | |
} | |
function esModuloDeTres(x) { | |
return x_es_modulo_de_y(x, 3); | |
} | |
function fizzBuzzBazz(n) { | |
if(esModuloDeTres(n) && esModuloDeCinco(n)) | |
return "Bazz"; | |
if(esModuloDeTres(n)) | |
return "Fizz"; | |
if(esModuloDeCinco(n)) | |
return "Buzz"; | |
return n; | |
} | |
console.log("describe fizzBuzzBazz"); | |
console.log("it returns 'Fizz' when the number given is divisible by 3"); | |
console.log(" ", fizzBuzzBazz(3) == 'Fizz'); | |
console.log("it returns 'Buzz' when the number given is divisible by 5"); | |
console.log(" ", fizzBuzzBazz(5) == 'Buzz'); | |
console.log("it returns 'Bazz' when the number given is divisible by 3 and 5"); | |
console.log(" ", fizzBuzzBazz(15) == 'Bazz'); | |
console.log("it returns the number given when the number given is not divisible by 3 or 5"); | |
console.log(" ", fizzBuzzBazz(82) == 82); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment