'Is there a way to change the color of your website when refreshing it?

I have made a website with one specific theme, is there a way to change the color of the background/text of the website when you refresh it? here is some code which can only change the background. How to make it so it will pick a theme with the text and background



Solution 1:[1]

if you want change color of background or text, use DOM to access this style and edit:

var bgcolorArr = new Array("silver", "#BAF3C3", "#c3baf3", "red", "green", "blue")
document.body.style.backgroundColor = bgcolorArr[Math.floor(Math.random()*bgcolorArr.length)]

Update!! Use Array literals is shorter new Array():

var bgcolorArr = ["silver", "#BAF3C3", "#c3baf3", "red", "green", "blue"]

Solution 2:[2]

You can use Math.random() on background color properties, ex: make the random number between 0-10, then make an array filled with hex values of colors you want. And then set the background or text color based on that Math_random().

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 DhaniAM