-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
85 lines (78 loc) · 2.63 KB
/
script.js
File metadata and controls
85 lines (78 loc) · 2.63 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const caixaPrincipal = document.querySelector(".caixa-principal");
const caixaPerguntas = document.querySelector(".caixa-perguntas");
const caixaAlternativas = document.querySelector(".caixa-alternativas");
const caixaResultado = document.querySelector(".caixa-resultado");
const textoResultado = document.querySelector(".texto-resultado");
const perguntas = [
{
enunciado: "Você gosta do meio ambiente",
alternativas: [
{
texto: "Sim!",
afirmacao: "Parabéns,você se importa com o meio ambiente. "
},
{
texto: "Não!",
afirmacao: "talvez se importe, mas não da muita atenção."
}
]
},
{
enunciado: "Você apoia a preservação do meio ambiente?",
alternativas: [
{
texto: "Sim.",
afirmacao: "eu apoio pois tem preservação dos ecossistemas bem importantes."
},
{
texto: "Não.",
afirmacao: "Não tenho muita noção disso mas um pouco me importo."
}
]
},
{
enunciado: "Você teria energia eólica em sua casa?",
alternativas: [
{
texto: "Sim.",
afirmacao: "eu teria, é uma boa fonte de enrgia sutentavel."
},
{
texto: "Não.",
afirmacao: "Talvez porque tenha um valor muito alto."
}
]
};
let atual = 0;
let perguntaAtual;
let historiaFinal = "";
function mostraPergunta() {
if (atual >= perguntas.length) {
mostraResultado();
return;
}
perguntaAtual = perguntas[atual];
caixaPerguntas.textContent = perguntaAtual.enunciado;
caixaAlternativas.textContent = "";
mostraAlternativas();
}
function mostraAlternativas(){
for(const alternativa of perguntaAtual.alternativas) {
const botaoAlternativas = document.createElement("button");
botaoAlternativas.textContent = alternativa.texto;
botaoAlternativas.addEventListener("click", () => respostaSelecionada(alternativa));
caixaAlternativas.appendChild(botaoAlternativas);
}
}
function respostaSelecionada(opcaoSelecionada) {
const afirmacoes = opcaoSelecionada.afirmacao;
historiaFinal += afirmacoes + " ";
atual++;
mostraPergunta();
}
function mostraResultado() {
caixaPerguntas.textContent = "Em 2049...";
textoResultado.textContent = historiaFinal;
caixaAlternativas.textContent = "";
}
mostraPergunta();