JavaScript if statement test for one or the other but not both

if-statement, javascript

Solution

If it is divisible by both 3 and 5, it'll be divisible by 15.

Please try the following condition

if ((n % 3 === 0 || n % 5 === 0) && ( n % 15 !== 0))

Problem

Hello fellow StackOverflowers. I'm have a brain fart right now, and I cannot seem to figure this out. I have the following code ``` if ((n % 3 === 0 || n % 5 === 0) &&( n % 3 !== 0 && n % 5 !== 0)) { return true; } else { return false; } ``` Basically I need to test if the number is a multiple of 3 || 5 but not a multiple of both. However when I enter any number I enter (whether it is multiple of 3 || 5 || both) the test always fails. I would have thought this was able to be performed in one statement. This code though does work fine. ``` if (n % 3 === 0 || n % 5 === 0) { if( n % 3 === 0 && n % 5 === 0) { return false; } else { return true; } } else { return false; } ``` But I'm wondering what I am missing in the first test. I'd like all the test to be in one like, but like I said I'm having a brain fart and cannot figure out what I'm missing.

Original source