I've got an assignment to write a js code using only loops that recieves a number from a user and prints out all the prime numbers between 1 and that number.
Thats what I've done, but its not working as I expect it to, cant find what Im missing:
var num = parseInt(prompt('Please enter a number'));
var flag = 0;
for (var i=2 ; i<=num ; i++){
for (var j=2 ; j<num ; j++){
if (num%j==0){
flag = 1;
break;
}
}
if (flag==0) console.log(i);
if (flag==1) flag=0;
}