Module 1 · Mathematical Language and Quantitative Reasoning Lesson 2 of 120

Functions, Domains, Ranges, and Graphs

A payment fee calculator with a valid input range.

2:34 clip10:57–13:32 in the full courseWatch on YouTube

Transcript

26 sentences · select one to jump there

Check your understanding

Does a negative amount automatically mean a negative fee?

Choose one answer

Code lab

Run it yourself

The lesson source in 7 languages. Edit it, run TypeScript and Python right here, and compare with the expected output.

002-functions-domains-ranges-and-graphs.ts
Start from GitHub
/**
 * Fintech Math Bootcamp · Lesson 002 of 120
 * Functions, Domains, Ranges, and Graphs
 * Module 01: Mathematical Language and Quantitative Reasoning
 *
 * Scenario: A payment fee calculator with a valid input range
 * Rule:     fee(x) = 1 + 0.02x, x ≥ 0
 *
 * Try it:   Does a negative amount automatically mean a negative fee?
 *
 * Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/mathematical-language-and-quantitative-reasoning/functions-domains-ranges-and-graphs/
 * Free course:    https://courses.thefintechbuilder.com
 * Synthetic teaching example, not financial advice or a production library.
 */

export function lesson002() {
  const fee = (amount: number): number => {
    if (!Number.isFinite(amount) || amount < 0)
      throw new Error("Invalid amount");
    return 1 + 0.02 * amount;
  };
  const result = fee(100);
  return result;
}

export const checkedResult = 3;

// Run this file directly: npx tsx lessons/01-mathematical-language-and-quantitative-reasoning/002-functions-domains-ranges-and-graphs.ts
if (process.argv[1] && import.meta.url.endsWith(process.argv[1].replace(/\\/g, "/").split("/").pop()!)) {
  console.log(JSON.stringify(lesson002(), null, 2));
}

Your output

Press Run to execute the code in your browser.

Expected output

3

Prefer your own machine? Every file is in the course repository · open it in Codespaces.

Lesson notes

The rule

fee(x) = 1 + 0.02x, x ≥ 0