Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

JavaScript Prime Number

// To understand this let's understand that Prime number has only two factors 
// 1) first factor = number it self
// 2) second factor = 1
// for instance 3 has only factors 3*1 = 3 and 1;
// I have taken two for loop to get two different numbers once we get two factors then it will console i
function getPrime(until) {
  let factor;
  for (let i = 0; i < n; i++) {
    factor = 0;
    for (let j = 1; j <= n; j++) {
      if (i % j == 0) {
        factor++;
      }
    }
    if (factor == 2) console.log(i);
  }
}
getPrime(30);
Source by www.programiz.com #
 
PREVIOUS NEXT
Tagged: #JavaScript #Prime #Number
ADD COMMENT
Topic
Name
9+2 =