Skip to content

Instantly share code, notes, and snippets.

@jwatzek
Last active April 16, 2019 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwatzek/ec268673a29f636572f9d0a901ca3c58 to your computer and use it in GitHub Desktop.
Save jwatzek/ec268673a29f636572f9d0a901ca3c58 to your computer and use it in GitHub Desktop.
Interpolate yr. and mos. from slider on log scale. Save to Embedded Data field for piping. If "Not applicable" (renamed "Keep the same") box checked, copy previous value.
Qualtrics.SurveyEngine.addOnload(function()
{
var answer = "${q://QID62/ChoiceNumericEntryValue/1}";
var sqrt32 = Math.pow(2, 1/3);
answer = parseFloat(answer);
answer = Math.pow(sqrt32, answer - 1);
var years = Math.floor(answer);
var months = answer % 1;
months *= 12;
months = Math.floor(months);
if (isNaN(years)) {
Qualtrics.SurveyEngine.setEmbeddedData('Punishment2', "${e://Field/Punishment1}");
} else {
Qualtrics.SurveyEngine.setEmbeddedData('Punishment2', years.toString() + ' yr. and ' + months.toString() + ' mos.');
}
$('Buttons').hide();
this.clickNextButton();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment