find prime numbers in range javascript

Solutions on MaxInterview for find prime numbers in range javascript by the best coders in the world

showing results for - "find prime numbers in range javascript"
Meera
14 Sep 2019
1// take input from the user
2const lowerNumber = 1
3var higherNumber = 10000
4
5console.log(`The prime numbers between ${lowerNumber} and ${higherNumber} are:`);
6
7// looping from lowerNumber to higherNumber
8for (let i = lowerNumber; i <= higherNumber; i++) {
9    let flag = 0;
10
11    // looping through 2 to user input number
12    for (let j = 2; j < i; j++) {
13        if (i % j == 0) {
14            flag = 1;
15            break;
16        }
17    }
18
19    // if number greater than 1 and not divisible by other numbers
20    if (i > 1 && flag == 0) {
21        console.log(i);
22    }
23}