This time I'm not here to ask for help with my code, but to ask you to judge my code. Where can I improve?  What should I do better?  Where did I do things wrong? This is a quiz that I had to do as an assignment today.  I'm not a professional.  I'm still studying, and at the moment, I'm doing an internship.<? session_start(); ?><html><head>    <script src=http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js></script>    <!--<script type=text/javascript src=quiz.js /> --></head><body>    <div class=domande>    <p>Sei ...?</p>        <div class=option value=yes name=domanda0><button>YES</button></div>        <div class=option value=no name=domanda0><button>NO</button></div>    </div>    <div class=domande>    <p>Sai ...?</p>        <div class=option value=yes name=domanda1><button>YES</button></div>        <div class=option value=no name=domanda1><button>NO</button></div>    </div>    <div class=domande>    <p>Ricerchi...?</p>        <div class=option value=yes name=domanda1_1><button>YES</button></div>        <div class=option value=no name=domanda1_1><button>NO</button></div>    </div>    <div class=domande>       <p>Finita la spesa, tieni sempre gli scontrini?</p>        <div class=option value=yes name=domanda1_2><button>YES</button></div>        <div class=option value=no name=domanda1_2><button>NO</button></div>    </div>    <!-- domanda 2 -->    <div class=domande>    <p>Hai gi pensato ..?</p>        <div class=option value=yes name=domanda2><button>YES</button></div>        <div class=option value=no name=domanda2><button>NO</button></div>    </div>    <div class=domande>    <p>Cerchi di...?</p>        <div class=option value=yes name=domanda2_1><button>YES</button></div>        <div class=option value=no name=domanda2_1><button>NO</button></div>    </div>    <div class=domande>    <p>La tua ...?</p>        <div class=option value=yes name=domanda2_2><button>YES</button></div>        <div class=option value=no name=domanda2_2><button>NO</button></div>    </div><script>        var risposte = new Object();        var $domande = $('.domande');        $domande.hide();        var totDomande = $('.domande').size();        var domandaOn = 0;        var risultato = ;        var countRisposte = 0;        $($domande.get(domandaOn)).fadeIn();        console.log(domandaOn);        $('.option').click(function(){            countRisposte = countRisposte+1;            console.log(countRisposte);            var risposta = ($(this).attr('value'));            var domanda = ($(this).attr('name'));            if(risposta == yes){                risultato += 1;            }            if(risposta == no){                risultato += 0;            }            $($domande.get(domandaOn)).fadeOut(function(){                if(domandaOn == 0){                    if(risposta == yes){                        domandaOn = 4;                    }else if(risposta == no){                        domandaOn = 1;                    }                }                if((domandaOn == 4 || domandaOn == 1) && countRisposte >1){                    if(risposta == yes){                        domandaOn = domandaOn+2;                    }else{                        domandaOn = domandaOn+1;                    }                }                if((domandaOn == 2 || domandaOn == 5) && countRisposte <3){                    domandaOn = domandaOn+1;                }                if((domandaOn == 3 || domandaOn == 6) && countRisposte > 2){                    console.log(domandaOn);                    var resFinale = ;                    console.log(risultato into 6:  +risultato);                    switch (risultato)                    {                    case 000:                        resFinale = result1;                      break;                    case 001:                        resFinale = result2;                      break;                    case 010:                        resFinale = result3;                      break;                    case 011:                        resFinale = result4;                      break;                    case 100:                        resFinale = result5;                      break;                    case 101:                        resFinale = result6;                      break;                    case 110:                        resFinale = result7;                      break;                    case 111:                        resFinale = result8;                      break;                    }                    console.log(resFinale);                    alert(risultato : +resFinale);                }else{                    $($domande.get(domandaOn)).fadeIn();                                    }            });        });</script></body></html> 
What do you think about my questionnaire?
javascript;jquery;html
For your convenience, here's a jsFiddle of your original code.User ExperienceThe user cannot easily amend an accidentally incorrect response, because the question fades away as soon as one clicks YES or NO.  Usually, such user-unfriendliness is not desirable.LanguageI'm personally fine with you coding in Italian.  However, I find this flavour of inglesiano disturbing.  For example, countRisposte, domandaOn, resFinale are all weird mixtures of languages.  Another programmer maintaining code like that would be likely to make a spelling mistake because of such odd words.PHPYou called session_start(), so it looks like you are using PHP.  In that case, why not also use PHP to render your questions with less redundancy?<?php    $domande = array(        'domanda0'   => Sei ...?,        'domanda1'   => Sai ...?,        'domanda1_1' => Ricerchi...?,        'domanda1_2' => Finita la spesa, tieni sempre gli scontrini?,        'domanda2'   => Hai gi pensato ..?,        'domanda2_1' => Cerchi di...?,        'domanda2_2' => La tua ...?,    );    foreach ($domande as $nome => $domanda) {?>    <div class=domande id=<?php echo $nome ?>>      <p><?php echo htmlspecialchars($domanda); ?></p>      <div class=option name=<?php echo $nome; ?> value=yes><button>YES</button></div>      <div class=option name=<?php echo $nome; ?> value=no><button>NO</button></div>    </div><?php    }?>Also, always use PHP long tags (<?php ... ?>); short tags (<? ... ?>) are officially discouraged in the PHP manual.Note that I added the id attribute to the outer <div>.  I'll use that later in the solution below.JavaScript inclusionIf you omit the http: from the URL, like this:<script src=//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js></script>then your page will work equally well whether it is served using HTTP or HTTPS.Calculation of risultato and resFinaleThe way you assemble risultatoif (risposta == yes) { risultato += 1; }if (risposta == no)  { risultato += 0; } seems rather fragile to me, because you would only arrive at the correct result if those statements are executed in the expected sequence.You use a long switch block to convert risultato to resFinale.  It might be clearer and shorter as:// Map risultato to resFinale.// risultato = 000 -> resFinale = result1// risultato = 001 -> resFinale = result2//  (etc.)// risultato = 111 -> resFinale = result8if (/^[01][01][01]$/.test(risultato)) {    resFinale = 'result' + (1 + parseInt(risultato, 2));} but see the solution below for an even better approach.Question DependenciesThe code related to domandaOn is very hard to follow.  The magic values you use for domandaOn don't correspond to the names of the questions, but to their index in the DOM.  The whole mechanism is fragile.  (Have fun modifying the code if you ever need to insert or remove questions!)What is particularly bad is that your if-blocks are not mutually exclusive.  For example, if domandaOn == 4 and risposta == 'no' (i.e., you answer NO to Hai gi pensato ..?, also known as domanda2), you first assign domandaOn = domandaOn+1, which cascades to another assignment domandaOn = domandaOn+1 because domandaOn == 5 and countRisposte == 2.  I'm pretty sure it's a bug, because your Ricerchi...? and Cerchi di...? questions are unreachable.  In any case, it's nasty code that should be rethought rather than fixed.Usage of variablesYou never use risposte and totDomande.The outer parentheses are superfluous:var risposta = ($(this).attr('value'));var domanda = ($(this).attr('name'));Interestingly, while you use risposta, you never use domanda.  The code could be a lot more robust and understandable if you used domanda.SolutionPutting all these ideas together and more, I would write the JavaScript code this way:// Answers to each question add these values to resFinalevar valore = {    'domanda0'   : { no: 0,   yes: 4 },    'domanda1'   : { no: 0,   yes: 2 },    'domanda1_1' : { no: 0,   yes: 1 },    'domanda1_2' : { no: 0,   yes: 1 },    'domanda2'   : { no: 0,   yes: 2 },    'domanda2_1' : { no: 0,   yes: 1 },    'domanda2_2' : { no: 0,   yes: 1 },};// The next question to present after each responsevar FINE = null;var domandeSeguenti = {    'domanda0'   : { no: 'domanda1',   yes: 'domanda2' },    'domanda1'   : { no: 'domanda1_1', yes: 'domanda1_2' },    'domanda1_1' : { no: FINE,         yes: FINE },    'domanda1_2' : { no: FINE,         yes: FINE },    'domanda2'   : { no: 'domanda2_1', yes: 'domanda2_2' },    'domanda2_1' : { no: FINE,         yes: FINE },    'domanda2_2' : { no: FINE,         yes: FINE },};// Show just the first question$('.domande').hide();$('#domanda0').fadeIn();var risultato = 1;$('.option').click(function(){    var risposta = $(this).attr('value');    var domanda = $(this).attr('name');    risultato += valore[domanda][risposta];    $('#' + domanda).fadeOut(function(){        var domandaSeguente = domandeSeguenti[domanda][risposta];        if (domandaSeguente == FINE) {            var resFinale = 'result' + risultato;            alert(risultato :  + resFinale);        } else {            $('#' + domandaSeguente).fadeIn();        }    });});I've fixed your unreachable-questions bug in the way I think you intended, so it does not behave like the original.  Here's a jsFiddle of my solution.I would go one step further and rename domanda0, domanda1, etc. to something more descriptive, but I have refrained from doing so in this solution because it would be hard to compare it against the original code.SummaryThe code is complex, and needs to be simplified.  Instead of hard-coding all the logic, you want to generalize, such that the application is data-driven.  That way, the questionnaire is largely defined by the data structures, and the code is elegant.