//Seccion que se encargara de los quices //Variables que guardaran los diferentes valores de los componentes del quiz const start = document.getElementById("start"); const pregunta = document.getElementById("pregunta"); const uno = document.getElementById("1"); const dos = document.getElementById("2"); const tres = document.getElementById("3"); // Arreglo que guardara el contenido de las preguntas del quiz, // y las diferentes contestaciones que pueden ser elegidas let preguntas = [ { pregunta : "1. I please my parter:", uno : "a. Because is the natural thing to do", dos : "b. Because is my obligation", tres : "c. Only when it is earned and I've been pleased before hand", saludable : "tres", masOmenos: "uno", violencia: "dos" } , { pregunta : "2. When I wish to be with my friends:", uno : "a. I am given the space to do so", dos : "b. My personal space is respected and granted, but is a bit frowned opon", tres : "c. I can't go out on my own", saludable : "uno", masOmenos: "dos", violencia: "tres" } , { pregunta : "3. When we have an argument:", uno : "a. Im being listened to, but in the end they do what ever they want", dos : "b. We talk it out, and reach a mutual understanding", tres : "c. They always got to win the argument", saludable : "dos", masOmenos: "uno", violencia: "tres" } , { pregunta : "4. When I speak with my friends:", uno : "a. I am accused of flirting with them", dos : "b. They trust me and doesn't feel threatened by them", tres : "c. Gets jealous, but doesn't show it", saludable : "dos", masOmenos: "tres", violencia: "uno" } , { pregunta : "5. When we have our differences:", uno : "a. They break my stuff", dos : "b. Even though an agreement was reached, they find a way to punish me", tres : "c. We talk it out, and make agreements that benefit us both", saludable : "tres", masOmenos: "dos", violencia: "uno" } , { pregunta : "6. In regards to sexual advances:", uno : "a. Respects when I say no", dos : "b. Tries to convince me to have sex, and sometimes gets it", tres : "c. I'm afraid to say no", saludable : "uno", masOmenos: "dos", violencia: "tres" } , { pregunta : "7. In regards to my celphone:", uno : "a. Can talk to whomever I want, whenever I want, without a need to explain myself", dos : "b. I'm forbidden to talk with certain people, checks my phone without permission, and controls my calls", tres : "c. Always askswith who I'm talking to, and gets mad if it's someone I could potentially be attracted to", saludable : "uno", masOmenos: "tres", violencia: "dos" } , { pregunta : "8. In our relationship:", uno : "a. Listens to my opinions, as long as we are in agreement", dos : "b. I never speak my mind out of fear of rejection", tres : "c. We both speak our minds and respect each other's opinion", saludable : "tres", masOmenos: "dos", violencia: "uno" } , { pregunta : "9. In our relationship:", uno : "a. We can both act independently", dos : "b. We can act on our own, but have to inform where I am and with whom", tres : "c. My partner always calls to find out where I am", saludable : "uno", masOmenos: "dos", violencia: "tres" } , { pregunta : "10. While with friends or family:", uno : "a. Offends me, but always apologizes afterwards", dos : "b. Treats me with much love and respect", tres : "c. Offends and humiliates me, and doesn't apologize", saludable : "dos", masOmenos: "uno", violencia: "tres" } , { pregunta : "11. Communication in our relationship:", uno : "a. Is very open, and we speak without much trouble", dos : "b. Is good, but from time to time I'm afraid of how they will react", tres : "c. I'm afraid of my partner's reactions to certain topics", saludable : "uno", masOmenos: "dos", violencia: "tres" } , { pregunta : "12. Facebook account:", uno : "a. It is shared, can't have my own account", dos : "b. Each has their own, but they know my password and questions my posts and shares", tres : "c. Private account, and I don't have to give any explanation of the things I do", saludable : "tres", masOmenos: "dos", violencia: "uno" } , { pregunta : "13. Spending:", uno : "a. Split between us", dos : "b. One or the other always pays voluntarily", tres : "c. They control my money and theirs", saludable : "dos", masOmenos: "uno", violencia: "tres" } , { pregunta : "14. I feel like my partner:", uno : "a. Gives me space and supports my decisions", dos : "b. Wants to control me", tres : "c. Manipulates and convinces me to do what ever they want, and sometimes succeeds", saludable : "uno", masOmenos: "dos", violencia: "tres" } ]; // Variables que contienen el tamaƱo del arreglo en donde se guardan las // preguntas y las posibles opciones, cual es la pregunta actual, y que // contestaciones fueron elegidas let ultimaPregunta = preguntas.length - 1; let preguntaActual = 0; let total = 0; // Funcion que despliega las preguntas y las posibles contestaciones function renderPreguntas() { let p = preguntas[preguntaActual]; pregunta.innerHTML = p.pregunta; uno.innerHTML = p.uno; dos.innerHTML = p.dos; tres.innerHTML = p.tres; } // Funcion que esta pendiente a si se le dio un click al evento que // iniciara el quiz start.addEventListener("click", empiezaQuiz); // Funcion que hace que se vea el contenido del quiz. Inicialmente // estan escondidas function empiezaQuiz(){ var quiz_var = document.getElementById('quiz'); var quiz_display = quiz_var.style.display; if(quiz_display == "none"){ quiz_var.style.display = "block"; renderPreguntas(); pregunta.style.display = "block"; } else{ quiz_var.style.display = "none"; pregunta.style.display = "none"; preguntaActual = 0; total = 0; } } function verifyResult(){ var porciento = (total/1400)*100; if(porciento >= 84){ alert("Felicidades! Se encuentra en una relacion muy saludable!") } else if (porciento >= 74) { alert("Ojo! Hay aspectos no muy saludables en su relacion.") } else{ alert("Alerta Roja! Es parte de una relacion no saludable!") } } // Funcion que verifica y guarda las conestaciones escogidas. Luego de que una // es seleccionada, se pasa a la proxima pregunta function checkAnswer(answer){ if(answer == preguntas[preguntaActual].saludable){ total += 100; } else if (answer == preguntas[preguntaActual].masOmenos) { total += 67; } else{ total += 33; } if(preguntaActual < ultimaPregunta){ preguntaActual++; renderPreguntas(); } else{ verifyResult(); empiezaQuiz(); } } // Variables de los botones, que contienen evenlisteners pendientes // a cual opcion es seleccionada. Cada opcion elegida invoca a // checkAnswers y clickedOption# para cambiar su color de fondo. // Esto indicara que fue seleccionado let op1 = document.getElementById("1"); op1.addEventListener('click', function(){checkAnswer("uno")}, false); let op2 = document.getElementById("2"); op2.addEventListener('click', function(){checkAnswer("dos")}, false); let op3 = document.getElementById("3"); op3.addEventListener('click', function(){checkAnswer("tres")}, false);