Practice Task

Practice: Explain and triage a provided code snippet

Explain a JavaScript order-total function, identify likely bugs, and propose a minimal safe fix.

Practice typeRealistic client scenario · no cash reward
SubmissionsOpen practice; every contributor can submit their own version
Review outcomePass: +25 Trust Points. Revision or not passed: no points until fixed.
Current statusOpen
Practice boundaryRead the exercise here; submit and revise in the task room

The brief is not the submission area

This page gives the customer scenario, source material, deliverables, review criteria, and suggested format. Formal practice submissions, files, revision notes, and review outcomes belong in the task room so each attempt is auditable.

Exercise brief

Use this page to understand the scenario, assumptions, source material, deliverables, and pass/fail criteria before working.

Task room

Submit the completed result, upload supporting files, send clarification messages, and resubmit a new version if revision is requested.

Reusable practice

There is no participant quota. Multiple contributors can submit, and each version is reviewed against the same criteria.

Review record

Outcomes are pass, revision needed, or not passed. Only a passing version earns Trust Points or case-review eligibility.

Client Scenario

What problem are you solving?

A client has an old order-total function. They say zero-quantity gifts and orders with missing quantities are often wrong, but they have not asked you to rewrite production code.

System Context

Use these assumptions

Assume the code could run in Node.js or browser JavaScript. Do not access a repository and do not rewrite the whole module. Focus on explanation, risks, test cases, and minimal repair.

Source Material

Base your work only on this material

function total(items){
  let sum=0;
  for(const item of items){
    if(item.qty) sum += item.price * item.qty;
  }
  return sum.toFixed(2);
}

Client note: zero-quantity gifts and missing-quantity orders are often wrong.
Deliverables

What to submit

  • What the code currently does
  • Likely bugs and trigger conditions
  • At least five test cases
  • Minimal safe fix proposal
  • What not to change without more context
Review Criteria

What makes a result pass review

  • Mention qty=0 being skipped
  • Mention price/qty type risk
  • Mention toFixed returns a string
  • Do not suggest a full rewrite without evidence
  • Tie each test case to a risk
Submission Format

Recommended format

  • Structured engineering note
  • Small fix snippet is allowed, but explanation and tests are required