The Prime Scanner
Hard+35 XP
Mission Briefing
The Grand Cipher requires a true Prime number to decode the vault. Ancient mathematicians used loops to test every possible divisor. You must rebuild their algorithm.
The Concept: Algorithmic Searching
Many algorithms require you to search for a counter-example. To prove a number isn't prime, you loop through potential divisors. The moment you find one that divides evenly (n % i === 0), you know it isn't prime!
The Objective
Your function receives a number n.
- Return
trueifnis a prime number, otherwise returnfalse. - Hint: Loop from 2 up to
n-1. Ifnis divisible by any of those numbers, it's not prime. (Assumen > 1).
Constraints
CoreLoopsMath
JavaScriptSystem handles I/O — write your function only
Loading...
3 Hidden
Input Arguments
n7
Expected Output
true
Click RUN to test your solution