This isn’t much to look at if you are experienced with writing JavaScript, but I’ve always wanted to write something from scratch. Here is my first attempt at calculating the temperature of a gas when pressure, volume and moles are known.
[code] <script type="text/javascript"><!–
var p=prompt("What is the pressure of the gas? units are atmospheres");
var v=prompt("What is the volume of the gas? units are liters");
var n=prompt("What are the number of moles of the gas?");
var R=(0.0821);
var result=Math.round((p*v)/(n*R));
document.write("Pressure is "+p+" atmospheres");
document.write("<br />");
document.write("Volume is "+v+" liters");
document.write("<br />");
document.write("Moles are "+n+" moles");
document.write("<hr />");
document.write("Temperature of the gas is equal to ");
document.write(result);
document.write(" K");
//–>
</script>
[/code]
Math.round was the tricky part. I’ve tested this on a few gas law problems and it seems to return the correct answer.
Note: I suppose the last three document.write lines could be combined as “Temperature of the gas is equal to “+result+” K” …