psychopy.org | Reference | Downloads | Github

Javascript code not working on Pavlovia

Hello,

I’m trying to get this code working on pavlovia, but apparently I need to change it into a JS code first.
In this routine, I’ve randomised the sound between mute 0 and sound 1. I have done this on the builder view using the custom code (inserting python commands to the experiment)
the code I had converted to JS as well so I can upload the experiment on Pavlovia is not working - stuck on initailising

The experiment works perfectly on locally but not online

example, CODE 3 - sound randomisation
soundFlag = randint(1,10)
if soundFlag < 6:
soundFlag = 0
else:
soundFlag = 1

sound_5.setVolume(soundFlag, log=False)

And the JS equivalent

function getRandInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}

soundFlag=getRandInt(1,10);
if(soundFlag<6){
soundFlag=0;
}
else{
soundFlag=1;
}

Wait Time
waitTime=getRandInt(2,8);
waitTime=waitTime/10;

But it is not working
Link is https://run.pavlovia.org/smoha005/sfm_tffm/html/

Hi @smoha005. please surround code with backticks for readability.

I think this is just the typo, probably uncommented code Wait Time.

I would like auditory beeps (sound) to occur randomly in half of the trials in the experiment. I have converted the python commands to JS however, I cannot hear any sounds on any of the trials when uploaded on Pavlovia.

The python commands:

if soundFlag < 6:
    soundFlag = 0


else:
    soundFlag = 1

sound_5.setVolume(soundFlag, log=False)```

```/////////////Function to generate random Numbers////////////
function getRandInt(min, max) {
  min = Math.ceil(min);
  max = Math.floor(max);
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

soundFlag=getRandInt(1,10);
if(soundFlag<6){
soundFlag=0;
}
else{
soundFlag=1;
}```