Hey there, fellow developers. I'm currently encountering a mental block and struggling to find a solution for my issue.
Here is the code snippet in question:
if ((n % 3 === 0 || n % 5 === 0) &&( n % 3 !== 0 && n % 5 !== 0))
{
return true;
}
else {
return false;
}
In essence, I need to determine if a number is a multiple of either 3 or 5 but not both.
Unfortunately, regardless of the input number (whether it's a multiple of 3, 5, or both), the test consistently fails. Initially, I believed this could be achieved within a single statement.
The following alteration of the code does yield correct results:
if (n % 3 === 0 || n % 5 === 0)
{
if( n % 3 === 0 && n % 5 === 0)
{
return false;
}
else {
return true;
}
}
else {
return false;
}
Nevertheless, I am puzzled about what exactly is lacking in the initial test. My aim is to consolidate all conditions into one line, yet due to this mental lapse, I am unable to pinpoint the missing piece to solve this puzzle.