How to randomly select 3 items without replacement, and embed them in different survey stages?

LOBLOB Community Member Qubie ✭
edited June 2020 in Custom Code

How to randomly select 3 items without replacement, and embed them in different survey stages?

I want to randomly select 3 images out of 100+ images, and embed them in different questions throughout the survey. It is crucial that every single respondent will not see the same image twice (randomizing without replacement), for example, respondent A can see images 1, 2, 3 but not images 1, 1, 2. What is the best way to do this? the number of questions after each image varies (and is actually conditioned on other questions previously answered using display logic).

Best Answer

  • rondevrondev Community Member - Trial User Wizard ✭✭✭✭✭
    Accepted Answer

    The JS written here, stores the image url into three different embedded data i.e. firstPicture, secondPicture, thirdPicture. Then you just need to pipe these embedded data into the img tag src as ->

    <img src="${e://Field/firstPicture}" />
    

    Make sure you declare those three embedded data in the survey flow at the very start of flow.

Answers

Sign In to Comment