Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: Creating math sheet generator

1. ## Creating math sheet generator

I have been asked by a friend to create a math sheet generator for their child, however i don't have a clue where to start with javascript.

Similar to this..
http://cemc2.math.uwaterloo.ca/mathf...sheetgen.shtml

It doesn't need to be advanced as that as all i'm looking for is how to create the sums.

If someone could help either by informing me where to start or even an online tutorial i would be extremely greatful!

Many thanks,
James

• ## Consider this ...

You can play with this to create different difficulty problem sets.
Area to vary is the 'xvals' and 'yvals' array set-up. Lots of freedom to change this to your liking.

Remove the drop down options list if you only want addition problems.
If you come up with additional improvement beyond simplistic display, post back here for other to see.

Code:
```<html>
<title>Math WorkSheet</title>
<script type="text/javascript">

var NProblems = 25;
var xvals = [];
var yvals = [];
for (var i=0; i<NProblems; i++) {
//  xvals.push(i);    yvals.push(i+1);  		// limit to problem values to (0,1) ... 25
xvals.push(i % 10);    yvals.push((i % 10)+1);  	// limit to single digit problems
}

function MakeTable(act) {
var tmp = '';
var str = '<table border="1" width="80%"><tr>';
i = 0;
while (i < NProblems) {
x = xvals[i];
y = yvals[i];
str += '<td align="right">'+x;
if (act == 'add') { str += '<br>+ '+y; tmp = x+y; }
if (act == 'sub') { str += '<br>- '+y; tmp = x-y; }
if (act == 'mul') { str += '<br>* '+y; tmp = x*y; }
if (act == 'div') { str += '<br>/ '+y; tmp = (x/y).toFixed(2); }
str += '<br>_____';
if (document.getElementById('answers').checked) { str += '<br>'+tmp; }
else { str += '<br>&nbsp;' }
str += '<br>&nbsp;</td>';
i++;
if ((i % 5) == 0) { str += '</tr><tr>'; }
}
str += '</tr></table>';
return str;
}

function GenerateWS() {
var x = 0;  var y = 0;  var str = '';
var str = '';
var sel = document.getElementById('MathAction').value;
switch (sel) {
case 'add' : str += MakeTable(sel); break;
case 'sub' : str += MakeTable(sel); break;
case 'mul' : str += MakeTable(sel); break;
case 'div' : str += MakeTable(sel); break;
default : alert('No choice selected'); break;
}
document.getElementById('TBL').innerHTML = str;
}
function randOrd() {
return (Math.round(Math.random())-0.5);
}
function NewSet() {
xvals.sort(randOrd);
yvals.sort(randOrd);
}

</script>
<body>
<select id="MathAction">
<option value="sub">Subtraction</option>
<option value="mul">Multiplication</option>
<option value="div">Division</option>
</select>
<button onclick="NewSet()">New worksheet</button>
<button onclick="GenerateWS()">Generate Worksheet</button>
<div id="TBL"></div>
</body>
</html>```
Good Luck!

• Thats bang on the money mate thank you very much! Would it be possible to generate the actual worksheet on a different page or would that be more hassle than it's worth?

Thanks again!

• ## Sure ...

Originally Posted by JamesSmith75
Thats bang on the money mate thank you very much! Would it be possible to generate the actual worksheet on a different page or would that be more hassle than it's worth?

Thanks again!
Sure ... no problem with display.

Save the program with a different name with this one line change:
Code:
```<button onclick="NewSet()">New worksheet</button>
<button onclick="GenerateWS()">Generate Worksheet</button>```
Minor problem with generation in that because of the random effect,
you might not get the same worksheet witht the same answers.
Would take a little more coding to save answers for a particular worksheet somewhere.

Anyway, you're most welcome. Happy to help!
Good Luck and have fun with it.

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•