Hi,
I am trying to set an image based on temperature but I get repeating images instead of the no-repeat and cover I set in the css. What do you think I am doing wrong?
<!DOCTYPE html>
<!-- -->
<html lang="en">
<head>
<title>Change Image</title>
<style>
body {
background: url(../images/trees.jpg);
background-repeat: no-repeat;
background-size: cover;
background-origin: content-box;
padding-top: 40px;
margin-top: 30px;
margin-left: 55px;
background-color: #8b9ab2;
color: #30270b;
}
</style>
<script>
//var body = document.getElementsByTagName("body")[0];
var cTemp;
cTemp = 363;
function changeImage()
{
switch (true) {
case (cTemp > 353): // tempeture is greater than 90
document.getElementsByTagName("body")[0].style.background = "url(../images/water-fountain.jpg)";
//document.getElementsByTagName("body")[1].style.background-repeat = no-repeat;
//document.getElementsByTagName("body")[2].style.background-size = cover;
break;
case ( cTemp > 353): // tempeture is greater than 80
document.getElementsByTagName("body")[0].style.background = "url(../images/trees.jpg)";
//document.getElementsByTagName("body")[1].style.background-repeat = no-repeat;
// document.getElementsByTagName("body")[2].style.background-size = cover;
break;
case (cTemp >= 333): // tempeture is greater than 60
document.getElementsByTagName("body")[0].style.background = "url(../images/blueskytrees.jpg)";
//document.getElementsByTagName("body")[1].style.background-repeat = no-repeat;
//document.getElementsByTagName("body")[2].style.background-size = cover;
// document.getElementsByTagName("body").style.background = url(../images/blueskytrees.jpg);
break; // it encounters this break so will not continue into 'case 2:'
case (cTemp > 313): // tempeture is greater than 40
document.getElementsByTagName("body")[0].style.background = "url(../images/pondwithducks.jpg)";
//document.getElementsByTagName("body")[1].style.background-repeat = no-repeat;
// document.getElementsByTagName("body")[2].style.background-size = cover;
// document.getElementsByTagName("body").style.background = url(../images/pondwithducks.jpg);
break;
default:
document.getElementsByTagName("body")[0].style.background = "url(../images/pondwithducks.jpg)";
//document.getElementsByTagName("body")[1].style.background-repeat = no-repeat;
//document.getElementsByTagName("body")[2].style.background-size = cover;
}
}
</script>
</head>
<body onload = "changeImage()">
</body>
</html>