64.1 F
Los Angeles
Thursday, October 24, 2024

Trump Lawyer Resigns One Day Before Trial To Begin

Joseph Tacopina has filed with the courts that he will not represent Donald J. Trump. The E. Jean Carroll civil case is schedule to begin Tuesday January 16,...

Judge Lewis A. Kaplan Issues Order RE Postponement

On May 9, 2023, a jury found Donald J. Trump liable for sexual assault and defamation. The jury awarded Ms. Carroll $5 million in damages. Seven months ago,...

ASUS Announces 2023 Vivobook Classic Series

On April 7, 2023, ASUS introduced five new models in the 2023 Vivobook Classic series of laptops. The top laptops in the series use the 13th Gen Intel® Core™...
ScienceChemistryFirst JavaScript From Scratch: Gas Laws

First JavaScript From Scratch: Gas Laws

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” …

Latest news

Related news