Created
April 12, 2012 21:51
-
-
Save Jared-Prime/2371267 to your computer and use it in GitHub Desktop.
FizzBuzz++ - using nested functions
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
// Codeacademy.com project, "FizzBuzz++" | |
// Goal: count from 1 to N, and output counts, sums and averages of all numbers divisible by both 3 and 5 | |
var FizzBuzzPlus = { | |
isFizzBuzzie: function(value){ | |
if (value%3===0 && value%5===0) | |
return false; | |
else if (value%3===0 || value%5===0) | |
return true; | |
else return false; | |
}, | |
getFizzBuzzSum: function(value){ | |
var sum = 0; | |
for(i=0; i<value; i++){ | |
if (this.isFizzBuzzie(i)){ | |
sum = sum + i; | |
} | |
} | |
return sum; | |
}, | |
getFizzBuzzCount: function(value){ | |
var count = 0; | |
for(i=0;i<value;i++){ | |
if (this.isFizzBuzzie(i)) { count++ }; | |
} | |
return count; | |
}, | |
getFizzBuzzAverage: function(value){ | |
var average = (this.getFizzBuzzSum(value)/this.getFizzBuzzCount(value)); | |
return average; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment