-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
111 lines (84 loc) · 2.93 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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//FUNCION DESPUES DE ENVIAR EL NOMBRE
function clickNameButton() {
if (userName.value) {
document.getElementById("welcomeMessage").innerHTML = "¡Bienvenid@, " + document.getElementById("userName").value + "! 🖐😊"; // getElementById = referencia a un objeto Element
location.href ='quizz.html'; // redireccionar con Javascript
} else {
alert("No haz ingresado tu nombre 🤷♀️");
}
}
function clickSendAnswers() {
// PREGUNTA 01
//Variable que almacena valor de la respuesta pregunta 1
let questionOne = "";
if (document.getElementById("optionOne").checked){
questionOne = document.getElementById("optionOne").value;
}
if (document.getElementById("optionTwo").checked){
questionOne = document.getElementById("optionTwo").value;
}
if (document.getElementById("optionThree").checked){
questionOne = document.getElementById("optionThree").value;
}
// Conversión de la variable a Number
if (questionOne === "1") {
questionOne = 1;
}
else {
questionOne = 0;
}
// PREGUNTA 02
//Variable que almacena valor de la respuesta pregunta 2
let questionTwo = "";
if (document.getElementById("optionFour").checked){
questionTwo = document.getElementById("optionFour").value;
}
if (document.getElementById("optionFive").checked){
questionTwo = document.getElementById("optionFive").value;
}
if (document.getElementById("optionSix").checked){
questionTwo = document.getElementById("optionSix").value;
}
// Conversión de la variable a Number
if (questionTwo === "1") {
questionTwo = 1;
}
else {
questionTwo = 0;
}
// PREGUNTA 03
//Variable que almacena valor de la respuesta pregunta 3
let questionThree = "";
if (document.getElementById("optionSeven").checked){
questionThree = document.getElementById("optionSeven").value;
}
if (document.getElementById("optionEight").checked){
questionThree = document.getElementById("optionEight").value;
}
if (document.getElementById("optionNine").checked){
questionThree = document.getElementById("optionNine").value;
}
// Conversión de la variable a Number
if (questionThree === "1") {
questionThree = 1;
}
else {
questionThree = 0;
}
//VARIABLE CON LA SUMATORIA DE LOS PUNTOS
let correctAnswers = questionOne + questionTwo + questionThree;
//MENSAJE DEL PUNTAJE OBTENIDO
document.getElementById("points").innerHTML= "En la trivia obtuviste " + correctAnswers + " puntos." ;
//MENSAJE SI HUBO UN ERROR
if(correctAnswers < 3) {
document.getElementById("answer").innerHTML = "SIGUE INTENTÁNDOLO, NO TE RINDAS!! 🙁😉";
}
//FELICITACIONES SI ACERTO EN TODO
if(correctAnswers == 3) {
document.getElementById("answer").innerHTML = "FELICIDADES, ACERTASTE EN TODAS!!🥳👏";
}
}
//REDIRECCIONAR PARA VOLVER A INTENTAR LA TRIVIA
function clicktryAgain() {
location.href= "index.html"
}