Chapter 29: Coding Foundations for Grade 8 Mathematics
Learn Grade 8 Math from beginner foundations through advanced Grade 8 problem solving with detailed explanations, at least five examples per topic, practice exercises, and review questions.
What this chapter covers
This chapter contains 13 topics. Technical terms are followed by plain-language meanings where they first appear. Each topic includes at least five worked examples. Coding is included only where it naturally supports the Grade 8 coding expectations.
29.1 Algorithm
An algorithm is a clear sequence of steps used to solve a problem or perform a calculation. In this section, the focus is Algorithm.
For a beginner, focus on the meaning before memorizing a procedure. Start with a small example, name the quantities and units, apply one rule at a time, and connect the result back to the question.
Coding example
// Algorithm
const points = [[1,2],[2,4],[3,5],[4,8],[5,9]];
const model = x => 1.8 * x + 0.2;
const predictions = points.map(([x,y]) => ({x, observed:y, predicted:model(x)}));
console.log(predictions);Code explanation
- The example stores a small set of coordinate pairs so each result can be checked manually.
model()represents a simple line used to estimate y-values from x-values.map()applies the model to every point and keeps both observed and predicted values.- Change the slope or intercept and compare the predictions to see whether the line follows the data more closely.
Expected result: A list of observed and predicted values is printed.
10 Worked Examples with Answers and Very-Beginner Explanations
Worked Example 1
Problem: Predict taxi cost: use the model cost = 4 + 2.5d with input 8.
- Identify the input variable.
- Substitute 8 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 24
Worked Example 2
Problem: Predict fundraiser revenue: use the model revenue = 120 + 15s with input 10.
- Identify the input variable.
- Substitute 10 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 270
Worked Example 3
Problem: Predict distance: use the model distance = 60t with input 2.5.
- Identify the input variable.
- Substitute 2.5 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 150
Worked Example 4
Problem: Predict savings: use the model savings = 200 + 50m with input 6.
- Identify the input variable.
- Substitute 6 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 500
Worked Example 5
Problem: Predict temperature trend: use the model temp = 18 - 1.5h with input 4.
- Identify the input variable.
- Substitute 4 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 12
Worked Example 6
Problem: Predict plant height: use the model height = 5 + 2w with input 7.
- Identify the input variable.
- Substitute 7 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 19
Worked Example 7
Problem: Predict rental cost: use the model cost = 30 + 8d with input 5.
- Identify the input variable.
- Substitute 5 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 70
Worked Example 8
Problem: Predict page count: use the model pages = 12r with input 9.
- Identify the input variable.
- Substitute 9 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 108
Worked Example 9
Problem: Predict points: use the model points = 6g + 3 with input 4.
- Identify the input variable.
- Substitute 4 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 27
Worked Example 10
Problem: Predict water use: use the model litres = 20 + 4m with input 5.
- Identify the input variable.
- Substitute 5 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 40
Practice exercise
Create one new Grade 8 problem involving Algorithm. Show the important steps, include units when needed, and explain how you checked the answer.
29.2 Variables in code
A variable is a letter or symbol that represents a value that may be unknown or may change. In this section, the focus is Variables in code.
For a beginner, focus on the meaning before memorizing a procedure. Start with a small example, name the quantities and units, apply one rule at a time, and connect the result back to the question.
Coding example
// Variables in code
const points = [[1,2],[2,4],[3,5],[4,8],[5,9]];
const model = x => 1.8 * x + 0.2;
const predictions = points.map(([x,y]) => ({x, observed:y, predicted:model(x)}));
console.log(predictions);Code explanation
- The example stores a small set of coordinate pairs so each result can be checked manually.
model()represents a simple line used to estimate y-values from x-values.map()applies the model to every point and keeps both observed and predicted values.- Change the slope or intercept and compare the predictions to see whether the line follows the data more closely.
Expected result: A list of observed and predicted values is printed.
10 Worked Examples with Answers and Very-Beginner Explanations
Worked Example 1
Problem: Simplify 3x + 2x.
- 3x and 2x are like terms.
- Add the coefficients: 3 + 2 = 5.
Very beginner explanation: Like terms have exactly the same variable part. Distribution multiplies every term inside parentheses.
Answer: 5x
Worked Example 2
Problem: Simplify 7y - 4y + 3.
- 7y and -4y are like terms.
- Combine them; keep the constant 3.
Very beginner explanation: Like terms have exactly the same variable part. Distribution multiplies every term inside parentheses.
Answer: 3y + 3
Worked Example 3
Problem: Simplify 4(a + 3).
- Multiply 4 by a.
- Multiply 4 by 3.
Very beginner explanation: Like terms have exactly the same variable part. Distribution multiplies every term inside parentheses.
Answer: 4a + 12
Worked Example 4
Problem: Simplify 2(3x - 5) + x.
- Distribute 2.
- 2(3x - 5)=6x-10.
- Combine 6x+x.
Very beginner explanation: Like terms have exactly the same variable part. Distribution multiplies every term inside parentheses.
Answer: 7x - 10
Worked Example 5
Problem: Simplify 5m + 8 - 2m - 3.
- Combine variable terms.
- Combine constant terms.
Very beginner explanation: Like terms have exactly the same variable part. Distribution multiplies every term inside parentheses.
Answer: 3m + 5
Worked Example 6
Problem: Simplify -3(2p + 4).
- Multiply -3 by both terms.
- Keep signs carefully.
Very beginner explanation: Like terms have exactly the same variable part. Distribution multiplies every term inside parentheses.
Answer: -6p - 12
Worked Example 7
Problem: Simplify 6x + 4 + x - 9.
- Combine x-terms.
- Combine constants.
Very beginner explanation: Like terms have exactly the same variable part. Distribution multiplies every term inside parentheses.
Answer: 7x - 5
Worked Example 8
Problem: Simplify 0.5x + 1.5x.
- Both terms have x.
- Add decimal coefficients 0.5 + 1.5.
Very beginner explanation: Like terms have exactly the same variable part. Distribution multiplies every term inside parentheses.
Answer: 2x
Worked Example 9
Problem: Simplify 3(2a + 1) - a.
- Distribute 3.
- Combine 6a-a.
Very beginner explanation: Like terms have exactly the same variable part. Distribution multiplies every term inside parentheses.
Answer: 5a + 3
Worked Example 10
Problem: Simplify 8q - 2(q + 3).
- Distribute -2.
- Combine 8q-2q.
Very beginner explanation: Like terms have exactly the same variable part. Distribution multiplies every term inside parentheses.
Answer: 6q - 6
Practice exercise
Create one new Grade 8 problem involving Variables in code. Show the important steps, include units when needed, and explain how you checked the answer.
29.3 Inputs and outputs
Inputs and outputs is an important Grade 8 concept in Coding Foundations for Grade 8 Mathematics. Start by identifying the quantities, relationships, units, or rules involved. Work with a small example first, show the important steps, and check whether the result is reasonable.
For a beginner, focus on the meaning before memorizing a procedure. Start with a small example, name the quantities and units, apply one rule at a time, and connect the result back to the question.
10 Worked Examples with Answers and Very-Beginner Explanations
Worked Example 1
Problem: Continue the pattern 2, 5, 8, ... for two more terms.
- Find the common difference: 3.
- Add the same difference each time.
Very beginner explanation: An arithmetic pattern changes by the same amount from one term to the next.
Answer: 11, 14
Worked Example 2
Problem: Continue the pattern 5, 9, 13, ... for two more terms.
- Find the common difference: 4.
- Add the same difference each time.
Very beginner explanation: An arithmetic pattern changes by the same amount from one term to the next.
Answer: 17, 21
Worked Example 3
Problem: Continue the pattern 10, 8, 6, ... for two more terms.
- Find the common difference: -2.
- Add the same difference each time.
Very beginner explanation: An arithmetic pattern changes by the same amount from one term to the next.
Answer: 4, 2
Worked Example 4
Problem: Continue the pattern 1.5, 2, 2.5, ... for two more terms.
- Find the common difference: 0.5.
- Add the same difference each time.
Very beginner explanation: An arithmetic pattern changes by the same amount from one term to the next.
Answer: 3, 3.5
Worked Example 5
Problem: Continue the pattern 20, 17.5, 15, ... for two more terms.
- Find the common difference: -2.5.
- Add the same difference each time.
Very beginner explanation: An arithmetic pattern changes by the same amount from one term to the next.
Answer: 12.5, 10
Worked Example 6
Problem: Continue the pattern 7, 13, 19, ... for two more terms.
- Find the common difference: 6.
- Add the same difference each time.
Very beginner explanation: An arithmetic pattern changes by the same amount from one term to the next.
Answer: 25, 31
Worked Example 7
Problem: Continue the pattern -3, 2, 7, ... for two more terms.
- Find the common difference: 5.
- Add the same difference each time.
Very beginner explanation: An arithmetic pattern changes by the same amount from one term to the next.
Answer: 12, 17
Worked Example 8
Problem: Continue the pattern 0.5, 1.75, 3, ... for two more terms.
- Find the common difference: 1.25.
- Add the same difference each time.
Very beginner explanation: An arithmetic pattern changes by the same amount from one term to the next.
Answer: 4.25, 5.5
Worked Example 9
Problem: Continue the pattern 12, 9, 6, ... for two more terms.
- Find the common difference: -3.
- Add the same difference each time.
Very beginner explanation: An arithmetic pattern changes by the same amount from one term to the next.
Answer: 3, 0
Worked Example 10
Problem: Continue the pattern 100, 110, 120, ... for two more terms.
- Find the common difference: 10.
- Add the same difference each time.
Very beginner explanation: An arithmetic pattern changes by the same amount from one term to the next.
Answer: 130, 140
Practice exercise
Create one new Grade 8 problem involving Inputs and outputs. Show the important steps, include units when needed, and explain how you checked the answer.
29.4 Conditions
Conditions is an important Grade 8 concept in Coding Foundations for Grade 8 Mathematics. Start by identifying the quantities, relationships, units, or rules involved. Work with a small example first, show the important steps, and check whether the result is reasonable.
For a beginner, focus on the meaning before memorizing a procedure. Start with a small example, name the quantities and units, apply one rule at a time, and connect the result back to the question.
10 Worked Examples with Answers and Very-Beginner Explanations
Worked Example 1
Problem: Conditions: Explain Conditions in one simple sentence.
- Look at the words in “Conditions”.
- State what the idea is used for.
- Give one small mathematical example.
Very beginner explanation: A beginner should first understand the meaning before memorizing a rule.
Answer: Conditions is a Grade 8 math idea used to describe or solve a specific mathematical relationship.
Worked Example 2
Problem: Conditions: A student says, “I can use Conditions without checking units or labels.” Is that a good method?
- Read the statement.
- Ask whether units, signs, labels, or conditions matter.
- Decide whether the method is safe.
Very beginner explanation: Many math mistakes come from using a correct calculation on the wrong quantity.
Answer: No. Important units, labels, signs, and conditions must be checked.
Worked Example 3
Problem: Conditions: What is the first step when solving a problem about Conditions?
- Read the whole question.
- Underline the known information.
- Identify what must be found.
Very beginner explanation: This prevents you from calculating before you understand the problem.
Answer: Identify the given information and the unknown before choosing a rule.
Worked Example 4
Problem: Conditions: After solving a Conditions problem, what should you do before accepting the answer?
- Estimate the expected size or direction.
- Check units and signs.
- Use an inverse method if possible.
Very beginner explanation: Checking is part of solving, not an optional extra.
Answer: Check whether the answer is reasonable and consistent with the problem.
Worked Example 5
Problem: Conditions: Give one way Conditions could appear outside a textbook.
- Think about money, measurements, data, maps, geometry, or technology.
- Connect the topic to one of those situations.
Very beginner explanation: Connecting math to real situations makes the rule easier to remember.
Answer: Conditions can be used in a real-life situation where quantities must be compared, measured, predicted, or calculated.
Worked Example 6
Problem: Conditions: Which representation could help explain Conditions: a table, graph, diagram, equation, or number line?
- Choose the representation that makes the relationship easiest to see.
- Label it clearly.
Very beginner explanation: Different representations show different features of the same mathematics.
Answer: Use the representation that best matches the problem; more than one may be valid.
Worked Example 7
Problem: Conditions: A student gets an answer for Conditions but cannot explain the steps. What should be improved?
- Rewrite the solution one step at a time.
- Name the rule used at each important step.
Very beginner explanation: A correct final number without reasoning may hide an error.
Answer: The reasoning should be shown so the solution can be checked.
Worked Example 8
Problem: Conditions: Why can estimation help before a detailed Conditions calculation?
- Round or use benchmark values.
- Predict the approximate answer.
- Compare the exact result with the estimate.
Very beginner explanation: If the exact answer is far from the estimate, recheck the work.
Answer: Estimation gives a target range for the final answer.
Worked Example 9
Problem: Conditions: How can you test whether your rule for Conditions works?
- Choose a very small easy example.
- Apply the rule.
- Check the result another way.
Very beginner explanation: Small examples expose mistakes quickly.
Answer: Test the rule on a simple case whose answer can be verified.
Worked Example 10
Problem: Conditions: How would you teach Conditions to someone seeing it for the first time?
- Define the idea.
- Show one easy example.
- Explain every step.
- Then let the learner try a similar problem.
Very beginner explanation: This sequence reduces memorization without understanding.
Answer: Teach meaning first, then a small worked example, then guided practice.
Practice exercise
Create one new Grade 8 problem involving Conditions. Show the important steps, include units when needed, and explain how you checked the answer.
29.5 Loops
A loop repeats a set of instructions in code. In this section, the focus is Loops.
For a beginner, focus on the meaning before memorizing a procedure. Start with a small example, name the quantities and units, apply one rule at a time, and connect the result back to the question.
Coding example
// Loops
const points = [[1,2],[2,4],[3,5],[4,8],[5,9]];
const model = x => 1.8 * x + 0.2;
const predictions = points.map(([x,y]) => ({x, observed:y, predicted:model(x)}));
console.log(predictions);Code explanation
- The example stores a small set of coordinate pairs so each result can be checked manually.
model()represents a simple line used to estimate y-values from x-values.map()applies the model to every point and keeps both observed and predicted values.- Change the slope or intercept and compare the predictions to see whether the line follows the data more closely.
Expected result: A list of observed and predicted values is printed.
10 Worked Examples with Answers and Very-Beginner Explanations
Worked Example 1
Problem: Predict taxi cost: use the model cost = 4 + 2.5d with input 8.
- Identify the input variable.
- Substitute 8 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 24
Worked Example 2
Problem: Predict fundraiser revenue: use the model revenue = 120 + 15s with input 10.
- Identify the input variable.
- Substitute 10 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 270
Worked Example 3
Problem: Predict distance: use the model distance = 60t with input 2.5.
- Identify the input variable.
- Substitute 2.5 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 150
Worked Example 4
Problem: Predict savings: use the model savings = 200 + 50m with input 6.
- Identify the input variable.
- Substitute 6 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 500
Worked Example 5
Problem: Predict temperature trend: use the model temp = 18 - 1.5h with input 4.
- Identify the input variable.
- Substitute 4 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 12
Worked Example 6
Problem: Predict plant height: use the model height = 5 + 2w with input 7.
- Identify the input variable.
- Substitute 7 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 19
Worked Example 7
Problem: Predict rental cost: use the model cost = 30 + 8d with input 5.
- Identify the input variable.
- Substitute 5 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 70
Worked Example 8
Problem: Predict page count: use the model pages = 12r with input 9.
- Identify the input variable.
- Substitute 9 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 108
Worked Example 9
Problem: Predict points: use the model points = 6g + 3 with input 4.
- Identify the input variable.
- Substitute 4 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 27
Worked Example 10
Problem: Predict water use: use the model litres = 20 + 4m with input 5.
- Identify the input variable.
- Substitute 5 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 40
Practice exercise
Create one new Grade 8 problem involving Loops. Show the important steps, include units when needed, and explain how you checked the answer.
29.6 Arrays of data
Data are observations, measurements, or categories collected to answer questions. In this section, the focus is Arrays of data.
For a beginner, focus on the meaning before memorizing a procedure. Start with a small example, name the quantities and units, apply one rule at a time, and connect the result back to the question.
Coding example
// Arrays of data
const points = [[1,2],[2,4],[3,5],[4,8],[5,9]];
const model = x => 1.8 * x + 0.2;
const predictions = points.map(([x,y]) => ({x, observed:y, predicted:model(x)}));
console.log(predictions);Code explanation
- The example stores a small set of coordinate pairs so each result can be checked manually.
model()represents a simple line used to estimate y-values from x-values.map()applies the model to every point and keeps both observed and predicted values.- Change the slope or intercept and compare the predictions to see whether the line follows the data more closely.
Expected result: A list of observed and predicted values is printed.
10 Worked Examples with Answers and Very-Beginner Explanations
Worked Example 1
Problem: Predict taxi cost: use the model cost = 4 + 2.5d with input 8.
- Identify the input variable.
- Substitute 8 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 24
Worked Example 2
Problem: Predict fundraiser revenue: use the model revenue = 120 + 15s with input 10.
- Identify the input variable.
- Substitute 10 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 270
Worked Example 3
Problem: Predict distance: use the model distance = 60t with input 2.5.
- Identify the input variable.
- Substitute 2.5 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 150
Worked Example 4
Problem: Predict savings: use the model savings = 200 + 50m with input 6.
- Identify the input variable.
- Substitute 6 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 500
Worked Example 5
Problem: Predict temperature trend: use the model temp = 18 - 1.5h with input 4.
- Identify the input variable.
- Substitute 4 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 12
Worked Example 6
Problem: Predict plant height: use the model height = 5 + 2w with input 7.
- Identify the input variable.
- Substitute 7 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 19
Worked Example 7
Problem: Predict rental cost: use the model cost = 30 + 8d with input 5.
- Identify the input variable.
- Substitute 5 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 70
Worked Example 8
Problem: Predict page count: use the model pages = 12r with input 9.
- Identify the input variable.
- Substitute 9 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 108
Worked Example 9
Problem: Predict points: use the model points = 6g + 3 with input 4.
- Identify the input variable.
- Substitute 4 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 27
Worked Example 10
Problem: Predict water use: use the model litres = 20 + 4m with input 5.
- Identify the input variable.
- Substitute 5 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 40
Practice exercise
Create one new Grade 8 problem involving Arrays of data. Show the important steps, include units when needed, and explain how you checked the answer.
29.7 Coordinates in code
Coordinates locate a point using an ordered pair (x, y), with horizontal movement first and vertical movement second. In this section, the focus is Coordinates in code.
For a beginner, focus on the meaning before memorizing a procedure. Start with a small example, name the quantities and units, apply one rule at a time, and connect the result back to the question.
Coding example
// Coordinates in code
const points = [[1,2],[2,4],[3,5],[4,8],[5,9]];
const model = x => 1.8 * x + 0.2;
const predictions = points.map(([x,y]) => ({x, observed:y, predicted:model(x)}));
console.log(predictions);Code explanation
- The example stores a small set of coordinate pairs so each result can be checked manually.
model()represents a simple line used to estimate y-values from x-values.map()applies the model to every point and keeps both observed and predicted values.- Change the slope or intercept and compare the predictions to see whether the line follows the data more closely.
Expected result: A list of observed and predicted values is printed.
10 Worked Examples with Answers and Very-Beginner Explanations
Worked Example 1
Problem: Where is the point (2,3) located?
- Move horizontally using x.
- Move vertically using y.
- Identify the quadrant or axis.
Very beginner explanation: Ordered pairs are always written (x, y): horizontal first, vertical second.
Answer: Quadrant I
Worked Example 2
Problem: Where is the point (-4,5) located?
- Move horizontally using x.
- Move vertically using y.
- Identify the quadrant or axis.
Very beginner explanation: Ordered pairs are always written (x, y): horizontal first, vertical second.
Answer: Quadrant II
Worked Example 3
Problem: Where is the point (-3,-2) located?
- Move horizontally using x.
- Move vertically using y.
- Identify the quadrant or axis.
Very beginner explanation: Ordered pairs are always written (x, y): horizontal first, vertical second.
Answer: Quadrant III
Worked Example 4
Problem: Where is the point (6,-1) located?
- Move horizontally using x.
- Move vertically using y.
- Identify the quadrant or axis.
Very beginner explanation: Ordered pairs are always written (x, y): horizontal first, vertical second.
Answer: Quadrant IV
Worked Example 5
Problem: Where is the point (0,4) located?
- Move horizontally using x.
- Move vertically using y.
- Identify the quadrant or axis.
Very beginner explanation: Ordered pairs are always written (x, y): horizontal first, vertical second.
Answer: on an axis
Worked Example 6
Problem: Where is the point (5,0) located?
- Move horizontally using x.
- Move vertically using y.
- Identify the quadrant or axis.
Very beginner explanation: Ordered pairs are always written (x, y): horizontal first, vertical second.
Answer: on an axis
Worked Example 7
Problem: Where is the point (-7,2) located?
- Move horizontally using x.
- Move vertically using y.
- Identify the quadrant or axis.
Very beginner explanation: Ordered pairs are always written (x, y): horizontal first, vertical second.
Answer: Quadrant II
Worked Example 8
Problem: Where is the point (1,-6) located?
- Move horizontally using x.
- Move vertically using y.
- Identify the quadrant or axis.
Very beginner explanation: Ordered pairs are always written (x, y): horizontal first, vertical second.
Answer: Quadrant IV
Worked Example 9
Problem: Where is the point (-2,-8) located?
- Move horizontally using x.
- Move vertically using y.
- Identify the quadrant or axis.
Very beginner explanation: Ordered pairs are always written (x, y): horizontal first, vertical second.
Answer: Quadrant III
Worked Example 10
Problem: Where is the point (8,7) located?
- Move horizontally using x.
- Move vertically using y.
- Identify the quadrant or axis.
Very beginner explanation: Ordered pairs are always written (x, y): horizontal first, vertical second.
Answer: Quadrant I
Practice exercise
Create one new Grade 8 problem involving Coordinates in code. Show the important steps, include units when needed, and explain how you checked the answer.
29.8 Functions
Functions is an important Grade 8 concept in Coding Foundations for Grade 8 Mathematics. Start by identifying the quantities, relationships, units, or rules involved. Work with a small example first, show the important steps, and check whether the result is reasonable.
For a beginner, focus on the meaning before memorizing a procedure. Start with a small example, name the quantities and units, apply one rule at a time, and connect the result back to the question.
Coding example
// Functions
const points = [[1,2],[2,4],[3,5],[4,8],[5,9]];
const model = x => 1.8 * x + 0.2;
const predictions = points.map(([x,y]) => ({x, observed:y, predicted:model(x)}));
console.log(predictions);Code explanation
- The example stores a small set of coordinate pairs so each result can be checked manually.
model()represents a simple line used to estimate y-values from x-values.map()applies the model to every point and keeps both observed and predicted values.- Change the slope or intercept and compare the predictions to see whether the line follows the data more closely.
Expected result: A list of observed and predicted values is printed.
10 Worked Examples with Answers and Very-Beginner Explanations
Worked Example 1
Problem: Predict taxi cost: use the model cost = 4 + 2.5d with input 8.
- Identify the input variable.
- Substitute 8 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 24
Worked Example 2
Problem: Predict fundraiser revenue: use the model revenue = 120 + 15s with input 10.
- Identify the input variable.
- Substitute 10 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 270
Worked Example 3
Problem: Predict distance: use the model distance = 60t with input 2.5.
- Identify the input variable.
- Substitute 2.5 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 150
Worked Example 4
Problem: Predict savings: use the model savings = 200 + 50m with input 6.
- Identify the input variable.
- Substitute 6 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 500
Worked Example 5
Problem: Predict temperature trend: use the model temp = 18 - 1.5h with input 4.
- Identify the input variable.
- Substitute 4 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 12
Worked Example 6
Problem: Predict plant height: use the model height = 5 + 2w with input 7.
- Identify the input variable.
- Substitute 7 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 19
Worked Example 7
Problem: Predict rental cost: use the model cost = 30 + 8d with input 5.
- Identify the input variable.
- Substitute 5 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 70
Worked Example 8
Problem: Predict page count: use the model pages = 12r with input 9.
- Identify the input variable.
- Substitute 9 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 108
Worked Example 9
Problem: Predict points: use the model points = 6g + 3 with input 4.
- Identify the input variable.
- Substitute 4 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 27
Worked Example 10
Problem: Predict water use: use the model litres = 20 + 4m with input 5.
- Identify the input variable.
- Substitute 5 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 40
Practice exercise
Create one new Grade 8 problem involving Functions. Show the important steps, include units when needed, and explain how you checked the answer.
29.9 Debugging
Debugging means finding and fixing errors in code or logic. In this section, the focus is Debugging.
For a beginner, focus on the meaning before memorizing a procedure. Start with a small example, name the quantities and units, apply one rule at a time, and connect the result back to the question.
Coding example
// Debugging
const points = [[1,2],[2,4],[3,5],[4,8],[5,9]];
const model = x => 1.8 * x + 0.2;
const predictions = points.map(([x,y]) => ({x, observed:y, predicted:model(x)}));
console.log(predictions);Code explanation
- The example stores a small set of coordinate pairs so each result can be checked manually.
model()represents a simple line used to estimate y-values from x-values.map()applies the model to every point and keeps both observed and predicted values.- Change the slope or intercept and compare the predictions to see whether the line follows the data more closely.
Expected result: A list of observed and predicted values is printed.
10 Worked Examples with Answers and Very-Beginner Explanations
Worked Example 1
Problem: Predict taxi cost: use the model cost = 4 + 2.5d with input 8.
- Identify the input variable.
- Substitute 8 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 24
Worked Example 2
Problem: Predict fundraiser revenue: use the model revenue = 120 + 15s with input 10.
- Identify the input variable.
- Substitute 10 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 270
Worked Example 3
Problem: Predict distance: use the model distance = 60t with input 2.5.
- Identify the input variable.
- Substitute 2.5 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 150
Worked Example 4
Problem: Predict savings: use the model savings = 200 + 50m with input 6.
- Identify the input variable.
- Substitute 6 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 500
Worked Example 5
Problem: Predict temperature trend: use the model temp = 18 - 1.5h with input 4.
- Identify the input variable.
- Substitute 4 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 12
Worked Example 6
Problem: Predict plant height: use the model height = 5 + 2w with input 7.
- Identify the input variable.
- Substitute 7 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 19
Worked Example 7
Problem: Predict rental cost: use the model cost = 30 + 8d with input 5.
- Identify the input variable.
- Substitute 5 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 70
Worked Example 8
Problem: Predict page count: use the model pages = 12r with input 9.
- Identify the input variable.
- Substitute 9 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 108
Worked Example 9
Problem: Predict points: use the model points = 6g + 3 with input 4.
- Identify the input variable.
- Substitute 4 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 27
Worked Example 10
Problem: Predict water use: use the model litres = 20 + 4m with input 5.
- Identify the input variable.
- Substitute 5 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 40
Practice exercise
Create one new Grade 8 problem involving Debugging. Show the important steps, include units when needed, and explain how you checked the answer.
29.10 Tracing code
Tracing code is an important Grade 8 concept in Coding Foundations for Grade 8 Mathematics. Start by identifying the quantities, relationships, units, or rules involved. Work with a small example first, show the important steps, and check whether the result is reasonable.
For a beginner, focus on the meaning before memorizing a procedure. Start with a small example, name the quantities and units, apply one rule at a time, and connect the result back to the question.
Coding example
// Tracing code
const points = [[1,2],[2,4],[3,5],[4,8],[5,9]];
const model = x => 1.8 * x + 0.2;
const predictions = points.map(([x,y]) => ({x, observed:y, predicted:model(x)}));
console.log(predictions);Code explanation
- The example stores a small set of coordinate pairs so each result can be checked manually.
model()represents a simple line used to estimate y-values from x-values.map()applies the model to every point and keeps both observed and predicted values.- Change the slope or intercept and compare the predictions to see whether the line follows the data more closely.
Expected result: A list of observed and predicted values is printed.
10 Worked Examples with Answers and Very-Beginner Explanations
Worked Example 1
Problem: Predict taxi cost: use the model cost = 4 + 2.5d with input 8.
- Identify the input variable.
- Substitute 8 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 24
Worked Example 2
Problem: Predict fundraiser revenue: use the model revenue = 120 + 15s with input 10.
- Identify the input variable.
- Substitute 10 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 270
Worked Example 3
Problem: Predict distance: use the model distance = 60t with input 2.5.
- Identify the input variable.
- Substitute 2.5 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 150
Worked Example 4
Problem: Predict savings: use the model savings = 200 + 50m with input 6.
- Identify the input variable.
- Substitute 6 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 500
Worked Example 5
Problem: Predict temperature trend: use the model temp = 18 - 1.5h with input 4.
- Identify the input variable.
- Substitute 4 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 12
Worked Example 6
Problem: Predict plant height: use the model height = 5 + 2w with input 7.
- Identify the input variable.
- Substitute 7 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 19
Worked Example 7
Problem: Predict rental cost: use the model cost = 30 + 8d with input 5.
- Identify the input variable.
- Substitute 5 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 70
Worked Example 8
Problem: Predict page count: use the model pages = 12r with input 9.
- Identify the input variable.
- Substitute 9 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 108
Worked Example 9
Problem: Predict points: use the model points = 6g + 3 with input 4.
- Identify the input variable.
- Substitute 4 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 27
Worked Example 10
Problem: Predict water use: use the model litres = 20 + 4m with input 5.
- Identify the input variable.
- Substitute 5 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 40
Practice exercise
Create one new Grade 8 problem involving Tracing code. Show the important steps, include units when needed, and explain how you checked the answer.
29.11 Using code for calculations
Using code for calculations is an important Grade 8 concept in Coding Foundations for Grade 8 Mathematics. Start by identifying the quantities, relationships, units, or rules involved. Work with a small example first, show the important steps, and check whether the result is reasonable.
For a beginner, focus on the meaning before memorizing a procedure. Start with a small example, name the quantities and units, apply one rule at a time, and connect the result back to the question.
Coding example
// Using code for calculations
const points = [[1,2],[2,4],[3,5],[4,8],[5,9]];
const model = x => 1.8 * x + 0.2;
const predictions = points.map(([x,y]) => ({x, observed:y, predicted:model(x)}));
console.log(predictions);Code explanation
- The example stores a small set of coordinate pairs so each result can be checked manually.
model()represents a simple line used to estimate y-values from x-values.map()applies the model to every point and keeps both observed and predicted values.- Change the slope or intercept and compare the predictions to see whether the line follows the data more closely.
Expected result: A list of observed and predicted values is printed.
10 Worked Examples with Answers and Very-Beginner Explanations
Worked Example 1
Problem: Predict taxi cost: use the model cost = 4 + 2.5d with input 8.
- Identify the input variable.
- Substitute 8 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 24
Worked Example 2
Problem: Predict fundraiser revenue: use the model revenue = 120 + 15s with input 10.
- Identify the input variable.
- Substitute 10 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 270
Worked Example 3
Problem: Predict distance: use the model distance = 60t with input 2.5.
- Identify the input variable.
- Substitute 2.5 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 150
Worked Example 4
Problem: Predict savings: use the model savings = 200 + 50m with input 6.
- Identify the input variable.
- Substitute 6 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 500
Worked Example 5
Problem: Predict temperature trend: use the model temp = 18 - 1.5h with input 4.
- Identify the input variable.
- Substitute 4 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 12
Worked Example 6
Problem: Predict plant height: use the model height = 5 + 2w with input 7.
- Identify the input variable.
- Substitute 7 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 19
Worked Example 7
Problem: Predict rental cost: use the model cost = 30 + 8d with input 5.
- Identify the input variable.
- Substitute 5 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 70
Worked Example 8
Problem: Predict page count: use the model pages = 12r with input 9.
- Identify the input variable.
- Substitute 9 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 108
Worked Example 9
Problem: Predict points: use the model points = 6g + 3 with input 4.
- Identify the input variable.
- Substitute 4 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 27
Worked Example 10
Problem: Predict water use: use the model litres = 20 + 4m with input 5.
- Identify the input variable.
- Substitute 5 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 40
Practice exercise
Create one new Grade 8 problem involving Using code for calculations. Show the important steps, include units when needed, and explain how you checked the answer.
29.12 Using code for graphs
Using code for graphs is an important Grade 8 concept in Coding Foundations for Grade 8 Mathematics. Start by identifying the quantities, relationships, units, or rules involved. Work with a small example first, show the important steps, and check whether the result is reasonable.
For a beginner, focus on the meaning before memorizing a procedure. Start with a small example, name the quantities and units, apply one rule at a time, and connect the result back to the question.
Coding example
// Using code for graphs
const points = [[1,2],[2,4],[3,5],[4,8],[5,9]];
const model = x => 1.8 * x + 0.2;
const predictions = points.map(([x,y]) => ({x, observed:y, predicted:model(x)}));
console.log(predictions);Code explanation
- The example stores a small set of coordinate pairs so each result can be checked manually.
model()represents a simple line used to estimate y-values from x-values.map()applies the model to every point and keeps both observed and predicted values.- Change the slope or intercept and compare the predictions to see whether the line follows the data more closely.
Expected result: A list of observed and predicted values is printed.
10 Worked Examples with Answers and Very-Beginner Explanations
Worked Example 1
Problem: Predict taxi cost: use the model cost = 4 + 2.5d with input 8.
- Identify the input variable.
- Substitute 8 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 24
Worked Example 2
Problem: Predict fundraiser revenue: use the model revenue = 120 + 15s with input 10.
- Identify the input variable.
- Substitute 10 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 270
Worked Example 3
Problem: Predict distance: use the model distance = 60t with input 2.5.
- Identify the input variable.
- Substitute 2.5 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 150
Worked Example 4
Problem: Predict savings: use the model savings = 200 + 50m with input 6.
- Identify the input variable.
- Substitute 6 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 500
Worked Example 5
Problem: Predict temperature trend: use the model temp = 18 - 1.5h with input 4.
- Identify the input variable.
- Substitute 4 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 12
Worked Example 6
Problem: Predict plant height: use the model height = 5 + 2w with input 7.
- Identify the input variable.
- Substitute 7 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 19
Worked Example 7
Problem: Predict rental cost: use the model cost = 30 + 8d with input 5.
- Identify the input variable.
- Substitute 5 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 70
Worked Example 8
Problem: Predict page count: use the model pages = 12r with input 9.
- Identify the input variable.
- Substitute 9 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 108
Worked Example 9
Problem: Predict points: use the model points = 6g + 3 with input 4.
- Identify the input variable.
- Substitute 4 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 27
Worked Example 10
Problem: Predict water use: use the model litres = 20 + 4m with input 5.
- Identify the input variable.
- Substitute 5 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 40
Practice exercise
Create one new Grade 8 problem involving Using code for graphs. Show the important steps, include units when needed, and explain how you checked the answer.
29.13 Documenting code logic
Documenting code logic is an important Grade 8 concept in Coding Foundations for Grade 8 Mathematics. Start by identifying the quantities, relationships, units, or rules involved. Work with a small example first, show the important steps, and check whether the result is reasonable.
For a beginner, focus on the meaning before memorizing a procedure. Start with a small example, name the quantities and units, apply one rule at a time, and connect the result back to the question.
Coding example
// Documenting code logic
const points = [[1,2],[2,4],[3,5],[4,8],[5,9]];
const model = x => 1.8 * x + 0.2;
const predictions = points.map(([x,y]) => ({x, observed:y, predicted:model(x)}));
console.log(predictions);Code explanation
- The example stores a small set of coordinate pairs so each result can be checked manually.
model()represents a simple line used to estimate y-values from x-values.map()applies the model to every point and keeps both observed and predicted values.- Change the slope or intercept and compare the predictions to see whether the line follows the data more closely.
Expected result: A list of observed and predicted values is printed.
10 Worked Examples with Answers and Very-Beginner Explanations
Worked Example 1
Problem: Predict taxi cost: use the model cost = 4 + 2.5d with input 8.
- Identify the input variable.
- Substitute 8 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 24
Worked Example 2
Problem: Predict fundraiser revenue: use the model revenue = 120 + 15s with input 10.
- Identify the input variable.
- Substitute 10 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 270
Worked Example 3
Problem: Predict distance: use the model distance = 60t with input 2.5.
- Identify the input variable.
- Substitute 2.5 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 150
Worked Example 4
Problem: Predict savings: use the model savings = 200 + 50m with input 6.
- Identify the input variable.
- Substitute 6 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 500
Worked Example 5
Problem: Predict temperature trend: use the model temp = 18 - 1.5h with input 4.
- Identify the input variable.
- Substitute 4 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 12
Worked Example 6
Problem: Predict plant height: use the model height = 5 + 2w with input 7.
- Identify the input variable.
- Substitute 7 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 19
Worked Example 7
Problem: Predict rental cost: use the model cost = 30 + 8d with input 5.
- Identify the input variable.
- Substitute 5 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 70
Worked Example 8
Problem: Predict page count: use the model pages = 12r with input 9.
- Identify the input variable.
- Substitute 9 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 108
Worked Example 9
Problem: Predict points: use the model points = 6g + 3 with input 4.
- Identify the input variable.
- Substitute 4 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 27
Worked Example 10
Problem: Predict water use: use the model litres = 20 + 4m with input 5.
- Identify the input variable.
- Substitute 5 into the model.
- Calculate the predicted output.
- Ask whether the result makes sense in the real situation.
Very beginner explanation: A mathematical model is a simplified rule for representing a real situation. Predictions should always be checked for reasonableness.
Answer: 40
Practice exercise
Create one new Grade 8 problem involving Documenting code logic. Show the important steps, include units when needed, and explain how you checked the answer.
Chapter 29 Review Questions and Answers
Q1. What is important to remember about Algorithm?
Answer: An algorithm is a clear sequence of steps used to solve a problem or perform a calculation. In this section, the focus is Algorithm.
Q2. What is important to remember about Variables in code?
Answer: A variable is a letter or symbol that represents a value that may be unknown or may change. In this section, the focus is Variables in code.
Q3. What is important to remember about Inputs and outputs?
Answer: Inputs and outputs is an important Grade 8 concept in Coding Foundations for Grade 8 Mathematics. Start by identifying the quantities, relationships, units, or rules involved. Work with a small example first, show the important steps, and check whether the result is reasonable.
Q4. What is important to remember about Conditions?
Answer: Conditions is an important Grade 8 concept in Coding Foundations for Grade 8 Mathematics. Start by identifying the quantities, relationships, units, or rules involved. Work with a small example first, show the important steps, and check whether the result is reasonable.
Q5. What is important to remember about Loops?
Answer: A loop repeats a set of instructions in code. In this section, the focus is Loops.
Q6. What is important to remember about Arrays of data?
Answer: Data are observations, measurements, or categories collected to answer questions. In this section, the focus is Arrays of data.
Q7. What is important to remember about Coordinates in code?
Answer: Coordinates locate a point using an ordered pair (x, y), with horizontal movement first and vertical movement second. In this section, the focus is Coordinates in code.
Q8. What is important to remember about Functions?
Answer: Functions is an important Grade 8 concept in Coding Foundations for Grade 8 Mathematics. Start by identifying the quantities, relationships, units, or rules involved. Work with a small example first, show the important steps, and check whether the result is reasonable.
Q9. What is important to remember about Debugging?
Answer: Debugging means finding and fixing errors in code or logic. In this section, the focus is Debugging.
Q10. What is important to remember about Tracing code?
Answer: Tracing code is an important Grade 8 concept in Coding Foundations for Grade 8 Mathematics. Start by identifying the quantities, relationships, units, or rules involved. Work with a small example first, show the important steps, and check whether the result is reasonable.
Q11. What is important to remember about Using code for calculations?
Answer: Using code for calculations is an important Grade 8 concept in Coding Foundations for Grade 8 Mathematics. Start by identifying the quantities, relationships, units, or rules involved. Work with a small example first, show the important steps, and check whether the result is reasonable.
Q12. What is important to remember about Using code for graphs?
Answer: Using code for graphs is an important Grade 8 concept in Coding Foundations for Grade 8 Mathematics. Start by identifying the quantities, relationships, units, or rules involved. Work with a small example first, show the important steps, and check whether the result is reasonable.
Q13. What is important to remember about Documenting code logic?
Answer: Documenting code logic is an important Grade 8 concept in Coding Foundations for Grade 8 Mathematics. Start by identifying the quantities, relationships, units, or rules involved. Work with a small example first, show the important steps, and check whether the result is reasonable.
Q14. Why should you show your steps?
Answer: Showing steps makes reasoning easier to verify and helps locate mistakes.
Q15. Why is estimation useful?
Answer: Estimation helps you judge whether a calculated answer is reasonable.
Q16. Why do units matter?
Answer: Units tell what a value measures and prevent incompatible quantities from being mixed.
Q17. When should you round?
Answer: Usually round near the end unless the question specifically asks for earlier rounding.
Q18. How can you check an answer?
Answer: Use an inverse operation, substitution, estimation, a graph, or a second method.
Q19. What should you identify first in a word problem?
Answer: Identify what is known, what is unknown, and the mathematical relationship connecting them.
Q20. What makes a final answer complete?
Answer: Give the value, correct units when needed, and a brief interpretation in context.
Q21. What should you do if an answer seems unreasonable?
Answer: Re-read the question and check copied values, signs, units, formulas, and calculations.
Q22. Why are diagrams useful?
Answer: A labelled diagram can reveal relationships among lengths, angles, areas, and coordinates.
Q23. Why are tables useful?
Answer: Tables organize values and help reveal patterns, rates, relationships, and missing information.
Q24. Why should you explain your reasoning?
Answer: Reasoning shows why a method works, not just what answer was obtained.
Q25. How do mistakes help learning?
Answer: Analyzing a mistake identifies the misunderstood rule or step and helps prevent repetition.
Q26. When is a calculator useful?
Answer: A calculator helps with lengthy arithmetic after the mathematical setup is understood and estimated.
Q27. Why compare more than one strategy?
Answer: Different strategies may make a problem easier and provide a way to verify the result.
Q28. What is mathematical communication?
Answer: It is presenting ideas clearly with words, symbols, diagrams, tables, graphs, and justified steps.
Q29. What is mathematical modelling?
Answer: It is representing a real situation with mathematics, testing the model, and revising it if needed.
Q30. Why should assumptions be stated?
Answer: Assumptions show the conditions the model depends on and help readers judge whether it is reasonable.