0

So I have this little questionnaire:

<!DOCTYPE html>
<html xml:lang="es">
    <head>
        <meta charset="UTF-8">
        <title>Ve y Hazte Ver</title>
        <link rel="stylesheet" href="../../css/main.css">
        <link rel="stylesheet" href="../../css/questionaire.css">
        <!--[if lt IE 9]>
            <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
        <script src="../../js/form.js"></script>
    </head>
    <body class="nonIndex">
        <header>
        </header>
        <nav id="navChoose" class="chooseLink">
            <a href="../choose.html">
                <img src="../../images/backArrow.png" alt="Volver" hight="80" width="100"></img>
            </a>
            <a href="../../index.html">
                <img src="../../images/inicio.png" alt="Inicio" height="90" width="150"></img>
            </a>
        </nav>

        <form method='post' id='quiz_form' onsubmit="getScore();" method="post">
            <ol>
                <li>Cuando vamos en bicicleta no debemos usar el casco. ¿Es eso verdad? </li>
                <p>
                    <input type="radio" name="q1"><label for="q1">Sí</label>
                </p>
                <p>
                    <input type="radio" name="q1" id="correct1"><label for="q1">No</label>
                </p>
                <p>
                    <input type="radio" name="q1"><label for="q1">No lo sé</label>
                </p>
                <li>Las luces de nuestra bicicleta serán...</li>
                <p>
                    <input type="radio" name="q2" id="correct2"><label for="q2">De color blanco y rojo</label>
                </p>
                <p>
                    <input type="radio" name="q2"><label for="q2">De color azul y negra</label>
                </p>
                <p>
                    <input type="radio" name="q2"><label for="q2">Nuestra bici no tiene que llevar luces</label>
                </p>
                <li>¿Tenemos que llevar un chaleco reflectante por la ciudad?</li>
                <p>
                    <input type="radio" name="q3" id="correct3"><label for="q3">Sí</label>
                </p>
                <p>
                    <input type="radio" name="q3"><label for="q3">No</label>
                </p>
                <p>
                    <input type="radio" name="q3"><label for="q3">No lo sé</label>
                </p>
                <li>¿Qué hacemos si circulamos por la calzada y vemos un semáforo rojo?</li>
                <p>
                    <input type="radio" name="q4" id="correct4"><label for="q4">Nos paramos</label>
                </p>
                <p>
                    <input type="radio" name="q4"><label for="q4">Seguimos</label>
                </p>
                <p>
                    <input type="radio" name="q4"><label for="q4">No sé lo que tenemos que hacer</label>
                </p>
                <li>Para girar a la derecha, extendemos el brazo...</li>
                <p>
                    <input type="radio" name="q5"><label for="q5">Hacia la izquierda</label>
                </p>
                <p>
                    <input type="radio" name="q5" id="correct5"><label for="q5">Hacia la derecha</label>
                </p>
                <p>
                    <input type="radio" name="q5"><label for="q5">No hace falta que lo indiquemos con el brazo</label>
                </p>
                <li>Si vamos en bici y queremos parar, ¿cómo tenemos que mover el brazo?</li>
                <p>
                    <input type="radio" name="q6"><label for="q6">No tenemos que moverlo</label>
                </p>
                <p>
                    <input type="radio" name="q6" id="correct6"><label for="q6">De arriba a abajo</label>
                </p>
                <p>
                    <input type="radio" name="q6"><label for="q6">Hacia la derecha</label>
                </p>
                <li>Si vamos en bici y vemos un paso peatonal, ¿qué hacemos?</li>
                <p>
                    <input type="radio" name="q7"><label for="q7">Seguir circulando aunque estén cruzando peatones</label>
                </p>
                <p>
                    <input type="radio" name="q7" id="correct7"><label for="q7">Detenernos</label>
                </p>
                <p>
                    <input type="radio" name="q7"><label for="q7">No sé lo que debemos hacer</label>
                </p>
                <li>¿Qué significa esta señal?</li>
                <p>
                    <input type="radio" name="q8"><label for="q8">Que tenemos que continuar circulando</label>
                </p>
                <p>
                    <input type="radio" name="q8" id="correct8"><label for="q8">Que debemos pararnos</label>
                </p>
                <p>
                    <input type="radio" name="q8"><label for="q8">No sé cuál es su significado</label>
                </p>
                <img src="../../images/sign3.png" alt="Señal de STOP" width="150px" height="150px">
                <li>¿Qué indica una señal con forma de triángulo como ésta?</li>
                <p>
                    <input type="radio" name="q9" id="correct9"><label for="q9">Peligro</label>
                </p>
                <p>
                    <input type="radio" name="q9"><label for="q9">Nos informan de cosas interesantes</label>
                </p>
                <p>
                    <input type="radio" name="q9"><label for="q9">No sé cuál es su significado</label>
                </p>
                <img src="../../images/sign4.png" alt="Señal de Peligro, zona escolar" width="150px" height="150px">
                <li>Si vemos una señal redonda como esta, ¿qué quiere decir?</li>
                <p>
                    <input type="radio" name="q10" id="correct10"><label for="q10">Nos prohíbe algo</label>
                </p>
                <p>
                    <input type="radio" name="q10"><label for="q10">Nos informa</label>
                </p>
                <p>
                    <input type="radio" name="q10"><label for="q10">No sé lo que quiere decir</label>
                </p>
                <img src="../../images/sign2_2.png" alt="" width="150px" height="150px">
            </ol>
            <input type="reset" value="Reinicia el test">
            <input type="submit" name="submit" value="Comprueba las Respuestas">
        </form>

        <footer>
            <p>Creado por X e Y a 2013</p>
        </footer>
    </body>
