I'm having trouble with this code that is supposed to generate a random color. The CSS formatting works perfectly, but I suspect there might be an issue with the function itself. When I try to run the code, it doesn't produce any error messages – it simply doesn't work as expected.
<!DOCTYPE html>
<html>
<head>
<title>
Color Randomizer
</title>
<style>
body{
margin: 0;
padding: 0;
background: #161818;
font-family: "Consolas";
}
.color{
margin-top: 300px;
text-align: center;
}
#hex{
display: block;
color: white;
font-size: 100px;
text-transform: uppercase;
margin: 0px;
}
.color button{
background: none;
outline: 10px;
color: white;
cursor: pointer;
font-size: 40px;
border: 3px solid white;
}
</style>
</head>
<body>
<div class="color">
<span id="hex">#??????</span>
<button onclick="genNewColor()">Generate New Color</button>
</button>
</div>
<script type="text/javascript">
function genNewColor() {
var symbols,color;
symbols = "0123456789ABCDEF";
color = "#";
for(var i =0;i<6;i++){
color = color + symbols[Math.floor(Math.random() * 16)]
}
document.body.style.background = color;
document.getElementById("hex").innerHTML = color
}
</body>
</html>