# Custom Grading Scheme - All items mandatory

## Custom Grading - All Items Mandatory

In this example we'll describe a custom scheme that enforces all components in course mandatory for course completion, even without any component explicitly declared as mandatory. Calculation & Display: Percent

Name: all (name should be all)

Weight: 100

Rule:

var lr=TOTAL_LESSONS;
var tr=(TOTAL_TESTS+TOTAL_SURVEYS);
var sr=TOTAL_SCORMS;
var score=0;
var total=0;
if(lr > 0){
total ++;
}
if(tr > 0){
total ++;
}
if(sr > 0){
total ++;
}
if(lr > 0){
score += ((lr-PENDING_LESSONS)/lr)*100.0/total;
}
if(tr > 0){
score += ((tr-PENDING_TESTS-PENDING_SURVEYS)/tr)*100.0/total;
}
if(sr > 0){
score += ((sr-PENDING_SCORMS)/sr)*100.0/total;
}
me.expressionResult = score;

Explanation:

The rule first checks the number of lessons, tests & surveys and scorms in the course. Based on the counts, it evenly allocates weights to each kind of learning activities. E.g. if course only consists of lessons, all 100% weight get allocated to lessons, whereas if course has lessons and tests, it divides the weights as 50 - 50 and if all 3 kind of activities are present it divides weights evenly as 33.33%...

Within each kind, it gives score in proportion to the total number of activities and completed activities.

When all activities are completed, learner would get 100% which is also set as the passing score.

If we need to consider only gradable lessons, tests, surveys and scorms in the above example, then the rule will change slightly, to use gradable counts rather than total counts. Here is the modified rule.

```var lr=GR_LESSONS;
var tr=(GR_TESTS+GR_SURVEYS);
var sr=GR_SCORMS;
var score=0;
var total=0;
if(lr > 0){ total ++; }
if(tr > 0){ total ++; }
if(sr > 0){ total ++; }
if(lr > 0){ score += ((lr-PENDING_GR_LESSONS)/lr)*100.0/total; }
if(tr > 0){ score += ((tr-PENDING_GR_TESTS-PENDING_GR_SURVEYS)/tr)*100.0/total; }
if(sr > 0){ score += ((sr-PENDING_GR_SCORMS)/sr)*100.0/total; }
me.expressionResult = score;```

Rating: