Q:

Write a JavaScript program to find the number of even digits in a given integer

0

Write a JavaScript program to find the number of even digits in a given integer.

All Answers

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

function even_digits(num) {
  var ctr = 0;
  while (num) {
    ctr += num % 2 === 0;
    num = Math.floor(num / 10);
  }
  return ctr;
}

console.log(even_digits(123));
console.log(even_digits(1020));
console.log(even_digits(102));

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