thecodezone.
The Code Zone
← Back to the Developer Playbook

Code Zone Bug Lab / Episode 09

The Function That Returns Nothing

The Console knows the area is 12. The page insists it is undefined.

DEV-152 · Functions · parameters · return15–20 minutesNo setup or account required
A rectangle calculation logs twelve but leaves the returned result undefined.
A rectangle calculation logs twelve but leaves the returned result undefined.

Your sprint ticket · In progress · DEV-152

The Function That Returns Nothing.

Customer report: My calculator logs the right area but displays undefined as the result.

Steps to reproduce

  1. Keep width 4 and height 3.
  2. Click Calculate area.
  3. Compare the result with the value logged in the Console.

Make a focused behavior fix. Styling and adding unrelated features belong to another ticket.

Acceptance criteria

  • 4 × 3 displays Area: 12.
  • 7 × 2 displays Area: 14.
  • A zero dimension produces Area: 0.
  • Decimal dimensions work, such as 2.5 × 4 = 10.

Learning demo only. No real accounts, purchases, authentication, or external requests.

Reproduce → inspect → hypothesize → verify

Take the ticket.

Reproduce the bug before editing. Inspect the Console and the JS tab. Explain one hypothesis, change the relevant code, then use Check challenge below the editor. Test the full ticket, not only the starter example. Reveal hints one at a time if needed.

Checking account and saved lab work…

Sign in to sync across devices

Loading the JavaScript and HTML editor…

Pass the checks or make three attempts to unlock an explained example.

Ready to test? Choose “Check challenge” after investigating.

    Open starter in a separate tab

    Code and prediction notes recover in this browser and sync when signed in. Instructor examples stay separate. Reset replaces code, not prediction notes.

    One possible solution

    Compare this approach with your own. Opening it does not change your code or mark the exercise complete.

    Add return area; after the calculation. A function without an explicit return produces undefined. Logging a result and returning it serve different purposes. Verify changed arguments and zero, rather than returning a hardcoded 12.

    Try first. Reveal one clue at a time.

    Need a lead?

    1. Look at the caller.

    What value does calculateArea give back to the code that called it?

    2. Logging is a side effect.

    console.log displays a value but does not make the containing function return that value.

    3. Return the computed result.

    Add return area after calculating. Keep the function useful for different arguments.

    Your lab report

    Show your reasoning.

    “I expected… I observed… The console showed… My hypothesis was… I changed… I verified…”

    Use Check challenge for automated behavior checks. Passing checks are useful evidence, not a complete code review.

    Give others room to investigate: label solutions as spoilers.

    Share your lab report on SKOOL (new tab) ↗