My goal is to create a button that generates two random color codes. Initially, this button seems to work fine on the first click, but on the second click, both codes turn into #000000.
Despite my attempts to troubleshoot the issue, I haven't been able to find a solution. I would greatly appreciate any advice on how to fix this problem.
var css = document.querySelector("h3");
var color1 = document.querySelector(".color1");
var color2 = document.querySelector(".color2");
var body = document.getElementById('gradient')
var random1 = document.getElementById("random1");
var random2 = document.getElementById("random2");
var colorGenerator = "1234567890ABCDEF";
var colortag1 = "#";
var colortag2 = "#";
...
Color1.addEventListener("input", backgroundcolor);
Color2.addEventListener("input",backgroundcolor);
Random1.addEventListener("click", randomColor);
body {
font: 'Raleway', sans-serif;
color: rgba(0,0,0,.5);
text-align: center;
text-transform: uppercase;
letter-spacing: .5em;
top: 15%;
background: linear-gradient(to right, red , yellow); /* Standard syntax */
}
h1 {
font: 600 3.5em 'Raleway', sans-serif;
color: rgba(0,0,0,.5);
text-align: center;
text-transform: uppercase;
letter-spacing: .5em;
width: 100%;
}
h3 {
font: 900 1em 'Raleway', sans-serif;
color: rgba(0,0,0,.5);
text-align: center;
text-transform: none;
letter-spacing: 0.01em;
}
button {
color: rgba(0,0,0,.5) ;
font: 800 1em 'Raleway', sans-serif;
background-color: transparent;
border: none;
overflow: hidden;
outline: none;
}
<!DOCTYPE html>
<html>
<head>
<title>Gradient background</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body id="gradient">
<h1>Backround Generator</h1>
<input class="color1" type="color" name="color1" value="#FF0000">
<input class="color2" type="color" name="color2" value="#FFFF00">
<h2>Current CSS Background</h2>
<button id="random1">Random Colors</button>
<h3></h3>
<script type="text/javascript" src="script.js"></script>
</body>
</html>