I am looking to dynamically change the text color between red and green based on a numeric value received from an external source (API).
If the value is greater than or equal to 50, it should be displayed in red. If it's less than 50, then it should be displayed in green.
Any suggestions on how to achieve this?
Chris
const api = "https://services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/RKI_Landkreisdaten/FeatureServer/0/query?where=county%20%3D%20%27SK%20stuttgart%27&outFields=cases,deaths,county,last_update,cases7_per_100k,recovered&returnGeometry=false&outSR=4326&f=json";
fetch(api).then((response) => {
return response.json();
}).then((json) => {
const cases = json.features[0].attributes.cases;
const deaths = json.features[0].attributes.deaths;
const cases7Per100k = json.features[0].attributes.cases7_per_100k;
const recovered = json.features[0].attributes.recovered;
const lastUpdate = json.features[0].attributes.last_update;
console.log(cases7Per100k)
document.getElementById("cases7Per100k").innerHTML = Math.round(cases7Per100k * 10) / 10 || 0;
});
<p id="cases7Per100k"></p>