Skip to content
Exercise · Conditions and loops · lesson 13 of 13

Exercise: prime number

Write a function function isPrime(n) that returns true if n is a prime number and false otherwise. A prime number is greater than 1 and divides evenly only by 1 and by itself.

  • isPrime(97) → true
  • isPrime(91) → false
  • isPrime(2) → true

Constraints: n is an integer from 0 to 10000; the numbers 0 and 1 are not prime.

Do not add extra imports unless the task says so explicitly.

prime.js — javascript
javascript · 4 lines
Ctrl+Enter run · Esc leave editor

Subscribe to take the course

The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.

Sign in another way