Skip to content

Instantly share code, notes, and snippets.

Created June 9, 2017 23:06
Show Gist options
  • Save anonymous/6892fde97d13472df2f62378b23c655f to your computer and use it in GitHub Desktop.
Save anonymous/6892fde97d13472df2f62378b23c655f to your computer and use it in GitHub Desktop.
fizzBuzzDrillJS2 created by dtstanley - https://repl.it/Ieut/9
function fizzBuzz(countTo) {
console.log("initial countTo = ", countTo);
var newCountTo = [];
for (var i =0; i< countTo.length; i++){
//compare countTo[i] to 15 and chg countTo[i] to fizzBuzz
if (countTo[i]%3 ==0 && countTo[i]%5 ==0){
newCountTo[i] = 'fizzbuzz';
}
//compare countTo[i] to 5 and chg countTo[i] to buzz
else if (countTo[i]%5 ==0){
newCountTo[i] = 'buzz';
}
//compare countTo[i] to 3 and chg countTo[i] to fizz
else if (countTo[i]%3 ==0){
newCountTo[i] = 'fizz';
}
else {
newCountTo[i] = countTo[i];
}
console.log("looped countTo = ", countTo[i]);
console.log("looped newCountTo = ", newCountTo);
}
return newCountTo;
}
fizzBuzz([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment