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.

  1. Return true if n is a prime number, otherwise return false.
  2. Hint: Loop from 2 up to n-1. If n is divisible by any of those numbers, it's not prime. (Assume n > 1).

Constraints

    CoreLoopsMath
    JavaScript
    Loading...
    3 Hidden

    Input Arguments

    n7

    Expected Output

    true

    Click RUN to test your solution