Repositorio del curso CCOM4030 el semestre B91 del proyecto Paz para la Mujer

quiz_preg_en.js 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. //Seccion que se encargara de los quices
  2. //Variables que guardaran los diferentes valores de los componentes del quiz
  3. const start = document.getElementById("start");
  4. const pregunta = document.getElementById("pregunta");
  5. const uno = document.getElementById("1");
  6. const dos = document.getElementById("2");
  7. const tres = document.getElementById("3");
  8. // Arreglo que guardara el contenido de las preguntas del quiz,
  9. // y las diferentes contestaciones que pueden ser elegidas
  10. let preguntas = [
  11. {
  12. pregunta : "1. I please my parter:",
  13. uno : "a. Because is the natural thing to do",
  14. dos : "b. Because is my obligation",
  15. tres : "c. Only when it is earned and I've been pleased before hand",
  16. saludable : "tres",
  17. masOmenos: "uno",
  18. violencia: "dos"
  19. } , {
  20. pregunta : "2. When I wish to be with my friends:",
  21. uno : "a. I am given the space to do so",
  22. dos : "b. My personal space is respected and granted, but is a bit frowned opon",
  23. tres : "c. I can't go out on my own",
  24. saludable : "uno",
  25. masOmenos: "dos",
  26. violencia: "tres"
  27. } , {
  28. pregunta : "3. When we have an argument:",
  29. uno : "a. Im being listened to, but in the end they do what ever they want",
  30. dos : "b. We talk it out, and reach a mutual understanding",
  31. tres : "c. They always got to win the argument",
  32. saludable : "dos",
  33. masOmenos: "uno",
  34. violencia: "tres"
  35. } , {
  36. pregunta : "4. When I speak with my friends:",
  37. uno : "a. I am accused of flirting with them",
  38. dos : "b. They trust me and doesn't feel threatened by them",
  39. tres : "c. Gets jealous, but doesn't show it",
  40. saludable : "dos",
  41. masOmenos: "tres",
  42. violencia: "uno"
  43. } , {
  44. pregunta : "5. When we have our differences:",
  45. uno : "a. They break my stuff",
  46. dos : "b. Even though an agreement was reached, they find a way to punish me",
  47. tres : "c. We talk it out, and make agreements that benefit us both",
  48. saludable : "tres",
  49. masOmenos: "dos",
  50. violencia: "uno"
  51. } , {
  52. pregunta : "6. In regards to sexual advances:",
  53. uno : "a. Respects when I say no",
  54. dos : "b. Tries to convince me to have sex, and sometimes gets it",
  55. tres : "c. I'm afraid to say no",
  56. saludable : "uno",
  57. masOmenos: "dos",
  58. violencia: "tres"
  59. } , {
  60. pregunta : "7. In regards to my celphone:",
  61. uno : "a. Can talk to whomever I want, whenever I want, without a need to explain myself",
  62. dos : "b. I'm forbidden to talk with certain people, checks my phone without permission, and controls my calls",
  63. tres : "c. Always askswith who I'm talking to, and gets mad if it's someone I could potentially be attracted to",
  64. saludable : "uno",
  65. masOmenos: "tres",
  66. violencia: "dos"
  67. } , {
  68. pregunta : "8. In our relationship:",
  69. uno : "a. Listens to my opinions, as long as we are in agreement",
  70. dos : "b. I never speak my mind out of fear of rejection",
  71. tres : "c. We both speak our minds and respect each other's opinion",
  72. saludable : "tres",
  73. masOmenos: "dos",
  74. violencia: "uno"
  75. } , {
  76. pregunta : "9. In our relationship:",
  77. uno : "a. We can both act independently",
  78. dos : "b. We can act on our own, but have to inform where I am and with whom",
  79. tres : "c. My partner always calls to find out where I am",
  80. saludable : "uno",
  81. masOmenos: "dos",
  82. violencia: "tres"
  83. } , {
  84. pregunta : "10. While with friends or family:",
  85. uno : "a. Offends me, but always apologizes afterwards",
  86. dos : "b. Treats me with much love and respect",
  87. tres : "c. Offends and humiliates me, and doesn't apologize",
  88. saludable : "dos",
  89. masOmenos: "uno",
  90. violencia: "tres"
  91. } , {
  92. pregunta : "11. Communication in our relationship:",
  93. uno : "a. Is very open, and we speak without much trouble",
  94. dos : "b. Is good, but from time to time I'm afraid of how they will react",
  95. tres : "c. I'm afraid of my partner's reactions to certain topics",
  96. saludable : "uno",
  97. masOmenos: "dos",
  98. violencia: "tres"
  99. } , {
  100. pregunta : "12. Facebook account:",
  101. uno : "a. It is shared, can't have my own account",
  102. dos : "b. Each has their own, but they know my password and questions my posts and shares",
  103. tres : "c. Private account, and I don't have to give any explanation of the things I do",
  104. saludable : "tres",
  105. masOmenos: "dos",
  106. violencia: "uno"
  107. } , {
  108. pregunta : "13. Spending:",
  109. uno : "a. Split between us",
  110. dos : "b. One or the other always pays voluntarily",
  111. tres : "c. They control my money and theirs",
  112. saludable : "dos",
  113. masOmenos: "uno",
  114. violencia: "tres"
  115. } , {
  116. pregunta : "14. I feel like my partner:",
  117. uno : "a. Gives me space and supports my decisions",
  118. dos : "b. Wants to control me",
  119. tres : "c. Manipulates and convinces me to do what ever they want, and sometimes succeeds",
  120. saludable : "uno",
  121. masOmenos: "dos",
  122. violencia: "tres"
  123. }
  124. ];
  125. // Variables que contienen el tamaño del arreglo en donde se guardan las
  126. // preguntas y las posibles opciones, cual es la pregunta actual, y que
  127. // contestaciones fueron elegidas
  128. let ultimaPregunta = preguntas.length - 1;
  129. let preguntaActual = 0;
  130. let total = 0;
  131. // Funcion que despliega las preguntas y las posibles contestaciones
  132. function renderPreguntas() {
  133. let p = preguntas[preguntaActual];
  134. pregunta.innerHTML = p.pregunta;
  135. uno.innerHTML = p.uno;
  136. dos.innerHTML = p.dos;
  137. tres.innerHTML = p.tres;
  138. }
  139. // Funcion que esta pendiente a si se le dio un click al evento que
  140. // iniciara el quiz
  141. start.addEventListener("click", empiezaQuiz);
  142. // Funcion que hace que se vea el contenido del quiz. Inicialmente
  143. // estan escondidas
  144. function empiezaQuiz(){
  145. var quiz_var = document.getElementById('quiz');
  146. var quiz_display = quiz_var.style.display;
  147. if(quiz_display == "none"){
  148. quiz_var.style.display = "block";
  149. renderPreguntas();
  150. pregunta.style.display = "block";
  151. }
  152. else{
  153. quiz_var.style.display = "none";
  154. pregunta.style.display = "none";
  155. preguntaActual = 0;
  156. total = 0;
  157. }
  158. }
  159. function verifyResult(){
  160. var porciento = (total/1400)*100;
  161. if(porciento >= 84){
  162. alert("Felicidades! Se encuentra en una relacion muy saludable!")
  163. }
  164. else if (porciento >= 74) {
  165. alert("Ojo! Hay aspectos no muy saludables en su relacion.")
  166. }
  167. else{
  168. alert("Alerta Roja! Es parte de una relacion no saludable!")
  169. }
  170. }
  171. // Funcion que verifica y guarda las conestaciones escogidas. Luego de que una
  172. // es seleccionada, se pasa a la proxima pregunta
  173. function checkAnswer(answer){
  174. if(answer == preguntas[preguntaActual].saludable){
  175. total += 100;
  176. }
  177. else if (answer == preguntas[preguntaActual].masOmenos) {
  178. total += 67;
  179. }
  180. else{
  181. total += 33;
  182. }
  183. if(preguntaActual < ultimaPregunta){
  184. preguntaActual++;
  185. renderPreguntas();
  186. }
  187. else{
  188. verifyResult();
  189. empiezaQuiz();
  190. }
  191. }
  192. // Variables de los botones, que contienen evenlisteners pendientes
  193. // a cual opcion es seleccionada. Cada opcion elegida invoca a
  194. // checkAnswers y clickedOption# para cambiar su color de fondo.
  195. // Esto indicara que fue seleccionado
  196. let op1 = document.getElementById("1");
  197. op1.addEventListener('click', function(){checkAnswer("uno")}, false);
  198. let op2 = document.getElementById("2");
  199. op2.addEventListener('click', function(){checkAnswer("dos")}, false);
  200. let op3 = document.getElementById("3");
  201. op3.addEventListener('click', function(){checkAnswer("tres")}, false);