Prime Number Program in JavaScript

Prime Number Program in JavaScript

Prime Number Program in JavaScript

Using JavaScript you can easily write any programming code, Here we write one of the most popular program Prime Number Program in JavaScript. To perform this task we need for loop and if else condition.

Prime Number Program in JavaScript

<html>
<head>
<script type="text/javascript">

function calcPrimeNumber()
{

 var beginNum = parseInt(document.numbers.firstNum.value);
 var endNum = parseInt(document.numbers.secondNum.value);
 var primeNumbs = new Array();
 var ctr = beginNum;
 while(ctr<=endNum)
{
if(isPrime(ctr)==true)
 {
  primeNumbs[primeNumbs.length] = ctr;
  }
  ctr = ctr+1;
}
 if (primeNumbs.length == 0)
{
document.getElementById('output_content').innerHTML = "There were no prime no within the range.";
 }
 else
 {
 outputPrimeNums(primeNumbs);
  }
}
function isPrime(num)
{
var flag = true;
for(var i=2; i<=Math.ceil(num/2); i++)
 {
if((num%i)==0)
{
flag = false;
 break;
}
}
return flag;    
 }

 function outputPrimeNums(primes)
{
 var html = "<h2>Prime Numbers</h2>";
 for (i=0;i<primes.length;i++){
  html += primes[i] + "<br/>";
 }
 document.getElementById('output_content').innerHTML = html;
 }

</script>
</head>
<body>
<form name="numbers">
Beginning Number: <input type="text" name="firstNum" />
End Number: <input type="text" name="secondNum" />
<input type="button" value="Find Prime Numbers" onclick="calcPrimeNumber()" />

</form>
<div id="output_content">
</div>
</body>
</html>

OutPut:

Start Number: 2
End Number:10
Prime Numbers are
2
3
5
7

