// JavaScript Document
thepage="Mass and hydrocarbon formulas"
//11/20/02-updated netscape 7
attempts=corrt=totl=tried=0
thesolution=given=0
solved=0
alldata=0
symbols=new Array("nothing","compound mass","C mass","H mass","gfw","C(formula)","H(formula)")
equations=new Array()
eqnset=new Array()
eqnset[0]=new Array(1,4,6,3)
eqnset[1]=new Array(1,4,5,2)
eqnset[2]=new Array(2,5,4,1)
eqnset[3]=new Array(2,5,6,3)
eqnset[4]=new Array(3,6,4,1)
eqnset[5]=new Array(3,6,5,2)
ansset=new Array()
ansset[1]=new Array(2,4)
ansset[2]=new Array(1,5)
ansset[3]=new Array(0,3)
for(var j=0;j<6;j++)equations[j]=symbols[eqnset[j][0]]+" = ("+symbols[eqnset[j][1]]+" &#247; "+symbols[eqnset[j][2]]+") &#215; "+symbols[eqnset[j][3]];
ansphrase=new Array("All of these problems involve using the appropriate mass ratios given by the molecular formula.","To calculate the C and H, given the total mass of compound:<br>","To calculate the total mass and the hydrogen,given the mass of carbon:<br>","To calculate the total mass and the C, given the H:<br>")
//This function clears the first table
function clear(){
	for( var k=0;k<4;k++)document.forms[0].elements[k].value=""
	attempts=0
	tried=0
	clearansspot()
}
compound=new Array()
compound[0]=new Array("CH4",1,4)
compound[1]=new Array("C2H6",2,6)
compound[2]=new Array("C3H8",3,8)
compound[3]=new Array("C4H10",4,10)
compound[4]=new Array("C5H12",5,12)
compound[5]=new Array("C6H14",6,14)
compound[6]=new Array("C7H16",7,16)
compound[7]=new Array("C8H18",8,18)
compound[8]=new Array("C9H20",9,20)
compound[9]=new Array("C10H22",10,22)
compound[10]=new Array("C3H4",3,4)
compound[11]=new Array("C2H4",2,4)
compound[12]=new Array("C3H8",3,6)
compound[13]=new Array("C4H10",4,6)
compound[14]=new Array("C5H8",5,8)
compound[15]=new Array("C6H6",6,6)
compound[16]=new Array("C7H12",7,12)
compound[17]=new Array("C8H16",8,16)
compound[18]=new Array("C9H14",9,14)
compound[19]=new Array("C10H18",10,18)
function startit(){
	clear()
	totl++
	document.forms[0].total.value=totl
	attempts=0
	option=Math.floor(Math.random()*compound.length)
	alldata=new Array()
	alldata[5]=12*compound[option][1]
	alldata[6]=compound[option][2]
	alldata[4]=alldata[6]+alldata[5]
	setproblem(option)
}
function setproblem(option){
	alldata[0]=compound[option][0]
	alldata[1]=0
	while(alldata[1]<3)alldata[1]=20*Math.random()
	alldata[2]=alldata[1]*alldata[5]/alldata[4]
	alldata[3]=alldata[1]*alldata[6]/alldata[4]
	for(var j=1;j<7;j++)alldata[j]=number(alldata[j],3,3)
	given=Math.ceil(3*Math.random())
	document.forms[0].elements[0].value=alldata[0]
	document.forms[0].elements[given].value=alldata[given]
	buildanswer()
	}
function buildanswer(){
	getsolved()
	theanswer=ansphrase[0]+ansphrase[given]+equations[ansset[given][0]]+" &#8594; "+solved[ansset[given][0]]+"<br>"+equations[ansset[given][1]]+" &#8594; "+solved[ansset[given][1]]+"<br>"
	//showanswer()
}
function getsolved(){
	solved=new Array()
	for(var j=0;j<6;j++)solved[j]=" ("+alldata[eqnset[j][1]]+" &#247; "+alldata[eqnset[j][2]]+") &#215; "+alldata[eqnset[j][3]]+" = "+alldata[eqnset[j][0]]+"<b> g</b>";
}
function answer(form){
	if(tried==1)alert("You've done this one. Get a new problem!")
	else{
	score=0
	if(tried==2){totl++;document.forms[0].total.value=totl}
	attempts++
	for(var j=1;j<4;j++){
		if(1*form.elements[j].value>1.05*alldata[j] || 1*form.elements[j].value<.95*alldata[j])score++;
	}
	if (score==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
		}
	}
}
