Skip to content

Instantly share code, notes, and snippets.

@dtstanley
Forked from anonymous/fizzBuzzDrillJS.js
Created June 9, 2017 21:37
Show Gist options
  • Save dtstanley/ae27866fcd8ede4ba22d2f5dfecf32d9 to your computer and use it in GitHub Desktop.
Save dtstanley/ae27866fcd8ede4ba22d2f5dfecf32d9 to your computer and use it in GitHub Desktop.
fizzBuzzDrillJS created by dtstanley - https://repl.it/G9KW/266
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