Q:

Write a JavaScript program to divide an integer by another integer as long as the result is an integer and return the result

0

Write a JavaScript program to divide an integer by another integer as long as the result is an integer and return the result.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

function divide_digit(num, d) {
       if (d==1)
         return num;
       else
       {
      while (num % d === 0) {
        num /= d;
        }
    return num;
       }
}
console.log(divide_digit(-12, 2))
console.log(divide_digit(13, 2))
console.log(divide_digit(13, 1))

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now