Day 40: Prime Numbers of 100DaysCodingChallenge

Hello all, 

I have started the 100 days of coding challenge to improve my programming skills..

Today is the Day40 of 100DaysCodingChallenge for 

to Display Prime Numbers Between Two Intervals (entered by user).

Code : 

let a = prompt("Enter a : ");
let b = prompt("Enter b : ");
console.log(`The prime numbers between ${a} and ${b} are:`); 
for (let i = a; i <= b; 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);
    }
}

Output :     

 


Happy Coding:)

Thank you...  

Comments

Popular posts from this blog

Day 100: Date Time to Number of 100DaysCodingChallenge

Day 64: Pattern using loops of 100DaysCodingChallenge

Day 20: Positive Number of 100DaysCodingChallenge