Skip to content

Commit 741f5a1

Browse files
authored
Fix: Prevent division by zero in progress calculations (#265)
1 parent a1b97cb commit 741f5a1

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

js/PageLevelProgressIndicatorView.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ class PageLevelProgressIndicatorView extends Backbone.View {
5757
if (isPresentationComponentWithItems) {
5858
const children = this.model.getChildren();
5959
const visited = children.filter(child => child.get('_isVisited'));
60-
return Math.round(visited.length / children.length * 100);
60+
// Handle division by zero when component has no children
61+
return children.length === 0 ? 0 : Math.round(visited.length / children.length * 100);
6162
}
6263
return 0;
6364
}

js/completionCalculations.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ class Completion extends Backbone.Controller {
132132
// this allows the user to see if assessments have been passed, if assessment components can be retaken, and all other component's completion
133133
const completed = completionObject.nonAssessmentCompleted + completionObject.assessmentCompleted + completionObject.subProgressCompleted;
134134
const total = completionObject.nonAssessmentTotal + completionObject.assessmentTotal + completionObject.subProgressTotal;
135-
const percentageComplete = Math.floor((completed / total) * 100);
135+
// Handle division by zero when page contains only optional content
136+
const percentageComplete = total === 0 ? 0 : Math.floor((completed / total) * 100);
136137
return percentageComplete;
137138
}
138139

0 commit comments

Comments
 (0)