JavaScript Program to find remainder without using the modulus operator

In this program, you will learn how to find remainder without using the modulus operator in JavaScript.


while (x >= y) {
  x = x - y
}

JavaScript Program to find remainder without using the modulus operator

Example: How to find remainder without using the modulus operator in JavaScript

let x = parseInt(prompt("Enter first number"))
let y = parseInt(prompt("Enter second number"))

while (x >= y) {
  x = x - y
}

console.log("Remainder is:" + x)

Output:

Enter first number> 10
Enter second number> 3
Remainder is:1