Hi,
nearly everything is fine, except:
1. You want to display "question by question".
This is not advisable.
The script cannot be hidden by "Always hide this question", but by javascript.
Well, you can run the script and at the end trigger the "Next"- button. But it will cause an unpleasant flicker of the page.
Therefore we recommend to display "group by group" and put one question into each group.
This way you have more options:
Fake the display "question by question", in some cases display two or more questions on on page, do some manipulations using javascript.
2. The question with the javascript must not be on the same page. Put it into a different group at the beginning of the survey.
As you see this line
$(document).on('ready pjax:scriptcomplete',function(){
the script starts after the document is loaded (ready).
Meaning: Your question "question" is displayed before the script works.
3. To hide it
There are these to lines in the script// After testing remove the slashes of the next row to hide this question
// $('#question{QID}').hide();So, do it: remove the slashes to hide the question.
Here two sample survey with both options
"question by question"
"group by group"
Joffm
By the way:
Your first requirement was
The goal is to get 5 hidden questions containing a random number between 1 and 5
This you got. Not more.
You did not say what you want to use it for.
If you tell us a bit more there may be a better solution to aim your goal.
Always remember: Help us to help you.