<h1>HEX Color: <span id="hex"></span></h1>
<button id="btn" type="button">클릭</button>
var hex = document.getElementById('hex');
var btn = document.getElementById('btn');
console.log(hex);
console.log(btn);
btn.addEventListener('click', function() {
var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f"];
var color = "#"
for(var i = 0; i < 6; i++) {
var random = Math.floor(Math.random() * arr.length);
color += arr[random]; // arr배열[랜덤값]
}
document.body.style.backgroundColor = color;
hex.textContent = color; // textContent; html에 텍스트 적용
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.