//Conversions - Density
//updated 11/14/00-added complete solution
//11/18/02-updated netscape7
thepage="Conversions - Density"
//refnumber=33
attempts=0
totl=0
corrt=0
tried=0
dvalues=0
first=second=0
theanswer=""
given=0
shown=0
dunits=new Array("mg/mL","mg/L","g/mL","g/L","kg/mL","kg/L")
massfactor=new Array(.001,1,1000)
volfactor=new Array(1,1000)
dfactor=new Array(1000,1e6,1,1000,1e-3,1)
insert="Recall that for the change in the mass unit, the numeric effect will be the opposite of the dimension change. That is, going to a larger quantity(g => kg) results in a smaller number. For changes in the volume unit, the numeric change is in the same direction as the dimension change."
function startit(){
	totl++
	document.forms[0].total.value=totl
	clear()
	getvalues()
	setproblem()
}
function getvalues(){
	dvalues=new Array()
	dvalues[2]=0
	while(dvalues[2]<.2 || dvalues[2]>5)dvalues[2]=10*Math.random();
	dvalues[3]=dvalues[0]=1000*dvalues[2]
	dvalues[5]=dvalues[2]
	dvalues[1]=dvalues[2] + "e+6"
	dvalues[4]=dvalues[2] + "e-3"
	}
function setproblem(){
	mass1=Math.floor(3*Math.random())
	vol1=Math.floor(2*Math.random())
	mass2=Math.floor(3*Math.random())
	vol2=Math.floor(2*Math.random())
	first=2*mass1+vol1
	second=2*mass2+vol2
	if(first==second)setproblem();
	else{
	given=dvalues[first]
	shown=dvalues[second]
	if(given>.01 & given<100)given=number(given,3,3);
	else given=number(given,3,2)
	if(shown>.01 & shown<100)shown=number(shown,3,3);
	else shown=number(shown,3,2)
	thequest="Convert a density of "+given+dunits[first]+" into a density with dimensions of "+dunits[second]+"?<br>"
	showquest(thequest)
	buildanswer(mass1,mass2,vol1,vol2)
}}
function buildanswer(mass1,mass2,vol1,vol2){
	if(mass1==mass2)mchange=" unchanged ";
	if(mass1<mass2)mchange=" increased ";
	if(mass1>mass2)mchange=" decreased ";
	if(vol1==vol2)vchange=" unchanged. ";
	if(vol1<vol2)vchange=" increased. ";
	if(vol1>vol2)vchange=" decreased. ";
	if(mass1==mass2)mfactor=1;
	else mfactor=massfactor[mass1]/massfactor[mass2];
	if(vol1==vol2)vfactor=1;
	else vfactor=volfactor[vol2]/volfactor[vol1]
	theeqn=given+"*"+mfactor+"*"+vfactor+"="+shown
	theanswer=insert+"<br>In this case, the mass dimension is "+mchange+" and the volume dimension  is "+vchange+"<br>The actual calculation is as follows, with the first multiplier representing the mass change and the second the volume change:<br>"+theeqn
	}
function answer(ans){
	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(ans>.95*dvalues[second] & ans<1.05*dvalues[second]){
		document.forms[0].results.value="Correct"
		corrt++
		document.forms[0].correct.value=corrt
		tried=1
	}
	else{
		document.forms[0].results.value="Incorrect"
		tried=2
	}}
}
