🔧 Describing Functions & Methods
4 exercises — read a function and choose the most accurate, natural English description. Focus on purpose, inputs, outputs, and edge cases.
0 / 4 completed
How to describe a function — template
- "This function takes [inputs] and returns [output]."
- "It checks whether / calculates / converts / groups…"
- "If [condition], it [behaviour]; otherwise, it [behaviour]."
- Focus on purpose, not implementation. Avoid repeating the code in words.
1 / 4
Read this function. Which description is the most accurate and natural in English?
function clamp(value, min, max) {
return Math.min(Math.max(value, min), max);
}Option C is the best description. A good function description should: (1) name the inputs in plain terms, (2) describe the purpose rather than the implementation details, (3) describe the output and edge-case behaviour. Option B is technically accurate but overcomplicated — it describes how the code works rather than what it does. Option D is partially correct (it returns the middle of three numbers when value is between min and max) but misses the clamping intent.
Next up: Classes & Objects →