OLI Dynamic Questions

OLI Dynamic Questions

  • Docs
  • API
  • Examples
  • Help

›Statistics

About

  • Overview

Statistics

  • Calculating the mean

Mathematics

  • Solve for x

Chemistry

  • Stoichiometry

Calculating the mean

Here is an example of dynamic question that asks the student to calculate the mean of a distribution of numbers.

const count = Math.floor(Math.random() * 10) + 5;

const samples = [];
let total = 0;

for (let i = 0; i < count; i++) {
  const sample = Math.floor(Math.random() * 10) + 5;
  samples.push(sample);

  total += sample;
}

const average = total / count;

module.exports = {
  average,
  count,
  samples
};

The above code snippet defines and exports three variables (average, count, and samples) that can then be referenced from any part of a question.

← OverviewSolve for x →
OLI Dynamic Questions
Docs
Getting StartedWriting Scripts
Community
Course Showcase (Coming soon)OLI Slack
More
OLIOLI Course EditorGitHubStar
Copyright © 2025 Carnegie Mellon University