0

I'm working on a codecademy.com lesson where I'm supposed to check if a number is a multiple of 3 or 5 (but not a multiple of 3 and 5), returning true or false depending on result of the test. The method should also return false if doesn't satisfy either of the conditions.

When I run the code it's telling me there's a syntax error: unexpected token. Can anyone see what I'm doing wrong?

var FizzBuzzPlus = {

    this.isFizzBuzzie = function(number){
        if (number % 3 === 0 && number % 5 === 0){
            return false;           
        }else if (number % 3 === 0 || number % 5 ===0){
            return true; 
        }else{
        return false; 
        }                           
    }; 
};

2 Answers 2

4

This should work:

var FizzBuzzPlus = {

    isFizzBuzzie: function(number){
        if (number % 3 === 0 && number % 5 === 0){
            return false;           
        }else if (number % 3 === 0 || number % 5 ===0){
            return true; 
        }else{
        return false; 
        }                           
    }
};
Sign up to request clarification or add additional context in comments.

Comments

1

Somewhat off-topic, but it would be better to evaluate the modulo for both 3 and 5 only once:

var FizzBuzzPlus = {

    isFizzBuzzie : function(number){
        var d3 = number % 3 === 0;
        var d5 = number % 5 === 0;
        if (d3 && d5){
            return false;           
        }else if (d3 || d5){
            return true; 
        }else{
        return false; 
        }                           
    }
};

for (var i = 0; i <= 25; i++){
    console.log(i + ": " + FizzBuzzPlus.isFizzBuzzie(i));
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.