</html>

And I want to validate it locally through a JavaScript file, which is actually working, but not as expected. I know all of it is working, since it will show the alert depending on the score: window.alert('Has sacado un ' + score + ' de 10. ¡Casi perfecto, muy bien!');

But, when I try to give different alerts for different scores, it will just not do anything but reset the form:

if(score<5)
{
    window.alert('Has fallado el test con ' + score + ' de 10 acertadas. ¡Inténtalo de nuevo!');
}
else if(score==5 || score==6) {
{
    window.alert('Has sacado una puntuación de ' + score + ' de 10. ¡Sigue practicando para mejorar!');
}
else if(score==7 || score==8) {
    window.alert('Has sacado una puntuación de ' + score + ' de 10. ¡Casi un sobresaliente!');
}
else if(score==9) {
    window.alert('Has sacado un ' + score + ' de 10. ¡Casi perfecto, muy bien!');
}
else
{
    window.alert('¡Has sacado un ' + score + ' de 10! No se puede hacer mejor \\(^o^\\(   )/^o^)/');
}

Where did I go wrong? Thanks beforehand.

John Dvorak
  • 26,799
  • 13
  • 69
  • 83
vitimiti
  • 77
  • 1
  • 8
  • How are you running that code block? On `submit`? – Evan Davis Oct 08 '13 at 18:22
  • Can we see your entire `getScore()` function? Are you preventing the form submission? – showdev Oct 08 '13 at 18:22
  • Make sure you execute your code at an appropriate time, specifically, after any `input` or `form` elements your JS deals with have been loaded. i usually use `document.addEventListener('DOMContentLoaded',function(){})` but there are other ways, see http://stackoverflow.com/questions/1307929/javascript-dom-load-events-execution-sequence-and-document-ready – Plato Oct 08 '13 at 18:25
  • It could be `last alert()`, can you comment it and check? – Kaf Oct 08 '13 at 18:28
  • 1
    This question appears to be offtopic because its cause is a typo – John Dvorak Oct 09 '13 at 07:15

1 Answers1

2

You have an error

else if(score==5 || score==6) {
{

Bracket on the new line brakes the script execution

artygus
  • 605
  • 4
  • 11