How to find the remainder without using modulo operator in JavaScript

2 Answers

0 votes
const n = 27;
const divisor = 6;
      
let remainder = n;
  
while (remainder >= divisor) {
       remainder = remainder - divisor;
}
  
console.log("The remainder is: " + remainder);

  
  
  
  
/*
run:
  
"The remainder is: 3"
  
*/

 



answered May 18, 2022 by avibootz
0 votes
const n = 27;
const divisor = 6;
      
const remainder = n - divisor * parseInt(n / divisor);
  
console.log("The remainder is: " + remainder);

  
  
  
  
/*
run:
  
"The remainder is: 3"
  
*/

 



answered May 18, 2022 by avibootz

Related questions

2 answers 223 views
2 answers 200 views
2 answers 205 views
2 answers 250 views
2 answers 209 views
2 answers 180 views
...