How to fix endless loop repetition?
-
It should look like this:
set 2 parameters to prompt ()
you need the function to display only prime numbers from the range
Problem:
If a composite number comes across, the function starts executing indefinitely.
Doesn't give out the number 3
UPD:
when it comes to two-digit numbers, it can be duplicated several times.
var input1 = prompt('Write first number'); var input2 = prompt('Write second number'); let Res = 'Res: '; let simpleNumber = function (start, end) { let range = start; while (range <= end || range == start) { if (range == 2) { Res += `${range} `; } let i = 2; let limit = Math.sqrt(range); while (i <= limit) { if(range % i === 0){ continue; } i+= 1 Res += `${range} `; } range++; } console.log(Res); } simpleNumber(input1, input2);
JavaScript Lorelei Levy, Nov 12, 2020 -
while (i <= limit) {
if(range % i === 0){
continue;
}
Well, what do you want, this is where it gets hung up on the composite. Break instead of continueAnonymous
1 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!