JS If statements are not working

Hi guys,
I apologise for any complexity of the following script, but what I am trying to achieve is
1.) At 6:51 am, the image sunrise.png is written as the background of #wrap
2.) At 12:04 midnight through 12:07 midnight, the background of #wrap is green.png
then
3.) Then, at a random time at night that is not 6:51 am nor in-between 12:04 midnight & 12:07 midnight, the background of #wrap is set as aurora.png

This is the code of if statments that I wrote to achieve it:

<script type="text/javascript">
			var timeMinutes=new Date();
			var timeHours=new Date();
			var sunriseHour=6;
			var sunriseMinutes=51;
			var greenHour=0;
			var greenMinutes=4;
			var greenMinutesEnd=7;
			var randomTime=Math.floor(Math.random()*11);
			var randomTimeEnd=randomTime + 1;
	
			if(randomTime=sunriseHour)
				{
					randomTime=Math.floor(Math.random()*11);
				}
			else if(randomTime=greenHour)
				{
					randomTime=Math.floor(Math.random()*11);
				}
			else {
				if(timeHours.getHours()=sunriseHour && timeMinutes.getMinutes()=sunriseMinutes)
					{
						document.write('<style type="text/css">#wrap{background:transparent url(img/sunrise.png) center top no-repeat;}.headerText span{color:#3c0376; text-shadow:none;}</style>');
					}
				else if((timeHours.getHours()=greenHour && timeMinutes.getMinutes()=greenMinutes) || (timeHours.getHours()=greenHour && ((timeMinutes.getMinutes()<greenMinutesEnd) && (timeMinutes.getMinutes()>greenMinutes))))
					{
						document.write('<style type="text/css">#wrap{background:transparent url(img/green.png) center top no-repeat;}.headerText span{color:#3c0376; text-shadow:none;}</style>');
					}
				else if(timeHours.getHours()=randomTime || timeHours.getHours()<randomTimeEnd)
					{
						document.write('<style type="text/css">#wrap{background:transparent url(img/aurora.png) center top no-repeat;}</style>');
					}
				else{
					document.write('<style type="text/css">#wrap{background:transparent url(img/space.png) center top no-repeat;}</style>');
				}
			}
		</script>

It is not producing any errors, but it is not wroking either.

Would anyone be willing to help me fix it and see if I am trim it down any?

I would really appreciate any help :slight_smile:

Thanks in Advance & I hope to hear from you soon,
Team 1504

if(randomTime=sunriseHour)

this assigns the value of sunriseHour to randomTime and then tests if randomTime is true.

Did you perhaps mean:

if(randomTime===sunriseHour)

which compares randomTime to sunriseHour and if they are identically equal returns true

Thank you that worked perfectly.

I thought about that, but stupid w3schools told me the single = was okay. :frowning:

I am seriously considering not using them as a resource anymore because they already damaged my knowledge of CSS a few years ago and now this…

Thank you again & Kind Regards,
Team 1504

Does the random time at night that is not occupied by the other set times logic look good?