// Equilibrium/Thermochemistry - Gibbs Free Energy, Entropy, and Heat Change Script
thepage="Equilibrium/Thermochemistry - Gibbs Free Energy, Entropy, and Heat Change"
//updated 11/14/00-added complete solution
//global variables
//refnumber=114
theanswer=""
attempts=0
tried=0
anrs=0
corrt=0
totl=0
theanswer=""
thdata=0
numstring="r0123456789"
ansset=new Array()
compound=new Array()
compound[0]=new Array("CHCl3",-63.6,17.62)
compound[1]=new Array("HCN",-13.4,74.38)
compound[2]=new Array("CH3NH2",-93.4,47.20)
compound[3]=new Array("C2H6",-183.3,22.73)
compound[4]=new Array("C2H5OH",-114.5,26.05)
compound[5]=new Array("C2H3Br",-139.5,11.44)
compound[6]=new Array("C3H7OH",-126.1,20.66)
compound[7]=new Array("C4H9Br",-112.7,12.01)
compound[8]=new Array("C6H5NH2",-6.3,27.09)
compound[9]=new Array("C7H6O2",122.4,33.89)
compound[10]=new Array("C7H16",-90.6,33.78)
compound[11]=new Array("C8H8Cl2",55,29.03)
compound[12]=new Array("C8H8Cl2",34,26.64)
compound[13]=new Array("C8H8Cl2",100,32.73)
compound[14]=new Array("C6H4N2O2",116.9,32.25)
compound[15]=new Array("C6H4N2O2",89.7,24.7)
compound[16]=new Array("C6H4N2O2",173.5,39.99)
compound[17]=new Array("C6H5NO3",113.8,41.7)
compound[18]=new Array("C6H5NO3",45.13,26.76)
compound[19]=new Array("C2H6S",-98.3,30.73)
compound[20]=new Array("C2H6S",-121,23.32)
compound[21]=new Array("CCl4",-23,5.09)
compound[22]=new Array("CS2",-111.5,13.8)
compound[23]=new Array("C2H4Br2",9.93,13.79)
compound[24]=new Array("C5H8",-135.1,11.8)
compound[25]=new Array("C5H8",-145.9,16.8)
compound[26]=new Array("C5H8",-148.8,21.55)
compound[27]=new Array("C6H5Cl",-45.2,20.4)
compound[28]=new Array("C6H5Br",-30.6,16.17)
compound[29]=new Array("C3H4O2",12.3,37.03)
compound[30]=new Array("C3H8O3",18.2,47.95)
question=new Array()
question[0]=new Array(" has a heat of fusion of ","KJ/mole and a melting point of ","&#186;C. What is its entropy of fusion in Joules?")
question[1]=new Array("A reaction has "," at ","K. What is the ","")
keys=new Array(" standard free energy change "," equilibrium constant ")
theeqns=new Array("&#916;S = &#916;H/T","K = e<sup>-&#916;G/RT</sup>","&#916;G = -RTlnK")
function startit(){
	clear()
	thedata=new Array()
	totl++
	document.forms[0].total.value=totl
	Math.random()>.5?enthalpy():GandK()
	}
function enthalpy(){
	type=0
	choice=Math.floor(Math.random()*compound.length)
	//choice=3
	thedata[0]=formula(choice)
	for(var j=1;j<3;j++)thedata[j]=compound[choice][j];
	thedata[2]=number(thedata[2]*4.184,3,3) 
	thedata[3]=1000*thedata[2]/(273+1*thedata[1])
	thequest=thedata[0]+question[0][0]+thedata[2]+question[0][1]+thedata[1]+question[0][2]
	ansr=3
	showquest(thequest)
	buildanswer(type)
}
function GandK(){
	thedata[0]=Math.random()*200
	thedata[0]=number(thedata[0],3,3)
	Math.random()>.5?thedata[0]=-1*thedata[0]:"";
	thedata[1]=0
	while(thedata[1]<273)thedata[1]=500*Math.random();
	thedata[1]=number(thedata[1],3,3)
	thedata[2]=Math.pow(2.718,(-1000*thedata[0]/(8.314*thedata[1])))
	thedata[2]=number(thedata[2],3,1)
	if(Math.random()<.5){
		type=1
		thequest=question[1][0]+" a "+keys[0]+" of "+thedata[0]+" KJ/mole "+question[1][1]+thedata[1]+question[1][2]+keys[1]+question[1][3]+"?"
	ansr=2
	}
	else{
		type=2
		thequest=question[1][0]+" an "+keys[1]+" of "+number(thedata[2],3,2)+question[1][1]+thedata[1]+question[1][2]+keys[0]+question[1][3]+" in KJ/mole?"
	ansr=0
	}
	showquest(thequest)
	buildanswer(type)
}
function formula(choice){
	thestring=compound[choice][0]
	theformula=""
	for(var j=0;j<thestring.length;j++){
		numstring.indexOf(thestring.charAt(j))>0?theformula+="<sub>"+thestring.charAt(j)+"</sub>":theformula+=thestring.charAt(j);
	}
	return theformula
}
function buildanswer(type){
	theanswer="This problem requires use of the relationship:<br>"+theeqns[type]+"<br>"
	if(type==0)theanswer+="&#916;S = "+thedata[2]+"/"+number((1*thedata[1]+273),3,3)+" = "+number(thedata[3]/1000,3,3)+"KJ = "+number(thedata[3],3,3)+"Joules";
	if(type==1)theanswer+="K = e<sup>-"+thedata[0]+"/(.008314 &#215; "+thedata[1]+")</sup> = "+thedata[2];
	if(type==2)theanswer+=" &#916;G = -0.008314 &#215; "+(1*thedata[1])+" &#215; "+number(Math.log(thedata[2]),3,3)+" = "+thedata[0];
	//showanswer()
}

function answer(ans){
	right=0
	if(tried==1)alert("You've done this one. Get a new problem.");
	else{
	attempts++
	if(tried==2){totl++
		document.forms[0].total.value=totl
		}
	if(thedata[ansr]<0){
		if(ans<.95*thedata[ansr] & ans>1.05*thedata[ansr] )right=1;
	}
	else{
		if(ans>.95*thedata[ansr] & ans<1.05*thedata[ansr])right=1;
	}
	if(right==1){
		document.forms[0].results.value="correct"
    		corrt++
		document.forms[0].correct.value=corrt
		tried=1
	}
	else{
		document.forms[0].results.value="incorrect"
		tried=2
	}
}}
