Skip to main content
Known Participant
October 5, 2024
Answered

count if a letter that you find in all months of the year counts

  • October 5, 2024
  • 1 reply
  • 915 views

Help! I have to count (A) how many times it occurs in the months (therefore in all the days of the year)
I add a code:
var total = 0;
for (var i=1; i<=12; i++) {
for (var j=1; j<=31; j++) {
var f = this.getField("Day"+i+"_"+j);
if (f.valueAsString =="A") total++;

}
}
event.value = total;

This topic has been closed for replies.
Correct answer try67

If I want to color text A in red, what can I do?


Change this:

if (f.valueAsString =="A") total++;

To:

if (f.valueAsString =="A") {
	total++;
	f.textColor = color.red;
} else f.textColor = color.black;

1 reply

try67
Community Expert
Community Expert
October 5, 2024

Since there aren't 31 days in each month, you should probably include code that skips missing fields (unless you have created those fields and they are always empty). Beside that, the code seems fine. What happens when you use it?

Known Participant
October 5, 2024

the months ending on the 30th are left blank.. the problem is that

for (var i=1; i<=12; i++)

doesn't count for me, by checking month by month it reaches July and then it no longer counts as never? Thank you

try67
Community Expert
Community Expert
October 5, 2024

Check the JS Console for error messages.