In plain words
A function is a named block of code that takes some inputs, does one job with them and hands back a result whenever you call it.
Where you see it
When your agent says it "added a formatPrice helper", that's a function. It's defined once, then called on the menu, at checkout and in the order email, each time with a different price.
What goes wrong
- Forgetting the return
The function does the work, then hands back undefined. The page shows a blank, or the word undefined, where the price should be.
function addTax(price) { price * 1.2; } - Leaving off the brackets
formatPrice names the function and formatPrice(1250) runs it. Without the brackets nothing runs, and the function itself gets passed around instead of its result.
- One function doing five jobs
A 200-line function that saves the order, charges the card and sends the email is hard to read and harder to fix. Ask for one function per job.
What to tell your agent
Quick check
Sign in to earn +10 XP for itQuickBite's receipt shows the total as "undefined". The calculateTotal function adds up every item. Likely bug?