//sample solution
//Create an object called FizzBuzzPlus
var FizzBuzzPlus = new Object();
//create the following functions:
// isFizzBuzzie
// return true if the provided value is
// a multiple of 3 or 5 but not both 3 and 5.
// otherwise it returns false
// arguments: number - integer
// returns: true or false - boolean
FizzBuzzPlus.isFizzBuzzie = function(someValue){
if(someValue%3===0 && someValue%5===0){
return false;
} else if(someValue%3===0 || someValue%5===0){
return true;
} else {
return false;
}
}
//getFizzBuzzSum
//returns the sum of all the numbers below the maximum provided
//which are multiples of 3 or 5 but not both
//arguments: number - maximum value for search
//returns: number - sum of the numbers below the maximum which are multiples of 3 or 5 but not both
FizzBuzzPlus.getFizzBuzzSum = function(someValue){
var sum = 0;
for(var i=0; i<someValue;i++){
if(this.isFizzBuzzie(i)){
sum = sum + i;
}
}
return sum;
}
//test
//console.log(FizzBuzzPlus.getFizzBuzzSum(7));
//getFizzBuzzCount
//returns the count of all the numbers below the maximum provided
//which are multiples of 3 or 5 but not both
//arguments: number - maximum value for search
//returns: number - count of the numbers below the maximum which are multiples of 3 or 5 but not both
FizzBuzzPlus.getFizzBuzzCount = function(someValue){
var count = 0;
for(var i=0; i<someValue;i++){
if(this.isFizzBuzzie(i)){
count++;
}
}
return count;
}
//test
//console.log(FizzBuzzPlus.getFizzBuzzCount(7));
//getFizzBuzzAverage
//returns the average(sum/count) of all the numbers below the maximum provided
//which are multiples of 3 or 5 but not both
//arguments: number - maximum value for search
//returns: number - average(sum/count) of the numbers below the maximum whihch are multiples of 3 or 5 but not both
FizzBuzzPlus.getFizzBuzzAverage = function(someValue){
return this.getFizzBuzzSum(someValue)/this.getFizzBuzzCount(someValue);
}
//test
console.log(FizzBuzzPlus.getFizzBuzzAverage(100));
No comments:
Post a Comment