//Conversions - Volumes
thepage="Conversions - Volumes"
//11/18/02-update netscape 7
//global variables
refnumber=31
attempts=0
theanswer=""
which=0
svol=0
path=""
second=0
first=0
totl=0
corrt=0
function pairs(name,factor,mp){
	this.name=name
	this.factor=factor
}
volume=new Array()
volume[1]=new pairs("gallons",.25)
volume[2]=new pairs("quarts",1)
volume[3]=new pairs("ounces",32)
volume[4]=new pairs("milliliters",946)
volume[5]=new pairs("liters",.946)
sequence=new Array(0,4,0,32,1000)
link=new Array()
link[1]=" quarts to milliliters "
link[2]=" milliliters to quarts "
function startit(){
	clear()
	totl++
	document.forms[0].total.value=totl
	startvol=0
	while(startvol<1)startvol=Math.round(100*Math.random())/10;
	first=Math.ceil(3*Math.random())
	second=3+Math.ceil(2*Math.random())
	if(Math.random()>.5){
		fvol=startvol*(volume[first].factor)
		fdim=volume[first].name
		svol=startvol*(volume[second].factor)
		sdim=volume[second].name
		key=1
	}
	else{
		svol=startvol*(volume[first].factor)
		sdim=volume[first].name
		fvol=startvol*(volume[second].factor)
		fdim=volume[second].name
		key=2
	}
	fvol=Math.round(100*fvol)/100
	svol=Math.round(100*svol)/100
	thequest="Convert "+fvol+fdim+" to "+sdim
	showquest(thequest)
	answerpath(key)
	buildanswer(key)
}
function answerpath(key){
	if(key==1){
		path=link[1]
		if(first!=2)path=volume[first].name+" to "+path
		if(second!=4)path=path+" to "+volume[second].name
	}	
	else{	
		path=link[2]
		if(second!=4)path=volume[second].name+" to "+path
		if(first!=2)path=path+" to "+volume[first].name
	}
	path="This problem can be solved by following conversion(s):<br><br>"+path+"<br><br>"
}
function buildanswer(key){
	if(key==1){
		if(first==2)theanswer=fvol+"*946";
		else theanswer=fvol+"*"+sequence[first]+"*946";
		if(second==5)theanswer=theanswer+"*1/1000";
	}		
	else{
		if(second==4)theanswer=fvol+"*1/946";
		else theanswer=fvol+"*1/946*1000";
		if(first!=2)theanswer=theanswer+"*1/"+sequence[first];
	}
	theanswer=theanswer+"="+svol	
	theanswer=path+theanswer
}
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*svol & theans<1.05*svol){
		corrt++
		document.forms[0].results.value="Correct"
		document.forms[0].correct.value=corrt
		tried=1
	}
	else{
		document.forms[0].results.value="Incorrect"
		tried=2
	}
	}
}
