{{#items}}

{{text}}

{{/items}} {{ctaText}}

{{#items}} {{/items}}

showing results for - "javascript write all the prime numbers from 1 to 100"

Marie

05 Nov 2017

```
1function isPrime(num) {
2 for ( var i = 2; i < num; i++ ) {
3 if ( num % i === 0 ) {
4 return false;
5 }
6 }
7 return true;
8}
9
10function display(n) {
11 var arr = [2];
12 for ( var i = 3; i < n; i+=2 ) {
13 if ( isPrime(i) ) {
14 arr.push(i);
15 }
16 }
17 console.log(arr); // use arr result on your own
18}
19
20display(100);
21
22
23//Added Functionality
24
25function prime(n,flag) {
26 ( typeof flag === "undefined" || flag === false ) ? flag = false : flag = true;
27
28 function isPrime(num) {
29 if ( num === 0 || num === 1 ) {
30 return false;
31 }
32 for ( var i = 2; i < num; i++ ) {
33 if ( num % i === 0 ) {
34 return false;
35 }
36 }
37 return true;
38 }
39
40 if ( flag ) {
41 var arr = [2];
42 for ( var i = 3; i <= n; i+=2 ) {
43 if ( isPrime(i) ) {
44 arr.push(i);
45 }
46 }
47 return arr;
48 } else {
49 return isPrime(n);
50 }
51}
52
```

similar questions

how to get prime numbers in javascriptprime factors of an integer jsremove non prime numbers jsjavascript find a prime numberprime or not in javascriptcheck primes in array jsprime numbers javascripthwo to make ana array of prime numbers in javascriptfind prime numbers in range javascriptjs is primesum of all primes below 2 javascriptsum prime numbers javascriptjs print all prime numbersjavascript prime number checknumber is prime or not javascriptjavascript prime numbers up till a certain numbersum of prime numbers javascriptfind prime number function javascript es6queries leading to this page

print prime numbers from 1 to 25 in javascriptprint prime numbers till 100 using javascriptprint prime numbers in javascript1 100 prime numbers jsjavascript get 50 prime numberssum of prime numbers from 1 to 100 in javascriptprime numbers from 1 to 100 in jshow to find prime numbers from 1 to 100 in javascriptprint prime numbers from 1 to 50 in javascripthow to find prime numbers under 100 in javascriptjavascript write all the prime numbers from 1 to 100javascript prime numbers 1 to 100write a javascript program to print prime numbers from 1 to 100print prime numbers between 1 to 100 in htmlprime numbers between 1 to 100 program in javascriptfind all prime numbers upto 10 in jsfirst 100 prime numbers in javascriptjavascript generate 50 first prime numbersprime number in javascript from 0 to 100print all prime numbers javascriptprint 1 to 10 prime numbers in javascriptreturn prime numbers between 1 and 100 in nodejsjavascript print prime numbers 1 to 100get all prime numbers javascriptfunction to find all prime number between 1 and 100print 1 to 100 prime number in jsjavascript generate 50 prime numberswrite a program to print prime numbers from 1 to 100 in javascripthow to print prime numbers from 1 to 100 in javascripthow to find prime number in an array using for loop in javascriptjavascript function to find prime numbers between 1 and 100prime numbers 1 to 100 jslist of prime numbers from 1 to 100 javascriptprint all prime numbers between 1 to 100 by javascript options to print prime numbers between 0 to 10 using javascript prime number program in javascript print 1 to 100javascript code to print prime numbers between 1 to 100print prime numbers from 1 to 10 in javascriptfind prime number 2 100 javascriptjavascript program to find prime numbers between 1 and 100javascript print prime numbersprime numbers from 1 to 100 jsprint prime numbers from 1 to 100 in javascriptall prime numbers in jslist all prime numbers from 1 to 100 javascriptprime numbers 1 to 20 in javascript codeprime number between 1 to 100 program in javascriptprint prime numbers between 1 to 100 in javascriptprint prime numbers up to 10 using jsjavascript get 50 first prime numbersjavascrit prime number seriesjavascript calculate all prime numbersjavascript generate prime numbers in range module that finds and returns all the prime numbers between 1 and 100 in nodejsprime numbers from 1 to 100 javascripthow to prime numbers first 100 prime number javascriptwap to print the prime numbers from 10 to 100 in javascriptprime numbers from 1 to 100 in javascriptprint prime number from 1 to 100 jswrite a program to output all prime numbers less than 100 in javascriptmodule that finds and returns all the prime numbers between 1 and 100 in node jsdisplay prime numbers from 1 to 100 in javascriptget all prime numbers before number javascriptprime numbers 1 to 100 in jsjavascript write all the prime numbers from 1 to 100 your answer for

you will get a confirmation link on this - you will have to click that for successful submission of your answer. we require this to keep the website free of spam, bots and unhelpful content

please ensure to add code which is syntactically corrent and executes properly

ask question on maxinterview

you will get a confirmation link on this - you will have to click that for successful submission of your question. we require this to keep the website free of spam, bots and unhelpful content

please be clear, to the point and respectful