this is only a part of the code
What does this loop do? This is a JavaScript for loop I'm trying to learn some JavaScript with modulo in it but I can't understand this one.
for (var x = 2; x < n; x++) {
if (n % x === 0) {
return false;
}
}
return true;
}
}
The above code will increment x (starting at 2) until it's 1 less than n. Each iteration, it checks if "n" can be evenly divided by "x". (Modulos are used to find the remainder). If it is evenly divisible, the program return false.
This code is a prime number checker. If it gets to the bottom it means "n" can only be divided by itself and returns true.