Empty Response From Multichoice Questions

Forums: 

So I’m looking at the H5P API documentation for the answered multichoice question on an interactive video.

https://h5p.org/node/3428

And I'm trying to figure something out. If you log event.data.statement.result.response after the user hits the check button, you’re supposed to get the user response. According to the documentation.

result.response:

The ids of the users answers where multiple alternatives are separated by “[,]“, for instance: “1[,]3” if the user answered the first and third alternatives in the way they are ordered in the editor

But for some reason I don’t understand I only get an empty string. Can anyone help me? It's been a big blocker for my project.

A rough version of what I'm trying to do is below.

H5P.externalDispatcher.on('xAPI', function (event) {

  if(event.data.statement.result.completion == true){

 

  console.log(event.data.statement.result.response);
  }
}

Content types: 
otacke's picture

Hi Shawn!

First of all, you should hit a couple of errors unless you click on check right away (which in fact will return an empty string, because no option was chosen). The result property is optional and should be checked. The same is true for the response property, even if the result property is set.

H5P.externalDispatcher.on('xAPI', function (event) {
  const result = event.data.statement.result;
  if (result && result.completion === true) {
    const response = event.data.statement.result.response;
    if (response) {
      console.log(response);
    }
  }
});

And that seems to be working quite fine here on h5p.org.

Best,
Oliver

Hi Oliver. I tried your code and it worked perfectly. However, the client has a new requirement that the questions no longer be in random order, and when I disable that option that the response I get is now an empty string. Any ideas?

otacke's picture

Hi Shawn!

Hard to say without knowing your code. The snippet that I posted before should work fine though, because turning off the randomize option will only change the order of the object.definition.choices array, but not the response object.

Best,
Oliver