Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

1. ## Setting the bgColor from a random number. Help please!

Hi!
I new my webpage to change the bgColor dependent on the outside temperature, which will be randomised. Also, i want to check which month it is first, so I can get an appropriate temperature for the season.
The first three ifs are to check which season it is and then set an appropriate outside temp. After them i have several ifs which i want to set the bgColor depending on the appropriate outside temperature.
I´ve come up with a little bit of code:

Code:
```	var temp = Math.floor(Math.random()*16);

var d = new Date();
var present = (d.getMonth()+1);

if ((present==12)||(present==1)||(present==2)){
newtemp=temp-20;

}

if ((2<present<6)||(8<present<12)){
newtemp=temp-5;

}
if (5<present<8){
newtemp=temp+10;

}

if (newtemp<-9)
{
document.body.style.backgroundColor="#8FD8D8";
}
if(-10<newtemp<-5)
{
document.body.style.backgroundColor="#0276FD";
}
if(-6<newtemp<0)
{
document.body.style.backgroundColor="#B7C3D0";
}
if(1<newtemp<6)
{
document.body.style.backgroundColor="#458B00";
}
if(5<newtemp<11)
{
document.body.style.backgroundColor="##FFE600";
}
if(10<newtemp<16)
{
document.body.style.backgroundColor="#CD0000";
}
if(15<newtemp<26)
{
document.body.style.backgroundColor="#660000";
}```
Would greatly appreciate input!

• this sort of thing won't do at all...
if(-10<newtemp<-5)
it should be ...
if(-10<newtemp && newtemp<-5)

• Okay, thanks!
So if I change that bit it should work?

• Originally Posted by Tengil
Okay, thanks!
So if I change that bit it should work?
Why not try it?

• You have to change every
place you have the
pattern ...

a<b<c

to

a<b && b<c

• Originally Posted by Philip M
Why not try it?
Yeah sorry, I should have before I typed, but I was in a hurry.

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•