There has been a similar post in the past, but I still need a little help because I’m not that experienced with javascript. I’m trying to change the font color based off the score, here’s what I have right now on one page of the website.
let score_comp = Math.round(((score-557)/557)*100);
let comparison= "abc";
let textcolor = "#FFFFFF"
if(score_comp<0){
comparison = "Lower than average American by " + Math.abs(score_comp) + "%";
textcolor = "#26D454";
} else if (score_comp>0){
comparison = "Higher than average American by " + score_comp + "%";
textcolor = "#FF4040";
} else {
comparison = "Equal to that of the average American." ;
}
local.setItem("SChouse_comparison", comparison);
local.setItem("SChouse_color", textcolor);
Then in the main page where the color should be displayed
$w("#" + section + "comp").text = local.getItem("SC" + section + "_comparison");
if( $w("#" + section + "comp").hidden ) {
$w("#" + section + "comp").show();
}
if ($w("#" + section + "comp").visible) {
let value = $w("#" + section + "comp").text;
let color = local.getItem("SC" + section + "_color");
$w("#" + section + "_comp").html = "<p style = 'color: " + color + ";'>" + value + "</p>";
}
The problem right now is that the text is displaying and everything else is working, but it always appears as white and does not change colors. Thanks!