samedi 8 octobre 2016

JavaScript: Please Help Me Make Sense of This Code For My Project

I am working on a school research project and have created a site that takes you through a mock test. The results are supposed to be shown at the very end but I do not want test takers to get their actual results. Below is the code that determines which of 3 main scores they get. (Severity is 1 of 4 choices)

if (tvalue < 0 && severity != "")
{ 
    resulttext = "<div style='text-align:center;padding:20px'>You associate "+openA+input.catB.label+closeA+" with "+open1+input.cat1.label+close1;
    resulttext += " and "+openA+input.catA.label+closeA+" with "+open1+input.cat2.label+close1+severity;
    resulttext += "you associate "+openA+input.catA.label+closeA+" with "+open1+input.cat1.label+close1;
    resulttext += " and "+openA+input.catB.label+closeA+" with "+open1+input.cat2.label+close1+".</div>"; 
    // resulttext += "<div>incompatible: "+incompatible+" ("+(ivar/39)+"); compatible: "+compatible+" ("+(cvar/39)+"); tvalue: "+tvalue+"</div>";
}
else if (tvalue > 0 && severity != "")
{ 
    resulttext = "<div style='text-align:center;padding:20px'>You associate "+openA+input.catA.label+closeA+" with "+open1+input.cat1.label+close1;
    resulttext += " and "+openA+input.catB.label+closeA+" with "+open1+input.cat2.label+close1+severity;
    resulttext += "you associate "+openA+input.catB.label+closeA+" with "+open1+input.cat1.label+close1;
    resulttext += " and "+openA+input.catA.label+closeA+" with "+open1+input.cat2.label+close1+".</div>"; 
    // resulttext += "<div>incompatible: "+incompatible+" ("+(ivar/39)+"); compatible: "+compatible+" ("+(cvar/39)+"); tvalue: "+tvalue+"</div>";
}
else
{ 
    resulttext = "<div style='text-align:center;padding:20px'>You do not associate "+openA+input.catA.label+closeA;
    resulttext += " with "+open1+input.cat1.label+close1+" any more or less than you associate ";
    resulttext += openA+input.catB.label+closeA+" with "+open1+input.cat1.label+close1+".</div>"; 
    // resulttext += "<div>incompatible: "+incompatible+" ("+(ivar/39)+"); compatible: "+compatible+" ("+(cvar/39)+"); tvalue: "+tvalue+"</div>";
}
$("#picture_frame").html(resulttext);
}

Instead of saying "You associate 'catB' with 'cat1' and 'catA' with 'cat2' (severity such as "more than") you associate 'catA' with 'cat1' and 'catB' with 'cat2'." I want it just to say "Your code is 'B1A2+severity' (concatenated)" so that they can give me their result with out knowing their score.

How would I do this without messing up the code? So far I have tried:

resulttext = <div style='text-align:center;padding:20px'>"Your code is B1A2 "+severity.</div>

But this does not work and ruins the whole project (even parts before it).

Aucun commentaire:

Enregistrer un commentaire