Problem Statement

When Georgia runs, she runs a 6-mile loop each day. We don’t know how many days she runs, so we’ll call that number “d.” So, now we can say that Georgia runs 6d miles. (In other words, 6d is the expression that represents how much Georgia runs each week.)

6
Constant
Miles per day
d
Variable
Number of days
6d
Expression
Total miles
6×d
=6d

Math Expressions from Word Problems

Translating real-world situations into mathematical expressions is a core skill in programming and algebra. Let's break down a problem step-by-step.
Continue

1. Identify the Constant

First, look for numbers that don't change. In our example, Georgia runs a 6-mile loop. This '6' is our constant rate.
Continue

2. Identify the Variable

Next, find the unknown quantity. we don't know how many days she runs. We assign a variable (like 'd') to represent this unknown number.
Continue

3. Formulate the Expression

Combine the constant and the variable using the appropriate operation. Since she runs 6 miles *each* day, we multiply 6 by d.
Continue

4. The Result

The expression '6d' represents the total distance. You can now use this logic to write code that calculates distance for *any* number of days.
Continue

Interactive Practice

Try transforming another problem into an expression yourself. If Georgia ran 10 miles a day, what would the expression be?
Continue

Calculating with Code

Once you have your expression (6d), translating it to code is straightforward.

calculateDistance.js
function calculateTotalDistance(days) {
  // The expression 6d becomes 6 * days
  const milesPerDay = 6;
  return milesPerDay * days;
}

// Result for 5 days:
console.log(calculateTotalDistance(5)); // Output: 30
Implementation in JavaScript
AlgoAnimator: Interactive Data Structures