-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhex.js
More file actions
19 lines (17 loc) · 976 Bytes
/
hex.js
File metadata and controls
19 lines (17 loc) · 976 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const hex = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F"];
const btn = document.getElementById("btn");
const color = document.querySelector(".color");
btn.addEventListener("click", function () {
// funcion del boton
let hexColor = "#"; // la sintaxis inicial con la que empieza un color hexadecimal
for (let i = 0; i < 6; i++) {
// el bucle que permite la creacion de los 6 digitos
hexColor += hex[getRandomNumber()]; // la creacion del colo, # + 6 elemento aleatoreos provenientes del array hex
}
color.textContent = hexColor; // modificacion del nombre segun el color presentado en pantalla
color.style.color = hexColor; // modificacion del color de las letras
document.body.style.backgroundColor = hexColor; // modificacion del background
});
function getRandomNumber() {
return Math.floor(Math.random() * hex.length); // funcion que permite escoger un numero entero aleatorio en base a los elementos del array
}