commit a596dea2626935daba969efa02850fd1d7cf0bd4
parent 7681fc52712b8c50555c6bf9ab22c1b778a1376d
Author: hrryt <harry@mayesfield.uk>
Date: Thu, 24 Sep 2026 19:38:58 +0100
Add subtracting fractions
Diffstat:
6 files changed, 35 insertions(+), 20 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -3,12 +3,13 @@
- Fix upside-down SVGs on Safari
# Questions
-- Improve adding fractions (subtraction etc.)
+- Improve adding fractions (sign of result, matching denominators, etc.)
- Add more questions
- Add plotting questions
- Find all roots of this quintic (or something) polynomial (repeated root knowledge)
- Transformations of shapes and graphs (curves)
- tricky parallel lines / internal angles etc questions
+ - Solve and represent inequalities
# Other stuff
- minesweeper / youtube video.
diff --git a/src/components/questions/AddingFractionsQuestion.jsx b/src/components/questions/AddingFractionsQuestion.jsx
@@ -1,6 +1,6 @@
import { formatFraction } from '../../scripts/formatUtils.js';
import { simplifyFraction, getHCF } from '../../scripts/mathsUtils.js';
-import { getRandomInt } from '../../scripts/randomUtils.js';
+import { getRandomInt, getRandomSelection } from '../../scripts/randomUtils.js';
import Question from '../Question.jsx';
function getRandomFraction(seed) {
@@ -17,8 +17,12 @@ function getRandomFractions(seed) {
return [num1, denom1, num2, denom2];
}
-export default function AddingFractionsQuestion({ seed, showAnswer }) {
- const [num1, denom1, num2, denom2] = getRandomFractions(seed++);
+export default function AddingFractionsQuestion({ seed, showAnswer, sign }) {
+
+ const sign2 = getRandomSelection(sign, { "Addition": [1], "Subtraction": [-1] }, seed++);
+
+ const [num1, denom1, absNum2, denom2] = getRandomFractions(seed++);
+ const num2 = sign2 * absNum2;
const question = formatFraction(num1, denom1) + formatFraction(num2, denom2, { showPlus: true });
diff --git a/src/components/questions/QuadraticEquationQuestion.jsx b/src/components/questions/QuadraticEquationQuestion.jsx
@@ -1,6 +1,6 @@
import { formatCoefficient, formatFraction } from '../../scripts/formatUtils.js';
import { getHCF } from '../../scripts/mathsUtils.js';
-import { getRandomChoice, getRandomInt } from '../../scripts/randomUtils.js';
+import { getRandomSelection, getRandomChoice, getRandomInt } from '../../scripts/randomUtils.js';
import Question from '../Question.jsx';
function formatQuadraticExpression(a, b, c) {
@@ -41,23 +41,14 @@ function formatFactors(l, m, n, o) {
export default function QuadraticEquationQuestion({ seed, showAnswer, aPlurality, framing, cSigns }) {
// (lx + m)(nx + o)
- const aChoices = Array();
- aPlurality.includes("a=1") && aChoices.push([1, 1]);
- // conveniently these all multiply to < 6.
- aPlurality.includes("a>1") && aChoices.push([1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [2, 2], [2, 3]);
- let [l, n] = getRandomChoice(aChoices, seed++)
-
- const factoriseChoices = Array();
- framing.includes("Solve") && factoriseChoices.push(false);
- framing.includes("Factorise") && factoriseChoices.push(true);
- const factorise = getRandomChoice(factoriseChoices, seed++);
-
- const cSignChoices = Array();
- cSigns.includes("Positive") && cSignChoices.push(1)
- cSigns.includes("Negative") && cSignChoices.push(-1)
+ const factorise = getRandomSelection(framing, { "Solve" : [false], "Factorise": [true] }, seed++);
+ const cSign = getRandomSelection(cSigns, { "Positive": [1], "Negative" : [-1] }, seed++);
+ let [l, n] = getRandomSelection(aPlurality, {
+ "a=1": [[1, 1]],
+ "a>1": [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [2, 2], [2, 3]],
+ }, seed++);
const mSign = getRandomChoice([-1, 1], seed++)
- const cSign = getRandomChoice(cSignChoices, seed++)
let m = getRandomInt(1, 9, seed++) * mSign
let o = getRandomInt(1, 9, seed++) * mSign * cSign
diff --git a/src/data/questions/Number/adding-fractions.js b/src/data/questions/Number/adding-fractions.js
@@ -1,24 +1,34 @@
import AddingFractionsQuestion from '/src/components/questions/AddingFractionsQuestion.jsx';
+import MultipleSelection from '/src/components/MultipleSelection.jsx';
export const data = {
title: 'Adding Fractions',
+ variables: [{
+ id: 'sign',
+ legend: 'Question type',
+ type: MultipleSelection,
+ values: ["Addition", "Subtraction"],
+ }],
questionLists: [{
id: 0,
n: 10,
questions: [{
type: AddingFractionsQuestion,
+ variables: { sign: 'sign' },
}]
}, {
id: 1,
n: 10,
questions: [{
type: AddingFractionsQuestion,
+ variables: { sign: 'sign' },
}]
}, {
id: 2,
n: 10,
questions: [{
type: AddingFractionsQuestion,
+ variables: { sign: 'sign' },
}]
}]
}
diff --git a/src/index.jsx b/src/index.jsx
@@ -78,6 +78,7 @@ function Sidebar() {
</Route>
</SidebarLink>
<SidebarLink href="/renderer" title="LaTeX Renderer" />
+ <li><a href="https://git.ttmaths.uk">Source Code</a></li>
</ul>
</nav>
);
diff --git a/src/scripts/randomUtils.js b/src/scripts/randomUtils.js
@@ -14,3 +14,11 @@ export function getRandomNumber(seed) {
const x = 1e4 * Math.sin(7 * seed);
return x - Math.floor(x);
}
+
+export function getRandomSelection(arr, dictionary, seed) {
+ const choices = Array();
+ for (const key in dictionary) {
+ arr.includes(key) && choices.push(...dictionary[key]);
+ }
+ return getRandomChoice(choices, seed);
+}