Picture of Leonardo Alves
Assessment Random Question Bank How to get question number
by Leonardo Alves - Thursday, 4 January 2018, 7:23 PM
 

Hi I need to get the question number of a random question from a question block. 

I am using the assessment extension to get 10 random questions from 20 question in a course.

Everything is working fine but I need to let the user know the question they are in. For ex: Question 3 of 10.

How can I get that information. Inside the mcq component when I log the data of the component the nth-child is always 1.  I can get the list the id of the question. But how can I get the generated question block to compare ids and get the position.

Thanks

Picture of Leonardo Alves
Re: Assessment Random Question Bank How to get question number
by Leonardo Alves - Thursday, 4 January 2018, 8:42 PM
 

I lost a few hours trying to find where that data was shown. And could not.  If someone knows where I can get this data please let me know.

For now I solved with kind of a hack.  I added a div with the class eachQuestionNumber in my template and on the page pageView:ready event I use jQuery to calculate it.

Adapt.on('pageView:ready', function() {
  $(document).ready(function() {
    var elements = $('.eachQuestionNumber')
    elments.each(function(index) {
      $(this).text('Question ' + (index + 1) + ' of ' + elements.length)
    })
  })
})
 
It's working for now. But it's very hacky and I am not confident at all with this solution. But for now will leave like this.
 
Thanks
Picture of Matt Leathes
Re: Assessment Random Question Bank How to get question number
by Matt Leathes - Monday, 15 January 2018, 6:53 PM
 

You could do something like this:

function getQuestionNumber(){
    var questionComponents = Adapt.assessment.get()[0]._currentQuestionComponents;
    return questionComponents.indexOf(Adapt.findById(this._id)) + 1;
}
Handlebars.registerHelper("questionNumber", getQuestionNumber);

That would allow you to display the question number by setting the displayTitle of the question to "Question {{questionNumber}}" in the JSON

Picture of K Edison
Re: Assessment Random Question Bank How to get question number
by K Edison - Tuesday, 26 February 2019, 6:36 PM
 

In which file do I add this function to? I am using the Framework version 3.2.0.

Picture of Matt Leathes
Re: Assessment Random Question Bank How to get question number
by Matt Leathes - Wednesday, 27 February 2019, 10:10 AM
 

https://github.com/adaptlearning/adapt-contrib-assessment#componentsjson