// Thermochemistry - Temperature & Heat Changes JavaScript
thepage="Thermochemistry - Temperature & Heat Changes"
//updated 12/02/02-netscape 7
//refnumber=87
//global variables
attempts=0
tried=0
which=0
theanswer=0
corrt=0
totl=0
option=0
ans=""
function parts(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10){
	this.p1=p1
	this.p2=p2
	this.p3=p3
	this.p4=p4
	this.p5=p5
	this.p6=p6
	this.p7=p7
	this.p8=p8
	this.p9=p9
	this.p10=p10
}
//0=q,1=Tf,2=Ti,3=mass
datalabel=new Array("q ","T<sub>f</sub> ","T<sub>i</sub> ","mass ")
dataunit=new Array(" Joules"," &deg;C"," &deg;C"," grams")
question=new Array()
seqs=new Array()
question[0]=new parts("A sample of water with a mass of "," g undergoes a temperature change from ","&deg;C to "," &deg;C. What is the heat change in Joules?")
seqs[0]=new Array(3,2,1)
question[1]=new parts("A sample of water with a mass of "," g and an initial temperature of "," Joules. What is the final temperature?")
seqs[1]=new Array(3,2,0)
question[2]=new parts("A sample of water with a mass of "," g and an unknown temperature "," Joules. If the final temperature is found to be ", "&deg;C. What was the initial temperature?" )
seqs[2]=new Array(3,0,1)
question[3]=new parts("A sample of water of unknown mass undergoes a temperature change from ","&deg;C to ","&deg;C with a concomitant change in heat content of "," Joules. What is the mass of the water?")
seqs[3]=new Array(2,1,0)
baseequation="q = (4.184J/g&middot;&deg;C) &#215; mass &#215; (Tf - Ti)"
equats=new Array()
ansseq=new Array()
equats[0]=new parts("4.184 &#215; mass &#215; (Ti - Tf) = q","4.184 &#215; "," &#215; ("," - ",") = ")
ansseq[0]=new Array(3,2,1,0)
equats[1]=new parts("-q/(4.184 &#215; mass) + Ti = Tf"," - ","/4.184 &#215; "," + "," = ")
ansseq[1]=new Array(0,3,2,1)
equats[2]=new parts("q/(4.184 &#215; mass) + Tf = Ti","","/4.184 &#215; "," + "," = ")
ansseq[2]=new Array(0,3,1,2)
equats[3]=new parts("q/(4.184 J/g&middot;&deg;C &#215; (Tf - Ti)) = mass","","/(4.184 &#215; ("," - ",")) = ")
ansseq[3]=new Array(0,1,2,3)
function startit(){
	clear()	
	totl++
	document.forms[0].total.value=totl
	document.forms[0].results.value=""
	Ti=0	
	while(Ti<10)Ti=number((100*Math.random()),4,3);
	Tf=Ti;
	while(Tf>Ti-5 & Tf<Ti+5)Tf=number((100*Math.random()),4,3);
	mass=number(1000*Math.random(),4,3)
	q=number((4.184*mass*(Tf-Ti)),4,3)
	thedata=new Array(q,Tf,Ti,mass)
	option=Math.floor(4*Math.random())
	buildquest(thedata,option)
	buildanswer(thedata,option)
}
function buildquest(thedata,option){
	insert=""
	x=thedata[0]
	if(option==1 || option==2)insert=getinsert(option,x)
	if(option!=1)thequest=question[option].p1+thedata[seqs[option][0]]+question[option].p2+insert+Math.abs(thedata[seqs[option][1]])+question[option].p3+thedata[seqs[option][2]]+question[option].p4;
	else thequest=question[option].p1+thedata[seqs[option][0]]+question[option].p2+thedata[seqs[option][1]]+insert+Math.abs(thedata[seqs[option][2]])+question[option].p3;
	showquest(thequest)
	//document.forms[0].theans.value=thedata[option]
}
function getinsert(option,x){
	x>0?insert="&deg;C gains ":insert="&deg;C loses ";
	return insert
}
function buildanswer(thedata,option){
	thetable=gettable(option)
	ans=thedata[option]
	theanswer=""
	theanswer=equats[option].p1+"<br>"+equats[option].p2+thedata[ansseq[option][0]]+equats[option].p3+thedata[ansseq[option][1]]+equats[option].p4+thedata[ansseq[option][2]]+equats[option].p5+thedata[ansseq[option][3]]+dataunit[option]
	theanswer=thetable+theanswer
}
function gettable(option){
	thetable=""
	for(j=0;j<=3;j++){
		thetable+=(datalabel[j]+"=");
		j!=option?thetable+=thedata[j]:thetable+="?";
		thetable+=(dataunit[j]+"<br>");
	}
	return thetable
}		
function answer(x){
	if(tried==1)alert("You've done this one. Get a new problem.")
	else{
	if(tried==2){totl++;document.forms[0].total.value=totl}
	attempts++
	thesum=1
	if(thedata[option]<0){
		if(x<.95*thedata[option] & x>1.05*thedata[option]){thesum=0}
	}
	else{
		if(x>.95*thedata[option] & x<1.05*thedata[option]){thesum=0}
	}
	if(thesum==0){
		document.forms[0].results.value="Correct"
		corrt++
		document.forms[0].correct.value=corrt
		tried=1
	}
	else{
		document.forms[0].results.value="Incorrect"
		tried=2
	}
}}
