-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
24 lines (19 loc) · 683 Bytes
/
app.js
File metadata and controls
24 lines (19 loc) · 683 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//Seleccionar Elementos del DOM
const boton = document.querySelector('button');
const color = document.getElementById('color');
function generarColorHexaAleatorio(){
let digitos = '0123456789ABCDEF';
let colorHex = '#';
for(let i = 0; i<6;i++){
let indiceAleatorio = Math.floor(Math.random()*16)
colorHex += digitos[indiceAleatorio]
}
return colorHex;
}
boton.addEventListener('click', function (){
let colorAleatorio = generarColorHexaAleatorio();
//Actualizar el texto
color.textContent = colorAleatorio;
//Actualizar el color de fondo
document.body.style.backgroundColor= colorAleatorio;
})