I'm setting up a simple Qualtrics survey with one question with a Loop & Merge function (in this one block); in Loop & Merge field 1, I've provided the URLs to my media files. The respondents have to select the right answer from two answer options (let's say Yes/No). All all my files are set up as a Loop & Merge within one question so that I won't have to create 100 separate questions for each individual media file.
This works great, however, I would also like to score my respondents' answers. The regular "scoring" feature in Qualtrics doesn't seem to work for me, since I can only provide one scoring option per question (i.e. I could only say that the first answer is always 1 point, and the second answer is always 0 points). However, the correct answer varies between my files (sometimes it's Yes/the first option; sometimes it's No/the second option).
I'm thinking there might be a way to list the correct answer (=i.e. the answer that should receive 1 point) in Field 2 in the Loop & Merge function; and then include some (javascript?) code in the question which would check the survey taker's answer choice against the "correct answer" in Field 2 of the Loop & Merge function for each media file. The code would assign "1" point if the participant's selected answer corresponds to Field 2 for each media file.
How would I write the (javascript) code to calculate a score for each question and an overall score at the end? (I don't need survey takers to see their score, but once a person is done, I would like to quickly see what their final overall score is, say 72 out of 100 possible points.)
Update: In the loop/merge function, I've added the right answer (for each file) in Field2, the incorrect answer in Field3. As suggested below, I've piped loop fields (2 and 3) into my question choices. I've added code in Field4 about whether or not the order of the answer options should be changed (0,1; 0= don't change order, 1= change order) so that the options always occur in the same order (for example, always Choice 1 = "Yes", Choice 2 = "No".) I've (unsuccessfully) tried to use the following JS code to refer to Field 4:
if (${lm://Field/4}==1) {
(choiceNum = ${lm://Field/3}, ${lm://Field/2})
}
If there is a way to work without JavaScript, I'd be glad to hear about that option as well.
Thank you so much!
How about this without JavaScript:
Include your two choices as loop fields: Field 2 is correct answer, Field 3 is incorrect answer
Pipe your loop fields (2 and 3) into your question choices
Randomize the choices
Score the question: Choice 1/Field 2 = 1 point, Choice 2/Field 3 = 0 points.
Related
I am trying to setup a survey in Qualtrics and want to randomize each question in the following way.
Every question asks the participant to make a choice, based on two variable parameters - Type of opponent (T) and Action (A). There are 6 types of opponent (T1,T2...T6) and 3 types of actions (A1,A2,A3). The actions have 6 replicates each (meaning there are 6 actions each of type A1,A2 and A3 A1[1..6],A2[1..6],A3[1..6]). There are 18 actions in total.
The question text will read
"You are playing against T[i] who has taken action Aj[k] "
i=1,2..6
j=1,2,3
k=1,2..6
I want to randomly assign the 6 questions in each action type to the 6 types of opponents - thereby generating 18 questions per subject.
How do i make the question text variable?
I have tried placing the following within the
Qualtrics.SurveyEngine.addOnReady(function(){})
block as a first step to at least randomly generate one of the opponent types, but the text does not change at all.
I am a complete newbie to javascript, although I have other coding experience.
Qualtrics.SurveyEngine.addOnReady(function()
{
var opponent_types =["Red","Blue","Green","Yellow"];
var selected_opponent_type = opponent_types[Math.floor(Math.random()*opponent_types.length)];
this.QuestionText = selected_opponent_type;
})
I am sure this is a syntax issue, can someone please point me in the right direction to go about this? The document.write is disabled in the Qualtrics API.
I am entirely new to both Qualtrics and Javascript (as such, apologies for how elementary this question may be). I have a survey on the former that will require using Javascript in a couple of the different Blocks in the survey to count the number of answers provided by a user in a number of different text entry boxes (all of which are in just one Block).
We want to pay respondents by the number of suggestions they make, so I really just want to count how many of the different text entry boxes in that one question Block have something written in them, to then use as a variable in another Block at the end of the survey to pay respondents based on how many questions they answered.
Conceptually, I assume it'll just mean initializing a counter, looping over the N text entry boxes we have, adding +1 to the counter for every one of those N boxes in which anything has been entered (I'm not worrying about whether what is entered is actually meaningful to us, assuming people don't just enter spaces), and keeping that variable to use in the very last block of the survey (where we tell them what they have earned, which is a fixed amount per suggestion). I just can't seem to find even the building blocks/ elementary syntax to implement that very simple counter through Googling and searching around here (I tried to get a bit of inspiration from these questions but no success so far: (1) Qualtrics Word Counter Javascript; (2) Qualtrics: javascript - text entry).
Any help would be appreciated!
You can do this in your survey flow after the text entry questions block:
Embedded Data: count = 0
Branch: If Text Question 1 Not Empty
Embedded Data: count = $e{ e://Field/count + 1 }
Branch: If Text Question 2 Not Empty
Embedded Data: count = $e{ e://Field/count + 1 }
etc...
At the end count will equal the number of text entry questions answered.
A disclaimer: I'm not familiar with Javascript. I've merely cobbled together a basic understanding of what I need to do for this task from Stack Overflow and other resources. My apologies if something below is unclear.
My problem: I need to generate a random number between 0 and 8,764, using Javascript, that will not repeat itself between Qualtrics survey responses.
Currently, I've found code to create an array that contains all numbers between 0 and 8,764, shuffles the array, and pops the last number off the end of the array.
It then adds embedded data to Qualtrics with that popped number, and I can then pipe the embedded data into a Qualtrics question to display it to my survey respondent. See below:
Qualtrics.SurveyEngine.addOnReady(function()
{
for (var i = 0, ar = []; i < 8; i++) {
ar[i] = i;
}
ar.sort(function () {
return Math.random() - 0.5;
});
var randomnumber = ar.pop();
Qualtrics.SurveyEngine.addEmbeddedData("randomnumber", randomnumber);
});
However, as far as I can tell, this Javascript code "resets" itself between survey responses, meaning it will re-create and re-shuffle the array each time a new respondent enters the survey. I'd like to find a way to make it so that it will be impossible for a new respondent to see the same popped "randomnumber" as a previous respondent. So, if the first survey respondent saw a 1, then the next survey respondent could see any number besides a 1 (let's say they see a 100 instead), and the next respondent could see any number except a 1 or a 100, etc etc.
I think it's possible to use embedded data in Javascript code and manipulate it (see here). It seems like there might be a way to access the randomnumber embedded data and write Javascript code to not remove any numbers from the array that match one of the previously popped randomnumbers. I lack the technical knowledge to execute this, if it's even the best way to accomplish the task.
Any and all help appreciated!
You can do what you want with Advanced Randomization in Qualtrics.
Set up a multiple choice question with your numbers 0 through 8,764 as the choices. Then use Advanced Randomization to select a random subset of 1 from all the numbers and click "Evenly Present" (Evenly Present is what tells Qualtrics to use every number before reusing any). Use JavaScript to hide the multiple choice question:
$(this.questionId).hide();
Now you can pipe your unique random number into a subsequent question. For example:
${q://QID1/ChoiceGroup/DisplayedChoices}
I wonder if I can simplify and use less lines of code for this purpose:
I have a class called "worker", and that class has a method that reads the properties (name, age, etc...) from a series of simple arrays.
Until there, everything is fine. Now, one of the properties that I want to add is a boolean value that makes reference to which months of the year the worker is active. For the moment, I have solved it like this:
var months_worker_1 = [{"jan":true},{"feb":true},{"mar":true},{"apr":false}] //and so on
And then, my property reads months_worker_1, but I have one array like that for each worker. I wonder if there is a way to do this that requires less lines of code, like for example, create a "master" array with all the months of the year, and in the array for each worker, specify just the months they are working. Those months become "true", and the rest of months become "false" automatically without specifying so... I have been scratching my head for some time, and for the moment only my current system is working fine, but I am guessing that there must be a simpler way...
Thanks very much!
Edit: I clarify, there is no "big picture". I am just doing some exercises trying to learn javascript and this one woke my interest, because the solution I thought seems too complicated (repeating same array many times). There is no specific goal I need to achieve, I am just learning ways to do this.
A really nice trick that I use sometimes is to use a binary number to keep track of a fixed amount of flags, and convert it to a decimal for easier storage / URL embedding / etc. Let's assume Mark, a user, is active all months of the year. Considering a binary number, in which 1 means "active" and 0 inactive, Mark's flag would be:
111111111111 (twelve months)
if Mark would only be active during january, february and december, his flag value would be:
11000000001
Checking if Mark is active during a specific months is as simple as checking if the character that corresponds to that month's index in Mark's flag is 1 or 0.
This technique has helped me in the past to send values for a large number of flags via URLs, while also keeping the URL reasonably short. Of course, you probably don't need this, but it's a nice thing to know:
Converting from binary to decimal is easy in JS:
parseInt(11000000001, 2).toString(10); // returns 1537
And the reverse:
parseInt((1537).toString(2)); // returns 11000000001
Edit
You could just as easily use an array made out of the month numbers:
var months_worker_1 = [1, 2, 3]; // this would mean that the user is active during january, february and march
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am developing a pong redux in html5 and javascript. I need help modifying it so that upon holding down D, it will subtract 4 from the ball.speedModifier variable, and then add 4 upon releasing D. The reason I don't just set the modifier back to 0 when the key is released, is because I want to have multiple things changing the modifier at once that stack on top of one another. With my current system for detecting key presses, the addition and subtraction of the variable would repeat at 60 FPS, while I only want it to occur once until the amount is subtracted again.
Here is a pastie of my code:
HTML: http://pastebin.com/txeNftNT
Javascript: http://pastebin.com/scpBqGqx
I think the easiest way to do this would be to track additional properties for each key. Instead of checking just if a key is down or up, you also want to track if they key was down or up on the previous iteration of checkInput(). That way, if the "D" key is down, but it wasn't down the last iteration, you subtract 4 from ball.speedModifier. Alternatively, if the "D" key is up, but wasn't up on the last iteration, you then add 4 back to ball.speedModifier.
The final key to making this work is at the end of every checkInput loop, you save out whether each key was down or not. Then on the next loop of checkInput() you're ready to do your checks again.
The following is just pseudo code, but hopefully gives the idea.
function checkInput(){
if(d.isDown()){
if(!d.wasDown()){
ball.speedModifer -= 4;
}
}else{
if(d.wasDown()){
ball.speedModifier += 4;
}
}
d.wasDown = d.isDown;
}
Just in case, I also put together a working example. Do note the three changes. Your pressedKeys is no longer an array, but an object of KeyCodes which correspond to the VALUES of your existing KEY object. And then this key's value is an object itself with two keys of "wasDown" and "isDown". I then pre-populate this object at the end of init() and then perform your various checks and updates in checkInput using the new object instead of the array.
http://jsfiddle.net/gUgGf/
Hopefully that helps!
I can think of two fairly simple ways to do what you want:
Have a variable that stores the base value, and then each frame perform all your calculations for any applicable modifiers instead of editing the value directly.
Have an array named something like pressedThisFrame that you push keys in to from your keydown event, and in the main loop you move entries out of pressedThisFrame and in to your overall pressedKeys array, and part of that move involves performing whatever modifiers are appropriate.