Calculating Scores
I want to create a quiz that tallies up the total score based on the choices a user makes on a set of questions of "Category" type. I'd like to take the index number of each response (0, 1, 2, 3), calculate, and display the sum. Please help :)

  • Hi Josh, This may help if you haven't worked it out yet, and assuming the category fields are single choice var c = @Category.replace(/\\s/g,""); //strips all of the spaces out of the category namevar catgry = {catA:0,catB:1,catC:2,catD:3,catE:4}; //assigns a number to all the category optionscatgry[c];  //returns the number associated with the selected category you need to replace catA, catB, etc with your category names with spaces removed. With this method you can also specify whatever value you want to each category selection. Obviously for your calculation you will have multiple to choose from so it will need to be something like this var total = 0;var cat1 = @Category1.replace(/\\s/g,""); var catgry1 = {catA:0,catB:1,catC:2,catD:3,catE:4};total += catgry1[cat1];var cat2 = @Category2.replace(/\\s/g,""); var catgry2 = {selectionA:0,selectionB:1,selectionC:2,selectionD:3,selectionE:4};total += catgry2[cat2];etc...write = "score = " + total;
  • Hi Josh, what do the category fields look like? Something like this?A) All category fields with categories 0  1  2 3 ?orB) category field with categories a b c d ? And you want to count the a as 0 , b as 1  and so on?And if B) - have all category fields the same categories? Rainer
This question is closed.