JavaScript code to generate composite number series

Took only 59 seconds to code JavaScript prototype to generate composite number series. Here is the code snippet.

Code (Run Code):

arr = [];
function checkComposite(num) {
if (num == 1) {
return false;
} else if (num == 2) {
return false;
}

for (var x = 2; x < num; x++) {
if (num % x == 0) {
return true;
}
}
return false;
}

function compositeNumbers() {
num = Number(document.getElementById('number').value);
for (var j = 1; j < num; j++) {
if (checkComposite(j)) {
arr.push(j);
}
}
document.getElementById('result').innerHTML = arr;
}

6 comments:

  1. I read this article, it is really informative one. Your way of writing and making things clear is very impressive. Thanking you for such an informative article.coding for kids where to start

    ReplyDelete
    Replies
    1. Final year engineering projects final year projects for computer science are a great opportunity to apply theoretical knowledge to practical problems and showcase your skills to potential employers. Here are some project ideas across various engineering disciplines:

      Delete
  2. Nice info, I am very thankful to you for sharing this important knowledge. This information is helpful for everyone. Read more info about Online Tutoring. So please always share this kind of information. Thanks.

    ReplyDelete
  3. Very well written article. It was an awesome article to read. Read more info about Coding Courses in Adelaide. Complete rich content and fully informative. I totally Loved it.

    ReplyDelete
  4. Great job for publishing such a nice article. Your article isn’t only useful but it is additionally really informative. Thank you because you have been willing to share information with us.IELTS classes in Surrey

    ReplyDelete
  5. You are providing good knowledge. It is really helpful and factual information for us and everyone to increase knowledge.about Online Tutor. Continue sharing your data. Thank you.

    ReplyDelete

Coding for Kids

What is coding? In coding we build a program to do a specific task for us. Code: A code is a set of computer instructions and when you will ...