Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
<!DOCTYPE html>
<html>
<head>
<title>Given a number count trailing zeros!</title>
<meta charset="UTF-8">
</head>
<body>
This is different from counting trailing zeroes from a given factorial.
<script>
function countTrailingZeros(input){
if(input === undefined || input < 10){
return 0;
}
var count = 0, multipleOfTen = 10, newvalue=0;
for(var i = 1; multipleOfTen <= input; i++) {
newvalue = parseInt(input/multipleOfTen);
if((newvalue * multipleOfTen ) === input){
multipleOfTen = multipleOfTen * 10;
count ++;
}else{
break;
}
}
return count;
}
console.log(countTrailingZeros(1000));
console.log(countTrailingZeros(1200));
console.log(countTrailingZeros(1230));
console.log(countTrailingZeros(1234));
console.log(countTrailingZeros(4));
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment