I have a JavaScript function that is getting data out of a JSON file and then doing some formatting to it. The code works but I feel like it just an awful way of doing it. All criticism and help appreciated.
function MCScrap(ZWA, ZWB, ZWC, ZWD, Number) {
$(document).ready(
function() {
setInterval(function() {
$.getJSON("mccount.json", function(machines) {
console.log(machines);
var Tcount = machines.Machines[Number].Tcount;
var Ycount = machines.Machines[Number].Ycount;
var TScount = machines.Machines[Number].TScount;
var YScount = machines.Machines[Number].YScount;
document.getElementById(ZWA).innerHTML = Ycount;
document.getElementById(ZWB).innerHTML = Tcount;
document.getElementById(ZWD).innerHTML = TScount + "%";
document.getElementById(ZWC).innerHTML = YScount + "%";
if (TScount < 3) {
document.getElementById(ZWB).style.backgroundColor = 'lime';
} else if (TScount < 5) {
document.getElementById(ZWB).style.backgroundColor = 'orange';
} else {
document.getElementById(ZWB).style.backgroundColor = 'red';
}
if (YScount < 3) {
document.getElementById(ZWA).style.backgroundColor = 'lime';
} else if (YScount < 5) {
document.getElementById(ZWA).style.backgroundColor = 'orange';
} else {
document.getElementById(ZWA).style.backgroundColor = 'red';
}
}
);
}, 3000);
});
}