Thanks to your comments, I rearranged the variables as follows. First, I created variables for each image to access their addresses from Gorilla, e.g.
var banana_img = gorilla.stimuliURL('banana.png');
Then, I created variables for each fruit in each position:
var banana = ["<img class='item1' src='" + banana_img + "'>", "<img class='item2' src='" + banana_img+ "'>", "<img class='item3' src='" + banana_img+ "'>", "<img class='item4' src='" + banana_img + "'>", "<img class='item5' src='" + banana_img + "'>", "<img class='item6' src='" + banana_img + "'>"];
Then, I saved each fruit combination as a variable, e.g.
var fruit = [banana[0], apple[1], grapes[2], banana[3], grapes[4], pear[5]]
FInally, I sorted it and selected the first 3 to get only three random items:
half_fruit = fruit.sort( function() { return 0.5 - Math.random() } ).slice(0, 3).join(" ");
Answer or comment below if you find a better way to do this!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…