I would add that you can combine that all together into a single expression to build your string or use a fallback string.
You can even do it with expression-scoped variables so you don’t have to have a bunch of other global variables if you don’t need them.
alerts = $context.response.data.alerts
hasAlerts = count(alerts) > 0
myString = map(alerts, concat(x.event, " until ", formatDate(x.end * 1000, "h:mm a")))
join(myString, "\r\n")
hasAlerts ? myString : "No alerts"
So from top to bottom:
- Alias the alerts data with a simpler (expression-scoped) variable
- Check if we even have alerts
- Build the alert string to format the various (potential) events
- If we have events, show the string, otherwise show a default message