Quotes help make search much faster. Example: "Practice Makes Perfect"

Thursday, December 6, 2012

Codecademy: Codeyear Write getFizzBuzzCount


//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));

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts