Created
June 9, 2017 21:37
-
-
Save anonymous/b0e9f049bb061a31f0b97c4def6ebbc5 to your computer and use it in GitHub Desktop.
fizzBuzzDrillJS created by dtstanley - https://repl.it/G9KW/266
This file contains 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
function fizzBuzz(countTo) { | |
var newCountTo = []; | |
for (var i =1; i<= countTo.length; i++){ | |
//compare countTo[i] to 3 and chg countTo[i] to fizz | |
if (countTo[i]%3 ===0){ | |
newCountTo[i] = 'fizz'; | |
} | |
//compare countTo[i] to 5 and chg countTo[i] to buzz | |
if (countTo[i]%5 ===0){ | |
newCountTo[i] = 'buzz'; | |
} | |
//compare countTo[i] to 15 and chg countTo[i] to fizzBuzz | |
if (countTo[i]%3 ===0 && countTo[i]%5 ===0){ | |
newCountTo[i] = 'fizzbuzz'; | |
} | |
} | |
return newCountTo; | |
} | |
/* From here down, you are not expected to | |
understand.... for now :) | |
Nothing to see here! | |
*/ | |
// tests | |
(function testFizzBuzz() { | |
// we'll use the variables in our test cases | |
var countTo = 16; | |
var expected = [ | |
1, 2, 'fizz', 4, 'buzz', 'fizz', 7, 8, 'fizz', | |
'buzz', 11, 'fizz', 13, 14, 'fizzbuzz', 16 | |
]; | |
var actual = fizzBuzz(countTo) || []; | |
if ( | |
expected.length === actual.length && | |
expected.every(function(item, index) { | |
return actual[index] === item;}) ) { | |
console.log('SUCCESS: fizzBuzz is working'); | |
} | |
else { | |
console.log('FAILURE: fizzBuzz is not working'); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment