lesson-cover

Go Back

Variables & Functions

isPrime

Write a function called solution that takes in a number and returns true if it's prime, false otherwise.

A prime number is a number that is greater than 1, and not divisible by any number other than itself.

There are a number of approaches to do this, but the simplest is to start a number i at 2, and keep using % to check if the input number is divisible by i.

result = solution(2) // true
result = solution(1) // false
result = solution(8) // false
result = solution(13) // true

Reminder for students with prior experience: you are not allowed to use for and while loops. Reason