The Life Starter
0 of 6 complete0%
Course Library · Lesson 3 of 6
Digital · Guided lesson

Separate and test the calculation

About 31 minutes · 6 reading + 25 practice and checks
Time includes reading, practice, and questions. Extra videos or further study are optional.
See this course’s project requirements

A keyboard-usable local workshop calculator with clear validation, correct totals, and an eight-case test record.

Keep your working files in your own notebook or software. Save a private description, checklist, and work link in My Proof.

What to include

  • Two-input state trace.
  • Deliberate type conversion and blank handling.
  • Isolated tested calculation.
  • Shared submit handler for pointer and keyboard.
  • Clear feedback and eight-case test record.

Review and revise

Use these criteria to check your work and choose what to improve.

  • Totals match the stated rule.
  • Invalid input never shows a current total.
  • Keyboard and pointer paths work consistently.
  • Tests and limitations are accurately reported.
Open the full course project
Want more background?
Before you begin

The idea in everyday life

Make a small fictional workshop calculator respond reliably to user input.

The idea

A function with explicit inputs can be tested independently of a page.

Follow along

Separate and test the calculation — guided practice

Change one pricing rule without altering event or display code.

Save workshop-calculator.html and open it locally in a browser; open the same file in a text editor. It is a complete original worked program. The rule is 8 units per seat, 1–6 whole seats, plus one optional 5-unit group pack. Nothing is sent or bought. Restore the supplied file before each lesson’s code variation.

  1. 1. Call the function

    Run calculate(2,false) in the browser console.

    calculate(2,false)

    You should see: The result is 16.

    You can test the rule without clicking the form.

  2. 2. Test the add-on

    Run calculate(2,true).

    calculate(2,true)

    You should see: The result is 21.

    The optional pack is a single group charge.

  3. 3. Change one rule

    In a copy, replace seats*8 with seats*9 inside calculate only. Save/reload and run calculate(2,true).

    You should see: The new result is 23.

    A focused rule change has a predictable effect.

  4. 4. Restore and document

    Restore 8 and write the two baseline outputs plus the changed output.

    You should see: Baseline is 16/21; variation is 23.

    Recording expected behavior supports future review.

Now change one thing

At 8 units per seat, what does calculate(6,true) return?

Your work

What to finish

A small calculation test record and isolated rule edit.

Common mistake

Watch for this

Updating explanatory text but forgetting the actual formula, or changing the formula without its visible explanation.

How can I tell I understand it?

Complete the changed case, explain your result, and pass the three application checks.

Try 3 questions

Quick knowledge check

Answer all 3 questions. Get at least 2 right and the lesson completes automatically.

Not yet passed

You’ll get an explanation for each answer. Signed in? Your results save to your account.

1A function returns n*4 + (extra?2:0). For n=3 and extra=true, result?
2A pricing function reads a hidden global value that changes elsewhere. What makes it harder to test?
3You change a fee from 5 to 6. Which test isolates the fee change?
0 of 3 answeredApply the lesson to a short question, then review the explanation.
3
Finish this lesson

Pass the check. We’ll save the progress.

Answer all 3 questions above and get at least 2 right. You can review the explanations and try again.

Go to the knowledge check
Optional course overview video · same video as Lesson 1
Traversy MediaJavaScript DOM Crash Course - Part 1YouTube
Optional course overview

JavaScript DOM Crash Course - Part 1

From Traversy Media. Watch here or open it on YouTube .

Optional course overview. Follow the written steps below at your own pace.
Tools, templates, and lesson sources

Tools and templates

Tools open in a new tab so you can keep your place here.

Sources and further reading

Explore the references behind this lesson.

MDN: Introduction to events
Source & access notes · checked 2026-09-12

Opened and inspected on 2026-09-12: Listeners and event objects.

Access: Free public web page; no paid enrollment required.

Reuse: Public reference; link only. LifeStarter prose, exercises and files are independently authored.

MDN: DOM scripting introduction
Source & access notes · checked 2026-09-12

Opened and inspected on 2026-09-12: Element selection and text updates.

Access: Free public web page; no paid enrollment required.

Reuse: Public reference; link only. LifeStarter prose, exercises and files are independently authored.

Report a problem with this lesson

Tell us what went wrong. Please leave out personal information and private project contents.

No sign-in needed.