Help please write the code on js, which is looking for the number of numbers from 1 to 1000 in which there is a number 3. It is desirable with the help of the remainder of the division. I tried to solve this, but I do not see numbers of type 931.

let count = 0; for(var i = 1; i<=1000;i++) { if (i%10==3 || i%100===30 || i%1000===300 || ~~((i/1000)*10)/10==0.3 || ~~((i/100)*10)/10==0.3){ count++; document.write(i+"<br/>")} } alert(count) 
  • 3
    On this site, so that the question is not zaminusovali and closed, it is necessary to supplement it with its own attempts to cope with the problem. The reason why . Thank. - Sasha Chernykh
  • And why is it desirable with the help of the remainder of the division? - Enikeyschik
  • @ Enikeyschik Because it’s so written in the assignment, obviously - Darth

1 answer 1

 let count = 0, num = 1000; const check3 = num => num%10 === 3 || num > 9 && check3(Math.floor(num/10)); while(count += check3(num--), num); console.log(count); // 931 видит - console.log(check3(931))