Im trying to create a HEX code generator and display it on a heading but the problem is it doesnt overwrite the text inside the heading instead it only placed adjacent to it.
let hexGenerator = {
result: '',
characters: 'ABCDEF0123456789',
hexColor: function() {
for (let i = 0; i < 6; i++) {
this.result += this.characters.charAt(Math.floor(Math.random() * this.characters.length));
}
return this.result;
}
}
window.onload = () => {
document.querySelector('button').addEventListener('click', () => {
document.getElementById('demo').innerHTML = 'HEX VALUE: #' + hexGenerator.hexColor();
})
}
<body>
<h1 id="demo">HEX VALUE: #</h1>
<button>Click Me!</button>
</body>