Printing all the prime numbers between 0 and 100

I’d appreciate a lot if you could point out what I am doing wrong with my code.

ReferenceError: Invalid left-hand side in assignment

``````for (var counter = 0; counter <= 100; counter = counter + 1)
{
for (var x = 2; x < counter; x = x + 1)
{if(counter % x = 0)
{
console.log(counter);
}
}

}
``````

Very many thanks,
Masa

This post was flagged by the community and is temporarily hidden.

Thank you. I could fixed the error. But my code is not correct yet, to get prime numbers between 0 and 100.

``````for (var counter = 0; counter <= 100; counter = counter + 1)
{
for (var x = 2; x < counter; x = x + 1)
{if(counter % x != 0)
{
console.log(counter);
}``````

Your dan’t closed your curly brackets. You have only `if(counter % x != 0)` closed properly. Your code should look like:

``````for (var counter = 0; counter <= 100; counter = counter + 1) {
for (var x = 2; x < counter; x = x + 1) {
if (counter % x != 0) {
console.log(counter);
}
}
}
``````

You should rethink your algorithm. Now it’s printing all numbers (multiple times). For finding prime number you could read about Sieve of Eratosthenes, I think it is one of the most efficient ways to find all of the smaller primes.