-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (40 loc) · 1.37 KB
/
index.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const elementoResposta = document.querySelector("#resposta")
const imputPergunta= document.querySelector("#imputPergunta")
const botaoPerguntar = document.querySelector("#botaoPerguntar")
const respostas = [
"Sim",
"Claro que sim",
"Mas é obvio que sim",
"É possivel que sim",
"Talvez Não",
"Talvez Sim",
"Possivelmente não",
"Não entedi, pergunte novamente",
"Você vai se surpreender...",
"Tudo indica que não",
"Não estou vendo... Pergunte novamente."
]
// fazer pergunta
function fazerPergunta(){
//input pergunta
if(imputPergunta.value== ""){
alert("Digite uma pergunta primeiro.")
return
}
//corrigir bug da resposta != para mesma pergunta
botaoPerguntar.setAttribute("disabled", true)
// jogar a pergunta na tela
const pergunta = "<div>" + imputPergunta.value + "</div>"
//gerar valores aleatórios
const totalRespostas = respostas.length
const numAleatorio = Math.floor(Math.random()* totalRespostas)
//jogar na tela por meio do h3
elementoResposta.innerHTML= pergunta + respostas[numAleatorio]
//corrigir bug da resposta != para mesma pergunta
elementoResposta.style.opacity= 1;
//sumir a resposta depois de um tempo
setTimeout(function(){
elementoResposta.style.opacity = 0;
botaoPerguntar.removeAttribute("disabled")
}, 3000 )
}