Reuse a Rule with a Parameter
Pass a threshold into a function without changing its comparison.
Supplied materials
- Paper and pencil; an adult may read aloud. No device, account or purchase is needed.
Learn the idea
A function is a named set of instructions. A parameter is an input named in those instructions; each call supplies its value. In this lesson both pages and goal are already-valid whole numbers from 0 through 30. A parameter lets one comparison work for different fictional goals.
Define status(pages, goal): if pages ≥ goal, return reached; else return continue. Return gives the result for that call. Compare status(8, 6) and status(8, 10). The pages input stays 8 while the goal parameter changes; the function body still uses ≥ and does not remember the previous call.
- Write the function with parameter names pages and goal.
- For each call, substitute its two supplied numbers.
- Evaluate the comparison and record the returned word.
- Test equality with status(6, 6).
See the method in action
status(8, 6) evaluates 8 ≥ 6 and returns reached. status(8, 10) evaluates 8 ≥ 10 and returns continue. status(6, 6) returns reached because equality is included.
Check your reasoning
Your answer is temporary and is not saved to an account. Download your current answer before leaving or reloading. Written work on paper or in another app stays in your own file.
See the answer and explanation
Reached
The inputs satisfy the stated contract and 7 ≥ 7 is true. The function returns reached; it does not add the parameters.
Take it further
Change only the goal input: compare status(7, 8) with status(7, 5). Expected returns: continue, reached. Explain which parameter caused the change.
Nothing here is saved to an account or sent to a teacher. The answer download includes your current choice and any checked feedback.
Check the subject sources
These LifeStarter passages, scenarios and exercises are authored for this Academy with AI assistance and review. External resources keep their publishers’ terms. A grade label suggests a starting level; it does not establish alignment with your school’s complete requirements.