Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8677553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:29:15+00:00 2026-06-12T20:29:15+00:00

It has to be with just functions, variables, loops, etc (Basic stuff). I’m having

  • 0

It has to be with just functions, variables, loops, etc (Basic stuff). I’m having trouble coming up with the code from scratch from what I’ve I learned so far(Should be able to do it). Makes me really mad :/. If you could give me step by step to make sure I understand I’d really really appreciated. Thanks a bunch in advanced.

How could I get the same result with a simpler code than this one:

var primes=4; 
for (var counter = 2; counter <= 100; counter = counter + 1)
{
    var isPrime = 0;
    if(isPrime === 0){ 
        if(counter === 2){console.log(counter);} 
        else if(counter === 3){console.log(counter);} 
        else if(counter === 5){console.log(counter);} 
        else if(counter === 7){console.log(counter);} 
        else if(counter % 2 === 0){isPrime=0;} 
        else if(counter % 3 === 0){isPrime=0;} 
        else if(counter % 5 === 0){isPrime=0;} 
        else if(counter % 7 === 0){isPrime=0;}
        else {
            console.log(counter);
            primes = primes + 1;
        }
    }
}
console.log("Counted: "+primes+" primes");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:29:16+00:00Added an answer on June 12, 2026 at 8:29 pm

    This finds all prime numbers between 2 and 100:

    var primes=0; 
    var isprime = true;
    for (var counter = 2; counter <= 100; counter = counter + 1)
    {
        // For now, we believe that it is a prime
        isprime = true;
        var limit = Math.round(Math.sqrt(counter)); // See comment from @AresAvatar, below
        // We try to find a number between 2 and limit that gives us a reminder of 0
        for (var mod = 2; mod <= limit; mod++) {
            // If we find one, we know it's not a prime
            if (counter%mod == 0) {
                isprime = false;
                break; // Break out of the inner for loop
            }
        }
    
        if (isprime) {
            console.log(counter, limit);
            primes = primes + 1;
        }
    }
    console.log("Counted: "+primes+" primes");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with a client who has just upgraded from SQL 2000 to SQL
Our WCF service has just one method: [ServiceContract(Name = Service, Namespace = http://myservice/)] [ServiceKnownType(GetServiceKnownTypes,
my co-worker has just create a new branch in the git repository which we
my certificate has just expired. I renewed it on Team section, then renew provisioning
Our team has just started developing for the Sitecore CMS. We find that after
A new colleague has just suggested using named HQL queries in Hibernate with annotations
i just wanted to put a selection on my picturebox.image but this has just
I have an XPage which has just broken due to (what should have been)
How to access the row which has just been inserted into a DB with
How would you explain to someone who has just started programming in Java, what

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.