Skip to content

Instantly share code, notes, and snippets.

@nathanpuls
Last active April 1, 2024 19:56
Show Gist options
  • Save nathanpuls/5fd13a50b496f6552c05bc110ca39f6f to your computer and use it in GitHub Desktop.
Save nathanpuls/5fd13a50b496f6552c05bc110ca39f6f to your computer and use it in GitHub Desktop.
function.txt
function changeBackgroundColor() {
// Generate random values for red, green, and blue components
const red = Math.floor(Math.random() * 256);
const green = Math.floor(Math.random() * 256);
const blue = Math.floor(Math.random() * 256);
// Construct a CSS color string
const randomColor = `rgb(${red}, ${green}, ${blue})`;
// Apply the random color to the background
document.body.style.backgroundColor = randomColor;
}
// Call the function to change the background color
changeBackgroundColor();
console.log("bg color");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment