Writing short bits of code to calculate partial series sums or to implement simple algorithms is a great extension to A level maths. I had wanted to do this for some time, and hoped that my school would install Python or Sage or some other programming package. Then I realized that I could do the programming perfectly well using three readily available tools: any simple text editor, javascript, and any browser. Javascript is a programming language which provides basic maths functions and constants (such as Math.PI and Math.sin()), and which is used everywhere in web pages. Using fairly simple (and easily modified) html students can create a form which will accept inputted data and also display the result.
Here’s an example of javasript to calculate sin(x):
<script type='text/javascript'>
ans=Math.sin(x);
</script>
However, as it stands, this will not display any output, nor can the value of x be inputted by the user. The following html creates a form for input, and defines a ‘div’ in which output will be displayed.
<html>
<body>
<form name='trig'>
sin<input type='text' name='xforsin' value=''>
<input type='button' value='calculate' onclick='findsin()'>
</form>
<script type='text/javascript'>
function findsin(){
x=document.trig.xforsin.value;
ans=Math.sin(x);
document.getElementById('output').innerHTML='sin('+x+')='+ans;
}
</script>
<div id='output'></div>
</body>
</html>
Although this looks more complicated, the actual calculation is the same. The rest is html to get the input and display the ouput.
The code as it stands above can be pasted into a text editor and saved as sin_calculator.html (or whatever filename is chosen). It’s important to make sure the file has no extra formatting and is saved with the extension ‘html’. This file can then be opened by a browser and used to calculate sin(x)!
My students were quite excited to find themselves writing a working web page in just a few minutes, and some of them have gone on to create their own pages, for example to invert a 2 x 2 matrix.
Once students have tried a program like this, there are many things they could adapt the javascript to do: calculate a series sum, solve a quadratic using the formula, or automate finding a missing angle using the cosine rule, for example.
Excellent tutorials on html and javascript are provided by W3Schools here.

