Skip to content

Commit

Permalink
Squashed commit & merge of the following:
Browse files Browse the repository at this point in the history
*note* See changelog.md for more information (v1.1.1)

commit b891e7d
Author: Jim Ke <jimke2000@gmail.com>
Date:   Fri Jul 30 18:04:12 2021 +1000

    Release

commit 396d91e
Author: Jim Ke <jimke2000@gmail.com>
Date:   Fri Jul 30 18:02:31 2021 +1000

    Questions are now in columns instead of rows

    Updated changelogs accordingly
    Questions are now generated in columns and rows to fit more in.
    Questions per sheet buffed from 25 -> 50

    Due to this experimental problem solving is broken :(

commit 880a97f
Author: Jim Ke <jimke2000@gmail.com>
Date:   Fri Jul 30 14:38:20 2021 +1000

    CHANGELOG update

commit 131483e
Author: Jim Ke <jimke2000@gmail.com>
Date:   Fri Jul 30 14:35:45 2021 +1000

    Problem solving engine update

    Added warnings to indicate it's experimental
    Added more questions to each sheet (10 -> 25)
    No two characters will be the same
    Updated changelog accordingly

commit c90f002
Author: Jim Ke <jimke2000@gmail.com>
Date:   Fri Jul 30 14:25:37 2021 +1000

    *experimental* problem solving engine

commit 00d6645
Author: Jim Ke <jimke2000@gmail.com>
Date:   Fri Jul 30 14:13:53 2021 +1000

    bump ver

commit a871288
Author: Jim Ke <jimke2000@gmail.com>
Date:   Fri Jul 30 14:11:19 2021 +1000

    Prettified errors

commit 250f2b9
Author: Jim Ke <jimke2000@gmail.com>
Date:   Fri Jul 30 14:08:01 2021 +1000

    CONTRIBUTING

commit ff96002
Author: Jim Ke <jimke2000@gmail.com>
Date:   Thu Jul 29 15:31:32 2021 +1000

    Expermiental problem solving
  • Loading branch information
Compositr committed Aug 1, 2021
1 parent 2917aae commit deee7fe
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 24 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<!-- @format -->

# v1.1.0 (28/07/2021 1:35PM AEST)
# v1.1.1 (30/07/2021 2:11PM AEST) Colour Release! Patch #1
- Bumped questions per sheet to 50 from 20
- Questions + answers now appear in columns to fit more questions in
- Added contributing guidelines (see CONTRIBUTING file)
- Made errors more user-friendly (instead of the default NodeJS error)
- Added experimental problem solving engine. Enter `p` when selecting a worksheet type.
> **Warning** Problem solving is experimental and does *not* work yet, and is a pre-release (sneak peek/leak).
> It is not actually meant for use yet, and will be fully released in `v1.2.0 Problem Solvers`
# v1.1.0 (28/07/2021 1:35PM AEST) Colour Release!

- Added timestamp to worksheet
- Added × and ÷ functionality
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
We are currently not looking for committers. If you still want to contribute, open a PR.
87 changes: 87 additions & 0 deletions database/ps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/** @format */

"use strict";
/** Problem solving worksheet handler/generator */
/**
* This file handles math problem generation and handles other math-y stuff.
*/

/**
* @class
* Mathamatical Expression object class
*/
class Expression {
/**
* Generate a new Expression
* @param {String} expr An expression
* @param {Number} answer Answer to the expression
* @param {Number} first First number
* @param {Number} last Last number
* @param {String} type Type of question
*/
constructor(expr, answer, first, last, type) {
this.expr = expr;
this.answer = answer;
this.first = first;
this.last = last;
this.type = type;
}
evalutate() {
return eval(expr);
}
}

function rnd(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function err(e) {
return console.log(chalk`
{red Whoops! An error occured. Please refer to the message below for more information}
${e}
`);
}

const characters = [
"Billy",
"Noel",
"Harry",
"Issac",
"Sasha",
"Dominic",
"Bella",
"Simon",
"Mary",
"Max",
];
const objects = [
"pencils",
"pens",
"scissors",
"cups",
"caps",
"phones",
"dollars",
"apples",
"oranges",
"bananas",
];
module.exports = () => {
const questions = [];
for (let i = 0; i < 25; i++) {
let person1 = characters[rnd(0, characters.length - 1)];
let person2 = characters[rnd(0, characters.length - 1)];
while(person1 === person2) {
person1 = characters[rnd(0, characters.length - 1)];
person2 = characters[rnd(0, characters.length - 1)];
}
const object = objects[rnd(0, objects.length - 1)];
const first = rnd(2, 20);
const last = rnd(2, 20);
const answer = first + last;
questions.push({
q: `${person2} has ${first} ${object}. ${person1} gave ${person2} ${last} ${object}. How many ${object} does ${person2} have now?`,
a: answer,
});
}
return questions;
};
71 changes: 50 additions & 21 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* @license
* All code within this repository, including this file is licensed under the
* All code within this repository, including this file is licensed under the
* GNU GENERAL PUBLIC LICENSE
* Version 3, 29 June 2007
*/
Expand All @@ -15,6 +15,10 @@ const { default: jsPDF } = require("jspdf");
const prompt = require("prompt");
const chalk = require("chalk");

const problemGen = require("./database/ps");

const questionsPerSheet = 50;

prompt.start();
prompt.message = chalk`
Select a type of worksheet and press {green ENTER} {gray Valid choices are {magenta + - / *}}`;
Expand All @@ -31,46 +35,47 @@ function app(type) {
if (type == "*") humantype = "Multiplication";
if (type == "/") humantype = "Division";
if (type == "-") humantype = "Subtraction";
if (type == "p") humantype = "Problem Solving";

/** Generate Questions */
const questions = [];
let questions = [];
if (type == "+") {
for (let index = 0; index < 20; index++) {
let first = rnd(1, 20);
let last = rnd(1, 20);
for (let index = 0; index < questionsPerSheet; index++) {
let first = rnd(1, 25);
let last = rnd(1, 25);
let answer = first + last;
questions.push({
q: `${first} + ${last}`,
q: `${first} + ${last}=`,
a: answer,
});
}
} else if (type == "-") {
for (let i = 0; i < 25; i++) {
let first = rnd(1, 20);
let last = rnd(1, 20);
for (let i = 0; i < questionsPerSheet; i++) {
let first = rnd(1, 25);
let last = rnd(1, 25);
/** Prevent negative answers */
while (first < last) {
first = rnd(1, 20);
last = rnd(1, 20);
first = rnd(1, 25);
last = rnd(1, 25);
}
let answer = first - last;
questions.push({
q: `${first} - ${last}`,
q: `${first} - ${last}=`,
a: answer,
});
}
} else if (type === "*") {
for (let i = 0; i < 25; i++) {
for (let i = 0; i < questionsPerSheet; i++) {
let first = rnd(1, 12);
let last = rnd(1, 12);
let answer = first * last;
questions.push({
q: `${first}×${last}`,
q: `${first}×${last}=`,
a: answer,
});
}
} else if (type === "/") {
for (let i = 0; i < 25; i++) {
for (let i = 0; i < questionsPerSheet; i++) {
let first = rnd(1, 12);
let last = rnd(1, 12);
while (
Expand All @@ -84,10 +89,12 @@ function app(type) {
}
let answer = first / last;
questions.push({
q: `${first}÷${last}`,
q: `${first}÷${last}=`,
a: answer,
});
}
} else if (type == "p") {
questions = problemGen();
}
if (typeof humantype == "undefined")
return console.log(
Expand All @@ -112,26 +119,48 @@ function app(type) {
2
);
doc.setFontSize(12);

let top = 3;
let n = 0;
for (let index = 0; index < questions.length; index++) {
const e = questions[index];
doc.text(`Q${index + 1}. ${e.q}=`, 3, index + 3);

if (n % 5 == 0) {
top += 2;
n = 0;
}
doc.text(`Q${index + 1}. ${e.q}`, n * 4 + 1, top);
n++;
}
doc.addPage({ orientation: "p", unit: "cm" });
doc.text("ANSWERS", 3, 3);
let x = 0;
let fromTop = 4;
for (let i = 0; i < questions.length; i++) {
if (x % 5 == 0) {
fromTop += 2;
x = 0;
}
const element = questions[i];
doc.text(`A${i + 1}. ${element.a}`, 3, i + 4);

doc.text(`A${i + 1}. ${element.a}`, x * 3 + 1, fromTop);
x++;
}
doc.save("worksheet.pdf");

console.log(chalk`
{green Successfully generated {magenta ${humantype}} worksheet!}`);
{green Successfully generated {magenta ${humantype}} worksheet! ${__dirname}\\worksheet.pdf}`);
if (type == "p")
console.log(
chalk`{red Hey there! Problem solving questions are expermiental, and may cause issues! Report bugs at {green https://github.com/CoolJim/mathsgen/issues}}`
);
}
function rnd(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function err(e) {
throw e;
return console.log(chalk`
{red Whoops! An error occured. Please refer to the message below for more information}
${e}
`);
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mathsgen",
"version": "1.1.0",
"version": "1.1.1",
"description": "Simple maths worksheet generator built with JavaScript, on NodeJS",
"main": "index.js",
"scripts": {
Expand Down
Binary file added releases/mathsgen-v1.1.1.zip
Binary file not shown.

0 comments on commit deee7fe

Please sign in to comment.