In version 2.73.1, I would like to take this one step further and partially randomize. I tried to combine the shuffle array script with a functioning script that partially randomizes an array question. The shuffle array script works properly and when the other code is added, all the answers still randomize. Any suggestions on how to fix this?
Code:
<script type="text/javascript" charset="utf-8">
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
return array;
}
$(document).on('ready pjax:complete',function() {
// Identify this question
var thisQuestion = $('#question{QID}');
var elements = $('tr.answers-list', thisQuestion).detach().toArray();
shuffleArray(elements);
$('tr.answers-list', thisQuestion).remove();
$.each(elements, function(i, el) {
$('table.subquestion-list tbody:eq(0)', thisQuestion).append(el);
});
// The answer code to place in the last position
var fixedCode = 'A4';
// Move the "fixed" row to the end
$('table.subquestion-list tbody:eq(0), table.subquestions-list tbody:eq(0)', thisQuestion).append($('tr[id$="X'+{QID}+fixedCode +'"]'));
// Fix up the array row background colours
$('table.subquestion-list tbody tr, table.subquestions-list tbody tr', thisQuestion).each(function(i){
$(this).removeClass('array1 array2').addClass('array'+(2-(i%2)));
});
});
</script>
I've also tried to change "table.subquestion-list" to "table.answers-list"
Can someone please tell me which one is more appropriate for array-columns and why?