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 201 views
2 answers 176 views
2 answers 178 views
2 answers 227 views
2 answers 176 views
2 answers 161 views
...