Hi everyone,
I have three equation type questions (aScore, bScore, cScore) and I'm trying to use javascript in a Text Display question to sort the results of the three equations in a descending order (since I couldn't find any sorting function available in EM ). I did this :
Code:
<script type="text/javascript" charset="utf-8">
var points=["{aScore}","{bScore}","{cScore}"];
points.sort(function(a,b){
return b - a
})
document.write(points);
</script>
The above code works well and sorts correctly if I put an array of numbers but what I get when I use the questions codes like shown above is a reverse order of how I put the variables in the array above irrespective of their values.
e.g. assume {aScore} was 3, {bScore} 17, and {cScore} was 5 then the above script would give me : 5, 17, 3 as if the code does not recognise the variables as numbers !
Any views on what I'm missing here please ??
edit: I guess the the problem is that EM {..} are being interpreted after the javascript function ended and I hope this can be solved some way or there is a simpler solution to what I need to achieve.
Thanks so much