// JavaScript Document

thepage="Molar Weight by Freezing Point Depression"
//updated 11/18/02-netscape 7
//global variables
attempts=0
which=0
theanswer=0
corrt=0
totl=0
missing=""
thearrow="<b>  &#8594;  </b>"
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
}
data=new Array()
question=new Array()
question[0]=new Array("A solution of "," grams of solute in "," grams of a solvent(<b>K<sub>f</sub> = ",";T<sub>f</sub> = ","&#176;C</B>) is found to have a freezing point of ","&#176;C. What is the solute's molecular weight?")
question[1]=new Array("grams of a solute with a gmw of ","g/mole is dissolved in ","grams of a solvent(<B>K<sub>f</sub> = ",";T<sub>f</sub> = ","&#176;C</B>). What would be the freezing point of the solution?")
question[2]=new Array("A solution of "," grams of solute(<B>gmw=","g/mole</B>) in "," grams of a solvent(<B>T<sub>f</sub> = ","&#176;C</B>) is found to have a freezing point of ","&#176;C. What is the solute's K<sub>f</sub>?")
qlist=new Array()
qlist[0]=new Array(0,3,4,6,7)
qlist[1]=new Array(0,1,3,4,6)
qlist[2]=new Array(0,1,3,6,7)
anslist=new Array(1,7,4)
symbols=new Array("mass(solute)","gfw(solute)","moles(solute)","mass(solvent)","K<sub>f</sub>","m","T<sub>f(solvent)</sub>","T<sub>f(solution)</sub>","&Delta;T<sub>f</sub>")
equations=new Array()
equations[0]=symbols[8]+"="+symbols[4]+"*"+symbols[5]//dT=Kf*m
equations[1]=symbols[2]+"="+symbols[0]+"/"+symbols[1]//moles=mass/gfw
equations[2]=symbols[1]+"="+symbols[0]+"/"+symbols[2]//gmw=mass/moles
equations[3]=symbols[5]+"="+symbols[2]+"/("+symbols[3]+"/1000)"//m=moles/(mass/1000)
equations[4]=symbols[5]+"="+symbols[8]+"/"+symbols[4]//m=dT/Kf "+symbols[4]+"/"+symbols[8]
equations[5]=symbols[2]+"="+symbols[5]+"*("+symbols[3]+"/1000)"//moles=(mass/1000)*m
equations[6]=symbols[4]+"="+symbols[8]+"/"+symbols[5]//Kf=m/dt "+symbols[8]+"/"+symbols[5]
equations[7]=symbols[8]+"="+symbols[6]+"-"+symbols[7]//dt=t1-t2
equations[8]=symbols[7]+"="+symbols[6]+"-"+symbols[8]//t2=t1-dt
ansseq=new Array()
labelseq=new Array(5,2,1,4,4,2,3,5,5)
ansseq[0]=new Array(7,4,5,2)
ansseq[1]=new Array(1,3,0,8)
ansseq[2]=new Array(1,3,6,7) // (1,3,7,6)
dlabels=new Array("g","g/mole","moles","deg/molal","moles/kg","<sup>o</sup>C")
function startit(){
	thequest=""
	clear()
	totl++
	document.forms[0].total.value=totl
	kf=gmw=tf1=tf2=mass1=mass2=0
	while(kf<1)kf=number(10*Math.random(),3,3);
	while(tf1<40)tf1=number(100*Math.random(),3,3);
	while(gmw<80)gmw=number(200*Math.random(),3,3);
	while(mass1<2)mass1=number(10*Math.random(),3,3);
	while(mass2<50)mass2=number(100*Math.random(),3,3);
	moles=number(mass1/gmw,3,3)
	m=number(moles/(mass2/1000),3,3)
	dtf=kf*m
	if(dtf<1){totl--;startit()}
	else{
	dtf<10?dtf=number(dtf,2,3):dtf=number(dtf,3,3)
	tf2=number(tf1-dtf,3,3)
	alldata=new Array(mass1,gmw,moles,mass2,kf,m,tf1,tf2,dtf)
	buildquest()
	}
}
function buildquest(){
	which=Math.floor(3*Math.random())
	if(which==0 || which==2){
		for(j=0;j<5;j++)thequest+=(question[which][j]+alldata[qlist[which][j]]);
		thequest+=question[which][5];
	}
	if(which==1){
		for(j=0;j<5;j++)thequest+=(alldata[qlist[1][j]]+question[1][j]);
	}	
	showquest(thequest);
	//document.forms[0].theans.value=alldata[anslist[which]]
	buildanswer()
}
function buildanswer(data,choose,missing){
	getsolved()
	theanswer="This problem is solved by the following sequence of steps:<br>"
	for(j=0;j<ansseq[which].length;j++){
		theanswer+=(equations[ansseq[which][j]]+thearrow+solved[ansseq[which][j]]+"<b>"+dlabels[labelseq[ansseq[which][j]]]+"</b><br>")
	}
	//showanswer()
	}

function getsolved(which){
	solved=new Array()
	solved[0]=alldata[4]+"*"+alldata[5]+"="+alldata[8]//Kf*m=dT
	solved[1]=alldata[0]+"/"+alldata[1]+"="+alldata[2]//mass/gfw=moles
	solved[2]=alldata[0]+"/"+alldata[2]+"="+alldata[1]//mass/moles=gmw
	solved[3]=alldata[2]+"/("+alldata[3]+"/1000)"+"="+alldata[5]//moles/(mass/1000)=m
	solved[4]=alldata[8]+"/"+alldata[4]+"="+alldata[5]//dT/Kf=m 
	solved[5]=alldata[5]+"*("+alldata[3]+"/1000)"+"="+alldata[2]//(mass/1000)*m=moles
	solved[6]=alldata[8]+"/"+alldata[5]+"="+alldata[4]//dT/m=Kf
	solved[7]=alldata[6]+"-"+alldata[7]+"="+alldata[8]//t1-t2=dt
	solved[8]=alldata[6]+"-"+alldata[8]+"="+alldata[7]//t1-dt=t2
	}
function answer(theans){
	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++
	if(theans>.95*alldata[anslist[which]] && theans<1.05*alldata[anslist[which]]){
		document.forms[0].results.value="Correct"
		corrt++
		document.forms[0].correct.value=corrt
		tried=1
	}
	else{
		document.forms[0].results.value="Incorrect"
		tried=2
	}
}}

