0

How to find prime numbers from 1 to n

I write it in javascript and can you correct me? https://code.sololearn.com/WZ6BNRklg1Fn/?ref=app

27th Jul 2022, 11:46 AM
k gready
k gready - avatar
3 ответов
0
You code only returns 1 number, but the task description indicates that you should return all prime numbers. Also you are only checking if n is a multiple of 2, not if it is a prime. Your current code will only ever retur 2 or 3.
27th Jul 2022, 11:58 AM
Lisa
Lisa - avatar
0
Put the if statement inside a for loop, then change the n to whatever variable you used for the loop. Also, you need a counter variable instead of the 'prime' variable for holding the count. Finally, return the counter. Edit: Also, to be a prime number, number%2 should be 1 not 0.
27th Jul 2022, 11:59 AM
Lama
Lama - avatar
0
Lisa can you demonstrate?.i didn't quite got it
27th Jul 2022, 12:03 PM
k gready
k gready - avatar