Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
11 views

Java code(1)

The document contains JavaScript and HTML code for a color flipper application. Users can change the background color of the webpage to predefined colors (green, red, blue) or a random color using buttons. The JavaScript functions handle the color changes and random color generation.

Uploaded by

21ke22i9358
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Java code(1)

The document contains JavaScript and HTML code for a color flipper application. Users can change the background color of the webpage to predefined colors (green, red, blue) or a random color using buttons. The JavaScript functions handle the color changes and random color generation.

Uploaded by

21ke22i9358
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

JAVA Code

const body=document.getElementsByTagName("body")[0]
body.style.backgroundColor="lightblue"
function setcolor(name){
body.style.backgroundColor= name;
}
function randomcolor(){
const red = Math.round(Math.random()*225)
const green = Math.round(Math.random()*225)
const blue = Math.round(Math.random()*225)
const color =`rgb(${red},${blue},${green})`
body.style.backgroundColor= color;
}

HTML code
<!DOCTYPE html>
<html lang ="en">
<head>
<title>color flipper</title>
<style>
#green {
background-color: greenyellow;
}
#red{
background-color: red;

}
#blue{
background-color: blue;
}
button{
border-radius: 5px;
width: 100px;
height: 40px;
margin: 5px;
}
</style>
</head>
<body>
<h3>color flipper</h3>
<button id="green" onclick="setcolor('green')">Green</button>
<button id="red" onclick="setcolor('red')">Red</button>
<button id ="blue" onclick="setcolor('blue')">blue</button>
<button id ="random" onclick="randomcolor()">Random</button>
<script src="main.js"></script>
</body>
</html>

You might also like