Represents Respondent's Answer.
CoolTool API allows you compare returned Answer with code of Alternative by using "==" and "!=" operators.
Properties:
Name | Type | Description |
---|---|---|
code | String | Chosen alternative code. |
value | Boolean | String | Value of the chosen alternative. |
alternative | Alternative | Refers to the chosen alternative. |
question | Question | Refers to the current question. |
Examples
// Suppose we want to do some operation if Alternative with code 'a1' has been chosen
// then we have to do next
// in case if you expect single answer in array
if (q.q1.get()=='a1') {
//do something
}
// in case if you expect answers from Multiple question
if (q.q1.get().contains('a1')) {
//do something
}
// Suppose we want to do some operation if Alternative with numeric code 1 has been chosen
// then we have to do next
// in case if you expect single answer in array
if (q.q1.get()==1) {
//do something
}
// in case if you expect answers from Multiple question
if (q.q1.get().contains(1)) {
//do something
}
// Suppose we have question with code q2 and numeric alternatives.
// Suppose then that we are interested in calculating the mean of Respondent's answers.
// then we do next job
// get answers array
var answersArray = q.q2.get();
var length = answersArray.length;
var sum = 0;
for (i = 0; i <length; i++){
var answer = answersArray[i];
// get answer's value. Since Other alternative returns value as String we convert it into Integer
sum = sum + parseInt(answer.value);
}
var mean = sum/length;