Skip to content

Instantly share code, notes, and snippets.

@Jared-Prime
Created April 12, 2012 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jared-Prime/2371267 to your computer and use it in GitHub Desktop.
Save Jared-Prime/2371267 to your computer and use it in GitHub Desktop.
FizzBuzz++ - using nested functions
// 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