0

I am a complete beginner in javascript so really need help! I have made a set of questions called advisorRating (parts shown below) and I want the preamble to say 'rate advisor A' and 'rate advisor B' on separate pages in random order.

i.e. on one page rate advisor A -> submit -> next page asks to rate advisor B and vice versa.

I also want the presentation order to be equally distributed (i.e. 50% time A and then B, vice versa)

To do this, I've tried the code below but its not working. For awhile it only showed advisor B twice and now its only showing advisor A twice.

  type: jsPsychSurveyLikert,
  questions: [
    {prompt: "How knowledgeable is this advisor?", 
    name: 'Knowledgeable', 
    labels: advisorLikertScale,
},
if (Math.random() < 0.5)
{
    advisorRating.preamble = "Please rate Advisor A on the following questions";
    timeline.push(advisorRating);
    advisorRating.preamble = "Please rate Advisor B on the following questions";
    timeline.push(advisorRating);
}
else
{
    advisorRating.preamble = "Please rate Advisor B on the following questions";
    timeline.push(advisorRating);
    advisorRating.preamble = "Please rate Advisor A on the following questions";
    timeline.push(advisorRating);
}

I've tried different things:

defining advisor preamble differently: advisorRating["preamble"]

defining advisorA and advisorB first and then pushing:

var advisorB = advisorRating
advisorA.preamble = "Please rate Advisor A on the following questions";
advisorB.preamble = "Please rate Advisor B on the following questions";
if (Math.random() < 0.5)
{
    timeline.push(advisorRatingA, advisorRatingB);
}
else
{
    timeline.push(advisorRatingB, advisorRatingA);
}

I would like to know why this isn't working. However, more importantly, I would like to know how I can achieve my initial goal: randomly presenting the instructions on different pages.

Thank you for your help :)x

0 Answers0