OLI Dynamic Questions

OLI Dynamic Questions

  • Docs
  • API
  • Examples
  • Help

›Chemistry

About

  • Overview

Statistics

  • Calculating the mean

Mathematics

  • Solve for x

Chemistry

  • Stoichiometry

Stoichiometry

Here is an example of a dynamic question that asks the student to calculate the amount of $H_{2}$ produced in the chemical reaction:

$$Zn + 2HCl \to H_{2} + ZnCl_{2}$$

// create the random value for grams of Zn
const gramsZn = OLI.randomInt(5, 60);
const molarMass = 65.38;

// create a function that solves the equation
const solver = (grams, molarMass) => { 

  // convert grams to moles:
  const molesZn = grams / molarMass;
  const molesH = molesZn; // 1 to 1 molar ratio

  // H2 molar mass is around 2g, 
  // result is rounded to two decimal places.
  const gramsH = OLI.round(molesH * 2.02, 4);

  return gramsH
};

// solution
const solution = solver(gramsZn, molarMass);

// distractors
const distractor1 = solver(gramsZn, 63.55); // grams of Cu, element left of Zn
const distractor2 = solver(gramsZn, 69.72); // grams of Ga, element right of Zn
const distractor3 = solver(gramsZn, molarMass) / 2; // result without accounting for H2
const distractor4 = solver(gramsZn, 36.55); // result using HCl molar mass instead of Zn

module.exports = {
    gramsZn,
    solution,
    distractor1,
    distractor2,
    distractor3,
    distractor4,
};

The above code snippet defines and exports six variables (gramsZn, solution , distractor1, distractor2, distractor3 and distractor4). These can be used in any part of the question.

The script creates a function that calculates the answer so that it can be referenced multiple times later in the script. This is useful for creating distractors.

← Solve 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