this is a simple color change project and on the surface it looks like it should work but either the JS file isn't loading or ive made a simple error, i cant work it out! Any help appreciated! The idea is you press the button ands the BG changes to a random hex color and the text changes to the hex code.
HTML
<!DOCTYPE html>
<hmtl lang="en">
<head>
<script src="script.js"></script>
</head>
<body>
<h1 id="text">Background Color</h1>
<button id="button">Change BG-Color</button>
</body>
</hmtl>
javascript
let button = document.getElementById('button');
let text = document.getElementById('text');
let body = document.querySelector('body');
let number = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F'];
button.addEventListener('click', colorChange);
function colorChange() {
let hex = '#';
for (let i = 0; i < 6; i++) {
const index = Math.floor(Math.random() * number.length);
hex += number[index];
}
text.textContent = hex;
body.style.backgroundColor = hex;
}