Using one of the powerful features of JavaScript, we can write a program that generates a random background color every time we refresh the page.
<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Generate Random Background Color</title>
</head>
<body onload="randomBackground()">
<script>
randomBackground = () => {
let x = Math.floor(Math.random() * 256)
let y = Math.floor(Math.random() * 256)
let z = Math.floor(Math.random() * 256)
let bgColor = `rgb(${x}, ${y}, ${z})`
document.body.style.background = bgColor;
}
randomBackground()
</script>
</body>
</html>
When we refresh our page, this is what we get:
This is how we generate random background colors using Javascript
Neumorphism design, alternatively termed as "soft UI" or "new skeuomorphism," represents a design trend that…
Debugging JavaScript code can sometimes be challenging, but with the right practices and tools, you…
Service Workers are one of the core features of modern web applications, offering powerful capabilities…
A database-driven website is a dynamic site that utilizes a database to store and manage…
Toasts are user interface elements commonly used in software applications, especially in mobile app development…
JavaScript has long been synonymous with frontend web development, powering interactive and dynamic user interfaces…