Forum Discussion

AdityaChettri's avatar
AdityaChettri
Community Member
3 months ago

Console error: Please check code for AccButton, setState()

Hi Everyone,

I have a set of questions which I am putting on individual slides so that the learner can go through them and answer. I am using two approaches and both are giving me some form of error.

1. Textboxes in place of options, and I am using JavaScript to track the choice using a variable.

2. Using the Graded Question slide, with radio buttons, again I am using JavaScript to track which option user has clicked and based on it, I am mapping it to the total score and competency score.

I am using JavaScript for two reasons, I have to perform some mapping of scores at a later point and also wanted to get my hands dirty to see what could be done. Here's the code:

var player = GetPlayer();

var selectedAns = player.GetVar("selected_answer");

var points = {
"A": 2,
"B":1,
"C":0,
"D":1
};

var selectedPoints = points[selectedAns];

var competencyScore = player.GetVar("comp3");
competencyScore+=selectedPoints;
player.SetVar("comp3",competencyScore);


var totalScore = player.GetVar("total");
totalScore += selectedPoints;
player.SetVar("total",totalScore);

 

Any suggestions or help would be appreciated regarding the error and best practices, cause right now the scores are messing up.

Also is there a way to dynamically create a new variable (or an element) in code and display it on the slide e.g. I want to calculate the comp3_percentage and display it on the slide.

var comp3_percentage = (comp3/6)*100;

 

No RepliesBe the first to reply