3

I'm working on experiment about distractions. As part of the experiment, I need a question to appear on the screen for two seconds, disappear for two seconds, then reappear. Here's my shot at programming this in javascript.

Qualtrics.SurveyEngine.addOnload(function()
{

    function togglequestion() { 
        if(this.getQuestionDisplayed()) {
             this.questionContainer.style.display = 'none';
        } else {
             this.questionContainer.style.display = 'block';
        }
     };

    var a1 = setTimeout(togglequestion, 2000);
    var a2 = setTimeout(togglequestion, 4000);

});

I think the problem is either in the way I'm declaring my function, or the if statement. I'm not very experienced with javascript so any bit of help would be very appreciated!

655321
  • 411
  • 4
  • 26
user2900369
  • 789
  • 1
  • 7
  • 9

1 Answers1

2

The second argument of the setTimeout function is a duration in milliseconds. Currently, the functions is called two times very quickly.

var a1 = setTimeout(togglequestion, 2000);
var a2 = setTimeout(togglequestion, 4000);
Maxime Lorant
  • 34,607
  • 19
  • 87
  • 97