Skip to content

Instantly share code, notes, and snippets.

@dtstanley
Forked from anonymous/fizzBuzzDrillJS2.js
Created June 9, 2017 23:06
Show Gist options
  • Save dtstanley/9880a681217dec94f30922c6cfd6f190 to your computer and use it in GitHub Desktop.
Save dtstanley/9880a681217dec94f30922c6cfd6f190 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]);
@dtstanley
Copy link
Author

Worked this one with Marius as an exercise in testing the code; improving the code and understanding better coding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment