MODULE 03 · LESSON 3.1
Write predictable functions with clear inputs, outputs and branching.
From mental model to working change
Treat Values, Functions and Control Flow as an engineering decision with consequences for the user, the next layer and the person debugging it later. This lesson sits at the browser boundary, where structure, state and user input become observable behavior.
Here, that decision supports a specific checkpoint: Build a persistent learning tracker that loads and saves data safely. A reviewable result should include a browser inspection, keyboard test and a recorded expected-versus-actual result rather than a claim that the feature simply works.
Values, Functions and Control Flow workflow
- 1Primitive Values
- 2Scope
- 3Functions
- 4Conditionals
A practical model for values, functions and control flow
Write predictable functions with clear inputs, outputs and branching. The useful unit of understanding is the boundary: who owns the decision, which input crosses it, what result is visible and how a failure is reported.
- Primitive Values: Connect this concept to the module checkpoint and identify the evidence a reviewer should expect.
- Scope: Explain the concept without framework jargon, then point to it in the working example.
- Functions: Decide what belongs in code, configuration, data or documentation and explain why.
- Conditionals: Name its input, observable result and most likely failure in this lesson.
Follow the data through the example
Do not copy the sample yet. First explain why primitive values is handled at this boundary and what would break if it moved.
function completionRate(done, total) {
if (total <= 0) return 0;
return Math.round((done / total) * 100);
}Point to the exact line or command where scope enters the example and where its result becomes observable.
Ship a reviewable increment
- 1Primitive Values
Describe the behavior in one sentence, then choose the smallest input that can prove it.
- 2Scope
Add this responsibility at the narrowest sensible boundary; do not pull an unrelated layer into the change.
- 3Functions
Run the focused example and save the output, trace, query or screenshot that confirms the result.
- 4Conditionals
Break one assumption on purpose, make recovery clear and record the trade-off you accepted.
Risks to catch during review
- Treating primitive values as vocabulary instead of defining the behavior it must produce.
- Testing the expected path while ignoring an empty, invalid, repeated or unauthorized case around scope.
- Allowing functions to cross a boundary without an explicit contract or useful error.
- Changing several layers before capturing the first piece of evidence, which makes the original cause harder to see.
A repeatable investigation sequence
- Reduce the problem to the smallest failing Values, Functions and Control Flow case.
- Capture the actual input and output at the primitive values boundary.
- Read the first relevant error, request, trace or query rather than the loudest downstream symptom.
- Test one explanation for the failure in scope; avoid changing two variables together.
- Keep a regression check that would expose the same defect if it returned.
Security decision
Keep untrusted content separate from executable markup or script, preserve native browser protections, and validate again when data reaches the server.
Performance decision
Use DevTools to measure the rendered result. Prefer semantic markup and the smallest necessary CSS or JavaScript before adding a dependency.
PRACTICE
Build something you can inspect
Write and test functions for progress percentage, lesson status and empty states.
Stretch challenge
Build a second implementation of primitive values, compare it with the first, and defend the choice you would ship.
Definition of done
- The behavior around primitive values works with realistic input.
- A failure involving scope is handled clearly and without leaking sensitive detail.
- The implementation remains keyboard-usable when it produces an interface.
- Your evidence directly supports the claim made in the exercise.
- The README records the important trade-off without pretending the solution is universal.
Check your reasoning
What is the difference between returning a value and logging it?
Answer by naming the expected primitive values behavior, the layer responsible for it and the evidence that would confirm your explanation.
Where would you investigate the first failure?
Start where scope crosses a boundary. Compare the actual input and output there before following downstream symptoms.
What would make this work reviewable?
Show the focused change, repeatable steps, the result of your check and one honest trade-off connected to functions.
What to carry into the next lesson
- Write predictable functions with clear inputs, outputs and branching.
- Keep primitive values visible at the boundary where it can be tested.
- Use evidence from scope before widening the implementation.
References and related reading
Progress is stored only in this browser.
Share this page
Share this page with the people who will use it next.
Discussion
No comments yet. Add the first useful question or observation.
You must log in to post a comment.