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
3 Respostas
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.
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.
0
Lisa can you demonstrate?.i didn't quite got it