hasAnswer()
The hasAnswer() function (client-side and server-side) determines whether a specific answer has been provided for a question.
Syntax
Use this syntax for the hasAnswer() function:
hasAnswer('QUESTION_CODE', 'ANSWER_CODE');
Return Value
The hasAnswer() function returns either true or false. If the specified answer has been selected for the question, the function the returns true. If a different answer has been provided or the question hasn't been answered, the function returns false.
Parameters
The question and answer codes are required.
The hasAnswer() function accepts the following parameters:
-
QUESTION_CODE(string) - Specifies the code that identifies the question for which you want to verify the provided answer. You can find the code in the Code field on the question record. -
ANSWER_CODE(string) - Specifies the code that identifies the answer you want to verify. You can find the code in the Code field on the answer record.
Examples
The following examples show how to use the hasAnswer() function.
Determining a Question's Selected Answer
This example verifies whether the question with the code SCREEN_SIZE has been answered with the code SIZE16. If the answer matches, the function returns true.
const isScreenSize16 = hasAnswer('SCREEN_SIZE', 'SIZE16');
console.log(isScreenSize16);