I need to shuffle the order of a block of multiple choice buttons. I trying this:

Block to setVariable Block with shuffle script Block to show the options. function shuffle(array) { array.sort(() => Math.random() - 0.5); } let x = {{options}}; shuffle({x); setVariable({{options}}, x); does not work
No description
2 Replies
naman
naman10mo ago
try using this script :
function shuffle(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}

let x = {{options}};
shuffle(x);
setVariable('options', x);
function shuffle(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}

let x = {{options}};
shuffle(x);
setVariable('options', x);
uncheck "Execute on client?" because the setVariable function is only available in script executed on the server
No description
crossbrasil
crossbrasilOP10mo ago
thanks. It works perfectly

Did you find this page helpful?