Java code(1)
Java code(1)
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>