Best JavaScript program to count number of even digits in a given integer
It best and simple Javascript program to count number of even digits in a given integer.
Output: Javascript program to count number of even digits in a given number
Count Even Digits - ITVoyagers
Total count of even digits is :
Write a Javascript program to count number of even digits in a integer
HTML code
<!DOCTYPE html><html><head><metacharset="utf-8"><title>Count Even Digits - ITVoyagers</title></head><body><inputtype="text"name="val"id="inputvalue"value="1234"><buttonid="count_button"onclick="countDigits()">Count</button><br><divid="outputdiv">
Total count of even digits is : <spanid="outputspan"></span></div><script type="text/javascript"src="counteven.js"></script><!-- itvoyagers.in --></body></html>
Javascript code (counteven.js)
var inputvalue =document.getElementById("inputvalue");
var outputspan =document.getElementById("outputspan");
//itvoyagers.infunction countDigits()
{
var total =0;
var val =parseInt(inputvalue.value);
while(val)
{
val%2===0? total++: total;
val =Math.floor(val/10);
}
outputspan.innerHTML = total;
}