739 thoughts on “Prime Number Program in JavaScript”

  1. I’ve been exploring for a little bit for any high-quality articles
    or blog posts in this kind of house . Exploring in Yahoo I
    at last stumbled upon this site. Studying this information So i am glad to exhibit that I’ve an incredibly good uncanny feeling I
    discovered just what I needed. I so much indubitably will make certain to do not omit this web site
    and provides it a glance regularly.

  2. Your style is so unique compared to other people I’ve read stuff
    from. I appreciate you for posting when you
    have the opportunity, Guess I’ll just book mark this web site.

  3. At this time it looks like Expression Engine is the top blogging platform out there right now.

    (from what I’ve read) Is that what you are using on your blog?

  4. Someone essentially help to make seriously articles I might
    state. This is the very first time I frequented your website page
    and to this point? I surprised with the analysis you made to make this actual
    put up amazing. Wonderful task!

  5. You made some decent points there. I checked on the
    internet to learn more about the issue and found most individuals will
    go along with your views on this web site.

  6. I’ve been surfing online more than three hours lately, yet I never found any attention-grabbing article like yours.
    It is lovely value enough for me. In my view, if all site owners and bloggers made
    just right content as you probably did, the web might be a lot more helpful than ever before.

  7. Hello everybody, here every person is sharing these know-how, thus it’s nice to read this webpage, and
    I used to pay a visit this weblog every day.

  8. With havin so much written content do you ever run into any problems
    of plagorism or copyright violation? My site has a lot of completely unique content I’ve either
    authored myself or outsourced but it looks like a lot of it is popping it up all over the
    web without my permission. Do you know any techniques to help
    reduce content from being stolen? I’d definitely appreciate it.

  9. Thanks for the marvelous posting! I actually enjoyed reading it, you might be a great
    author.I will be sure to bookmark your blog and will eventually come back down the road.
    I want to encourage you continue your great job, have a nice afternoon!
    asmr 0mniartist

  10. Hi, I think your blog might be having browser compatibility issues.
    When I look at your blog site in Chrome, it looks fine but when opening in Internet Explorer, it has some overlapping.
    I just wanted to give you a quick heads up! Other then that, fantastic blog!
    asmr 0mniartist

  11. I have been exploring for a bit for any high quality articles or weblog posts on this sort of space
    . Exploring in Yahoo I ultimately stumbled upon this web site.
    Studying this info So i am happy to express that I have a very just
    right uncanny feeling I found out exactly what I needed.

    I so much without a doubt will make certain to don?t fail to
    remember this web site and give it a glance on a constant basis.
    0mniartist asmr

  12. I am really enjoying the theme/design of your website.

    Do you ever run into any browser compatibility problems?
    A small number of my blog readers have complained about my blog not working correctly in Explorer but looks great in Firefox.
    Do you have any ideas to help fix this issue?

  13. I absolutely love your blog.. Very nice colors & theme.
    Did you build this web site yourself? Please reply back as I’m
    hoping to create my very own website and would like to find out where you got this from or just what the theme is named.
    Appreciate it!

  14. I savor, result in I found exactly what I used to be looking for.
    You’ve ended my four day lengthy hunt! God Bless you man. Have a great day.
    Bye

  15. I’m no longer sure the place you are getting your information, however good topic.
    I needs to spend some time studying much more or figuring out more.
    Thanks for fantastic information I was looking for this info for
    my mission.

  16. I don’t even know how I ended up here, but I thought this post was great. I do not know who you are but definitely you’re going to a famous blogger if you are not already 😉 Cheers!|

  17. You really make it appear so easy together with your presentation but I find
    this topic to be really one thing that I believe I might never understand.
    It sort of feels too complicated and very extensive for me.
    I’m looking forward on your subsequent submit, I’ll attempt to get the grasp of it!

  18. I’m not sure why but this weblog is loading extremely slow for me.

    Is anyone else having this problem or is it a problem on my end?

    I’ll check back later on and see if the problem still exists.

  19. I do accept as true with all of the concepts you’ve presented for your post. They are really convincing and will definitely work. Still, the posts are too brief for beginners. May just you please extend them a little from subsequent time? Thanks for the post.|

  20. scoliosis
    I’ve read a few excellent stuff here. Definitely value bookmarking for revisiting.

    I surprise how so much attempt you place to create any such fantastic informative website.
    scoliosis

  21. scoliosis
    We stumbled over here different web address and thought I might as well check things out.

    I like what I see so now i am following you. Look forward to looking over
    your web page repeatedly. scoliosis

  22. scoliosis
    I’ve been surfing online more than three hours today, yet
    I never found any interesting article like yours. It’s pretty worth enough for me.
    In my opinion, if all site owners and bloggers made good content as you did, the web will
    be much more useful than ever before. scoliosis

  23. I have read some good stuff here. Certainly value bookmarking for revisiting.
    I wonder how so much attempt you set to create this sort of
    wonderful informative site.

  24. Hello, i think that i saw you visited my web site so
    i came to “return the favor”.I’m trying to find things
    to enhance my site!I suppose its ok to use some of your ideas!!

  25. I’m not sure exactly why but this site is loading very slow for
    me. Is anyone else having this issue or is it a problem on my end?
    I’ll check back later on and see if the problem still exists.

  26. My partner and I absolutely love your blog and find a lot of your post’s to
    be precisely what I’m looking for. can you offer guest writers to write content
    in your case? I wouldn’t mind composing a post or elaborating on many of the subjects you write
    with regards to here. Again, awesome website!

  27. Link exchange is nothing else except it is just placing the other person’s website link on your page at suitable place and other person will also do same in support of you.

  28. Hi! I could have sworn I’ve visited this website before but after
    looking at a few of the articles I realized it’s new to me.
    Nonetheless, I’m certainly delighted I discovered it and
    I’ll be book-marking it and checking back frequently!

  29. Does your website have a contact page? I’m having a tough time locating it but, I’d like to shoot you an email.
    I’ve got some suggestions for your blog you might be interested in hearing.
    Either way, great blog and I look forward to seeing it improve over time.

  30. Hello there, You’ve done a great job. I’ll definitely digg it and personally suggest to my friends.

    I am sure they will be benefited from this site.

  31. Hi, Neat post. There’s an issue with your site in internet explorer, could check
    this? IE nonetheless is the marketplace leader
    and a huge section of other people will pass over your excellent writing because of this problem.

  32. Hello There. I found your blog using msn. This is a really well written article.
    I will make sure to bookmark it and come back to read more of your useful info.
    Thanks for the post. I will certainly comeback.

  33. fantastic post, very informative. I wonder why the other specialists of this
    sector do not understand this. You should continue your writing.
    I am confident, you’ve a great readers’ base already!

  34. En iyi leke kremi markası

    Türkiyenin lider kozmetik firması olan hccare sizlere en iyi ödüllü
    leke kremi markasını sunuyor,
    Cilt lekelerine karşı kesin çözüm olan bu en iyi leke kremini kullanmadan karar vermemenizi tavsiye ediyoruz.

    En iyi Leke Kremi

  35. I’m impressed, I must say. Rarely do I encounter a blog that’s both equally educative and
    amusing, and let me tell you, you’ve hit the nail
    on the head. The issue is something too few folks are speaking intelligently about.
    Now i’m very happy that I came across this during my hunt for something regarding this.

  36. I like the helpful information you provide in your articles.
    I’ll bookmark your weblog and check again here frequently.

    I’m quite certain I’ll learn lots of new stuff right here!
    Best of luck for the next!

  37. Magnificent goods from you, man. I’ve take into accout your stuff previous to and you are simply extremely wonderful.
    I really like what you’ve obtained here, certainly like what
    you are stating and the way in which in which you
    say it. You make it entertaining and you still take
    care of to stay it wise. I can’t wait to read far more from you.
    That is actually a tremendous website.

  38. It’s a pity you don’t have a donate button! I’d most certainly donate
    to this fantastic blog! I guess for now i’ll settle for
    bookmarking and adding your RSS feed to my Google account.
    I look forward to brand new updates and will talk about this website with my
    Facebook group. Talk soon!

  39. Admiring the time and energy you put into your site and in depth information you
    provide. It’s great to come across a blog every
    once in a while that isn’t the same out of date rehashed material.
    Wonderful read! I’ve bookmarked your site and
    I’m including your RSS feeds to my Google account.

  40. Definitely imagine that that you stated. Your favorite
    reason seemed to be at the net the simplest thing to understand of.
    I say to you, I certainly get annoyed even as other people think about issues that they just don’t recognize about.
    You managed to hit the nail upon the highest and outlined out the entire thing with no need side effect , people can take
    a signal. Will likely be back to get more.
    Thank you

  41. Hi! I could have sworn I’ve been to this blog before
    but after looking at some of the posts I realized it’s new to me.
    Nonetheless, I’m certainly delighted I stumbled upon it
    and I’ll be book-marking it and checking back regularly!

  42. Pingback: ivermect tablet
  43. I absolutely love your site.. Great colors & theme. Did you
    develop this site yourself? Please reply back as I’m trying to create my own site
    and would like to learn where you got this from or what the theme is
    called. Thank you!

  44. It is really a nice and helpful piece of information. I’m satisfied that you just shared this useful information with
    us. Please stay us up to date like this. Thank you for
    sharing.

  45. I absolutely love your blog and find many of your post’s to be precisely
    what I’m looking for. Would you offer guest writers to write
    content for you? I wouldn’t mind publishing a
    post or elaborating on many of the subjects you write about
    here. Again, awesome web site!

  46. This is really attention-grabbing, You’re an excessively skilled blogger.
    I’ve joined your feed and sit up for in search of more of
    your great post. Also, I’ve shared your website in my social networks

  47. Wow, superb weblog format! How lengthy have you been blogging for?
    you make blogging look easy. The whole glance of your web site
    is great, as neatly as the content material!

  48. Oh my goodness! Awesome article dude! Thank you, However I am encountering
    difficulties with your RSS. I don’t understand
    the reason why I am unable to join it. Is there anyone else
    getting identical RSS problems? Anyone that knows the answer can you kindly
    respond? Thanx!!

  49. Hey there! This is kind of off topic but I need some advice
    from an established blog. Is it difficult to set up your own blog?
    I’m not very techincal but I can figure things out pretty
    fast. I’m thinking about making my own but I’m not sure where to start.
    Do you have any points or suggestions? Thank you

  50. Hello just wanted to give you a quick heads up and let you
    know a few of the pictures aren’t loading properly.
    I’m not sure why but I think its a linking issue.
    I’ve tried it in two different web browsers and both show
    the same results. ps4 https://bitly.com/3z5HwTp ps4 games

  51. Hello would you mind stating which blog platform you’re working
    with? I’m going to start my own blog in the near future but I’m having a
    hard time making a decision between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your layout seems different
    then most blogs and I’m looking for something completely unique.
    P.S My apologies for getting off-topic but I had to ask!
    scoliosis surgery https://coub.com/stories/962966-scoliosis-surgery scoliosis
    surgery

  52. Pingback: MKsOrb
  53. Pingback: viagra buy greece
  54. Pingback: cialis en ligne
  55. Pingback: One Time Email
  56. Pingback: stromectol 100mg
  57. hello my lovely stopforumspam member

    What are the Types of Loans in Ohio depending on the purpose
    Specific purpose payday loans in Ohio. Funds received in debt may be spent only for a specific purpose specified in the loan agreement.
    Non-purpose loan. The debtor may spend the money received at his discretion.
    Most popular specific purpose payday loans in Ohio are:

    House loan. The most common, of course, is a mortgage when the purchased property acts as collateral for a loan. Sometimes a youth loan is issued, with lighter conditions for debtors. Still quite common is a housing loan that does not imply purchased housing in the form of collateral.
    Car loan – payday loans in Ohio to a car or similar vehicle. The key is often the purchased goods, making the terms of the loan better. Also, loan conditions are improved: car insurance, life and health insurance of the borrower, and receiving a salary to the account of the creditor bank.
    Land loan. To purchase a plot for construction or agricultural activities.
    Consumer. For purchases in modern supermarkets, equipment stores, you can take a personal loan right at the point of sale. Often, specialists located there can contact the bank and get a regular or fast payday loans. Borrowed funds automatically pay for the goods, and the consultant explains when and how to re-pay the debt.
    Educational loan. It is issued to students, as well as to applicants who have passed the competition, to pay for tuition at universities, colleges, etc.
    Broker loan. For the circulation of securities, payday loans in Ohio are issued to an exchange broker, se-curities are purchased securities.
    Others. Objectives not related to those listed, but agreed and approved by the creditor.

  58. hello my lovely stopforumspam member

    Welcome to Grosvenor Casinos, where you can play a wide range of casino games, from slots to poker, blackjack, and roulette! There’s something for everyone here – become a member of the casino to have the best of online casino gaming. Our Sportbook offers a range of sports betting odds and is available for pre event or in play bets 24/7 and 365 days of the year. Whether you’re here for football tournaments or the latest betting odds for horse racing, Tennis, Golf, Cricket and even Rugby Union, you are covered.

Leave a Reply

Your email address will not be published.