-
-
Save dtstanley/502a09498365feb16361406a6de76592 to your computer and use it in GitHub Desktop.
fizzBuzzDrillJS created by dtstanley - https://repl.it/G9KW/272
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; i++){ | |
// if (i%3 !==0 && i%5 !==0){ | |
// newCountTo.push(i); | |
// } | |
//compare countTo[i] to 15 and chg countTo[i] to fizzBuzz | |
if (i%3 ===0 && i%5 ===0){ | |
newCountTo.push('fizzbuzz'); | |
} | |
//compare countTo[i] to 5 and chg countTo[i] to buzz | |
else if (i%5 ===0){ | |
newCountTo.push('buzz'); | |
} | |
//compare countTo[i] to 3 and chg countTo[i] to fizz | |
else if (i%3 ===0){ | |
newCountTo.push('fizz'); | |
} | |
else{ | |
newCountTo.push(i); | |
} | |
} | |
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