1 2 3
|
if
(number % 1 && number) //If the number is divisible by 1 and itself
status == true; //Returns true value
|
This if statement is incorrect in several ways:
1) % gives you the remainder after division. So, for example... 17%5 would give you 2 because 17/5 has a remainder of 2. With that in mind... ask yourself what the remainder is after a division by 1? It's always going to be zero, because any number divided by 1 is itself with no remainder. Therefore, this if statement is always going to be false because the first portion of it is always 0.
2) && does not do what you think it does. It does not combine operands for the % operator. Instead, it combines the boolean result on its left and right sides. So the left side is "number % 1" and the right side is "number". If
both of those sides are nonzero, then you get 'true'. Otherwise you get 'false.
As already mentioned... "number % 1" is always going to be zero, so && will give you false no matter what. But "number" likely is
never going to be zero.
3) The logic here doesn't make sense... because
every number is divisible by 1 and itself. So even if this statement worked as you intended, it would think that every number is prime.