I tried to create a switch function called temp() which should allow the display of a definition once inserted a value. Currently this doesn't work at all and I can't understand why
function temp() { var x = parseInt(document.getElementById('temp').value); var y = (document.getElementById('temp1')); switch (x) { case x < 36: y=hypothermia; break; case x > 37: y=hyperthermia; break; case x > 38,5: y=pyrexia; break; default: y.style.display='none'; } }
I also tried to use the "if... else if..." method, but only the first two cases really work, while the rest is just ignored (and I already tried switching orderd).
function temp() { var x = parseInt(document.getElementById('temp').value); var y = (document.getElementById('temp1')); if (x < 36) y.style.background = "yellow",y.style.color = "blue",y.innerHTML = "hypothermia"; else if (x < 37) y.style.display = "none"; else if (x > 37) y.style.background = "yellow",y.style.color = "black",y.innerHTML = "hyperthermia"; else if (x > 38) y.style.background = "red",y.style.color = "black",y.innerHTML = "pyrexia"; }
Aucun commentaire:
Enregistrer un commentaire