Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

JS print all prime numbers

// program to print prime numbers between the two numbers

// take input from the user
const lowerNumber = parseInt(prompt('Enter lower number: '));
const higherNumber = parseInt(prompt('Enter higher number: '));

console.log(`The prime numbers between ${lowerNumber} and ${higherNumber} are:`);

// looping from lowerNumber to higherNumber
for (let i = lowerNumber; i <= higherNumber; i++) {
    let flag = 0;

    // looping through 2 to user input number
    for (let j = 2; j < i; j++) {
        if (i % j == 0) {
            flag = 1;
            break;
        }
    }

    // if number greater than 1 and not divisible by other numbers
    if (i > 1 && flag == 0) {
        console.log(i);
    }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: is object js 
Javascript :: expo build ios 
Javascript :: upload file in react 
Javascript :: react native indicator 
Javascript :: restrict the user from going to signup or login page if the user is already logged in firebase auth 
Javascript :: express request body undefined 
Javascript :: how to get day name in moment js 
Javascript :: get dir from filepath javascript 
Javascript :: how to get unique values from array in javascript without duplicate value 
Javascript :: set property dom javascrpt 
Javascript :: How can I know which radio button is selected via jQuery 
Javascript :: falsy value javascript 
Javascript :: react native get timezone 
Javascript :: embed example discord.js 
Javascript :: active nav links in next.js 
Javascript :: set label text in jquery 
Javascript :: javascript simulate click on element 
Javascript :: how to generate random id in javascript 
Javascript :: js php number format 
Javascript :: js Date(date).toLocaleString() MINUUTES 
Javascript :: iterate through object array javascript 
Javascript :: how to add link to button in react js 
Javascript :: vue cdn 
Javascript :: default value input date js 
Javascript :: discord.js bot mention 
Javascript :: exponent in javascript 
Javascript :: syntax for srcset in react 
Javascript :: javascript break for loop 
Javascript :: app.post (req res) get data 
Javascript :: img src in react js 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =