You can use something like this:
var count = 0;
// for fields with specific text:
if (this.getField(" field name ").valueAsString == " specific text ") count++;
// for non-empty fields:
if (this.getField(" field name ").valueAsString != "") count++;