You need to understand
the difference between Java and JavaScript, this forum is for the latter.
That being said there are two ways to attack this problem (maybe more...). One is to loop through the string and count the dots (by comparing to '.'), the other is to remove all non-dots (possibly with a regular expression) and then to get the length of the remaining string.