Codecademy Project FizzBuzz++ The Problem Answer

The Function Project FizzBizz++ full source code from Codecademy. Answered by Mike Le.

/*
Michael Le
Codecademy username: mikele
Javascript Function Project: FizzBuzz++: The Return of Modulus
The Problem
*/

//Create an object called FizzBuzzPlus
var FizzBuzzPlus = {


// return true if the provided value is
// a multiple of 3 or 5 but not both 3 and 5.
// otherwise it returns false

isFizzBuzzie:function(value){
    if((value%3===0 || value%5===0) && 
            !(value%3===0 && value%5===0))
        return true;
    else
        return false;
},

//returns the sum of all the numbers below the maximum 
//provided which are multiples of 3 or 5 but not both

getFizzBuzzSum:function(max){
    var sum=0; 
    for(i=0;i<max;i++){
        //check for 3 or 5 multiples and add to sum
        if(this.isFizzBuzzie(i))
            sum+=i;
    }
    return sum;
},

//returns the count of all the numbers below the maximum 
//provided which are multiples of 3 or 5 but not both

getFizzBuzzCount: function(max){
    var count=0;
    for(i=0;i<max;i++){
        if(this.isFizzBuzzie(i))
            count++; //this means count+1
    }
    return count;
},

//returns the average(sum/count) of all the numbers 
//below the maximum 
//provided which are multiples of 3 or 5 but not both

getFizzBuzzAverage: function(max){
    sum = this.getFizzBuzzSum(max);
    count = this.getFizzBuzzCount(max);
    return sum/count;
}
};

//Complete the answer find for max = 100;
console.log(FizzBuzzPlus.getFizzBuzzAverage(100));
Show Comments