它必须只有函数、变量、循环等(基本的东西)。从我到目前为止所学到的知识(应该能够做到)中,我无法从头开始编写代码。让我真的很生气:/。如果你能一步一步地给我以确保我理解我真的很感激。非常感谢。
我怎么能用比这个更简单的代码得到相同的结果:
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");