Java for converting minutes to hours | XM Community
Skip to main content
Hello,



I have a value of minutes (the answer of QID1). And if this value is over than 60, I want to convert this to hours and minutes.



Qualtrics.SurveyEngine.addOnReady(function()

{

var hours = parseInt(("${q://QID1/ChoiceTextEntryValue}") / 60);

var mins = parseInt(("${q://QID1/ChoiceTextEntryValue}") % 60);



var t1;

if(hours = 0){

t1 == mins;

}

Qualtrics.SurveyEngine.setEmbeddedData("t1", mins + " minutes");



else if(hours >= 1){

t1 == hours;

}

Qualtrics.SurveyEngine.setEmbeddedData("t1", hours + " hours " + mins + " minutes");

});





The problem is the "else if" part. I know the current code is wrong because it is showing only hours.



Could anyone help me correct this code?



Thank you very much in advance.
Hello @jhwang ,



Here is the updated code:



var hours = parseInt(("${q://QID1/ChoiceTextEntryValue}") / 60);

var mins = parseInt(("${q://QID1/ChoiceTextEntryValue}") % 60);



if(hours == 0){



Qualtrics.SurveyEngine.setEmbeddedData("t1", mins + " minutes");

}



else {



Qualtrics.SurveyEngine.setEmbeddedData("t1", hours + " hours " + mins + " minutes");

}
@Shashi



Perfect!



Thanks a lot!

Leave a Reply