-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
32 lines (27 loc) · 1.22 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const drawButton = document.querySelector(".draw-button"); // armazena o botão de sorteio
// função para realizar o sorteio de números aleatórios
function drawNumber() {
const min = Math.ceil(document.querySelector(".input-min").value);
const max = Math.floor(document.querySelector(".input-max").value);
const resultElement = document.getElementById("result-number");
if (min >= max) {
alert("O valor mínimo não pode ser maior ou igual ao valor máximo!")
} else {
const result = Math.floor(Math.random() * (max - min + 1)) + min;
// classe result-hidden para ocultar o resultado
resultElement.classList.add("result-hidden");
setTimeout(() => {
resultElement.style.opacity = 1;
resultElement.innerHTML = result;
// remove a classe result-hidden para exibir o resultado com a transição
resultElement.classList.remove("result-hidden");
}, 100);
};
};
// função para tocar o arquivo de áudio ao clicar no botão
function playAudio() {
const audio = document.getElementById("myAudio")
audio.play()
}
// event listener para observar quando o botão for clicado
drawButton.addEventListener("click", drawNumber);