I would like my buttons to change the color every time the page refreshes. I made a java script code that is not working and would like help identifying my error.
<script>
let r = Math.floor(Math.random()*255),
g = Math.floor(Math.random()*255),
b = Math.floor(Math.random()*255);
document.button.style.backgroundColor='rgb('+r+','+g+','+b+')';
</script>
Would that be the right way?
<!DOCTYPE html>
<html lang="PT-BR">
<head>
<meta charset="UTF-8"/>
<title>Menu inicial</title>
<style>
@font-face{
font-family: 'FontLogo';
src: url("../_fonts/bubblegum-sans-regular.otf");
}
body{
background-color: lightgrey;
background-image: url("_imagen/background body menu.jpg");
background-repeat:no-repeat;
background-size: 100%;
}
section{
padding: 20px;
background-color: #4CAF50;
margin: 0px 200px;
font-size: 50px;
text-transform: uppercase;
text-align: center;
color: white;
font-family: 'FontLogo',sans-serif;
font-weight: bold;
}
form {
padding: 262px;
margin-left: 200px;
margin-right: 200px;
margin-top: 20px;
margin-bottom: 20px;
border: 0px solid #f1f1f1;
background-color: rgba(0,0,0,.6);
box-shadow: -3px 4px 29px 2px rgba(0,0,0,.6);
}
button{
padding: 50px;
margin: 10px;
}
</style>
</head>
<body>
<script>
let r = Math.floor(Math.random()*255),
g = Math.floor(Math.random()*255),
b = Math.floor(Math.random()*255);
document.button.style.backgroundColor='rgb('+r+','+g+','+b+')';
</script>
<section id="letrero">menu inicial</section>
<form>
<button type="submit">Cadastro</button>
<button type="submit">Consulta</button>
<button type="submit">Relatorio</button>
</form>
</body>
</html>