Ver Mensaje Individual
  #3 (permalink)  
Antiguo 05/03/2018, 12:06
Avatar de aeberdion
aeberdion
 
Fecha de Ingreso: enero-2009
Ubicación: Petal, MS
Mensajes: 136
Antigüedad: 15 años, 10 meses
Puntos: 8
Respuesta: Resultado dependiendo de valor maximo

Encontre esto en github. el html ya esta modificado para lo que necesito pero sigo con dudas en el js
Cita:
<div id="wrapper">
<h1>What is your spiritual gift?</h1>
<p>Take this questionnaire to find out!</p>

<form id="quiz">
<!-- Question 1 -->
<h2>I like organizing Services</h2>
<!-- Choices -->
<label><input type="radio" name="q1" value="c1">
Almost Never
</label><br />
<label><input type="radio" name="q1" value="c2">
Rarely
</label><br />
<label><input type="radio" name="q1" value="c3">
Sometimes
</label><br />
<label><input type="radio" name="q1" value="c4">
Almost Always
</label><br />
<label><input type="radio" name="q1" value="c5">
Always
</label><br />

<!-- Question 2 -->
<h2>I enjoy starting new churches</h2>
<!-- Choices -->
<label><input type="radio" name="q2" value="c1">
Almost Never
</label><br />
<label><input type="radio" name="q2" value="c2">
Rarely
</label><br />
<label><input type="radio" name="q2" value="c3">
Sometimes
</label><br />
<label><input type="radio" name="q2" value="c4">
Almost Always
</label><br />
<label><input type="radio" name="q2" value="c5">
Always
</label><br />

<!-- Question 3 -->
<h2>Working with my hands is fun for me</h2>
<!-- Choices -->
<label><input type="radio" name="q3" value="c1">
Almost Never
</label><br />
<label><input type="radio" name="q3" value="c2">
Rarely
</label><br />
<label><input type="radio" name="q3" value="c3">
Sometimes
</label><br />
<label><input type="radio" name="q3" value="c4">
Almost Always
</label><br />
<label><input type="radio" name="q3" value="c5">
Always
</label><br />

<!-- Question 4 -->
<h2>I can tell when someone is insincere</h2>
<!-- Choices -->
<label><input type="radio" name="q4" value="c1">
Almost Never
</label><br />
<label><input type="radio" name="q4" value="c2">
Rarely
</label><br />
<label><input type="radio" name="q4" value="c3">
Sometimes
</label><br />
<label><input type="radio" name="q4" value="c4">
Almost Always
</label><br />
<label><input type="radio" name="q4" value="c5">
Always
</label><br />

<!-- Question 5 -->
<h2>I pray for the lost dayly</h2>
<!-- Choices -->
<label><input type="radio" name="q5" value="c1">
Almost Never
</label><br />
<label><input type="radio" name="q5" value="c2">
Rarely
</label><br />
<label><input type="radio" name="q5" value="c3">
Sometimes
</label><br />
<label><input type="radio" name="q5" value="c4">
Almost Always
</label><br />
<label><input type="radio" name="q5" value="c5">
Always
</label><br />

<!-- Question 6 -->
<h2>Encouraging others is a high priority in my life</h2>
<!-- Choices -->
<label><input type="radio" name="q6" value="c1">
Almost Never
</label><br />
<label><input type="radio" name="q6" value="c2">
Rarely
</label><br />
<label><input type="radio" name="q6" value="c3">
Sometimes
</label><br />
<label><input type="radio" name="q6" value="c4">
Almost Always
</label><br />
<label><input type="radio" name="q6" value="c5">
Always
</label><br />

<button type="submit" id="submit" onclick="tabulateAnswers()">Submit Your Answers</button>
<button type="reset" id="reset" onclick="resetAnswer()">Reset</button>
</form>


<div id="answer"></div>
</div>
</body>
</html>
Lo que quiero que evalue es el valor total de la suma de ciertas preguntas y me de el resultado correspondiente ( digamos que q1 + q3 = primer resultado y q2 + q4 = segundo resultado)
Cita:
// function to calculate the result of the survey
function tabulateAnswers() {
// initialize variables for each choice's score
var c1score = 0;
var c2score = 0;
var c3score = 0;
var c4score = 0;
var c5score = 0

// get a list of the radio inputs on the page
var choices = document.getElementsByTagName('input');
// loop through all the radio inputs
for (i=0; i<choices.length; i++) {
// if the radio is checked..
if (choices[i].checked) {
// add 1 to that choice's score
if (choices[i].value == 'c1') {
c1score = c1score + 1;
}
if (choices[i].value == 'c2') {
c2score = c2score + 2;
}
if (choices[i].value == 'c3') {
c3score = c3score + 3;
}
if (choices[i].value == 'c4') {
c4score = c4score + 4;
}
if (choices[i].value == 'c5') {
c4score = c5score + 5;
}
// If you add more choices and outcomes, you must add another if statement below.
}
}

// Find out which choice got the highest score.
// If you add more choices and outcomes, you must add the variable here.
var maxscore = Math.max(c1score,c2score,c3score,c4score,c5score);

// Display answer corresponding to that choice
var answerbox = document.getElementById('answer');
if (c1score == maxscore) {
alert ("You are a computer researcher! You will enjoy developing algorithms, and doing things with computers no one else has done before. For example, researchers sent a robot to the moon, built a computer to beat the best humans in Jeopardy, and are creating robots to do your chores for you. Computer researchers typically go to college and work at universities, or as a part of the research and development team in companies.");
}
if (c2score == maxscore) {
alert ("You are an altruistic coder! You love to help people and feel the positive impact of your work every day. Altrustic coders are out there every day making the world a better place. Computer scientists write software to more effectively help doctors diagnose illnesses such as cancer, connect people in third world countries to education and medical resources on the internet, code websites and software for nonprofit organizations, and much more!");
}
if (c3score == maxscore) {
alert ("You are a developer! Developers create games, apps, social media, movies, and all sorts of fun programs that people enjoy. These coders work on projects such as Minecraft, Poptropica, and Youtube. Developers need sharp coding skills, are great debuggers, and need to work well in a team of other developers.");
}

if (c4score == maxscore) {
alert ("You are the future CEO of a new startup! You enjoy taking risks and building the next big thing that no one has even thought of before. For example, billionare Mark Zuckerberg founded Facebook in 2004, a project he started inside his dorm room in college which eventually turned into a social networking revolution that changed the world.");
}

if (c5score == maxscore) {
alert ("You are the future CEO of a new startup! You enjoy taking risks and building the next big thing that no one has even thought of before. For example, billionare Mark Zuckerberg founded Facebook in 2004, a project he started inside his dorm room in college which eventually turned into a social networking revolution that changed the world.");
}
// If you add more choices, you must add another response below.
}
__________________
Recuerda siempre que eres único… Exactamente igual que todos los demás.
Ideas Sordas

Última edición por aeberdion; 05/03/2018 a las 20:06