// Acids & Bases - pH and pOH Calculations Script
thepage="pH and pOH Calculations - WP"
//updated 12/02/02-netscape 7
//globals
//refnumber=113
totl=0
corrt=0
tried=0
attempts=0
theanswer=""
missing=0
given=0
//constants
Kw=1e-14
K="1.00 &#215; 10<sup>-14</sup>"
parts=new Array()
aparts=new Array()
labels=new Array()
labels[0]="[H<sup>+</sup>]"
labels[1]="[OH<sup>-</sup>]"
labels[2]="pH"
labels[3]="pOH"
question=new Array("What is the<b> ","</b> if the<b> "," = ","</b>?")
ansphrase=new Array("Since ",", the solution is obtained by the following step(s):<br>")
equations=new Array("-log ","1.00 &#215; 10<sup>-14</sup>/","10<sup>-","14-")
function startit(){
	clear()
	totl++
	document.forms[0].total.value=totl
	power=Math.round(12*Math.random())
	first=1/(Math.random()+"e"+power)
	if(first<1e-13 || first>.09){totl--;startit()}
	else{
	if(Math.random()>.5){parts[0]=first;parts[1]=Kw/parts[0]}
	else {parts[1]=first;parts[0]=Kw/parts[1]};
	parts[2]=-Math.log(parts[0])/2.302;
	parts[3]=-Math.log(parts[1])/2.302;
	parts[2]=aparts[2]=Math.round(100*parts[2])/100
	parts[3]=aparts[3]=Math.round(100*parts[3])/100
	aparts[0]=parts[0]
	aparts[1]=parts[1]
	parts[0]=number(parts[0],3,2);
	parts[1]=number(parts[1],3,2);
	buildquest()
}}
function buildquest(){
	given=Math.floor(4*Math.random());
	missing=given;
	while(missing==given)missing=Math.floor(4*Math.random());
	buildanswer(given,missing)
	thequestion=question[0]+labels[missing]+question[1]+labels[given]+question[2]+parts[given]+question[3]
	showquest(thequestion)
}
function buildanswer(given,missing){
	key=Math.round(1*(""+given+missing))
	if(key>15){
			if(given>1)bridge=given-2;
			else bridge=given+2;
			}
	else{
		if(missing>1)bridge=missing-2;
		else bridge=missing+2;
		}
	if(key==2 || key==13){
				theanswer=ansphrase[0]+equations[0]+labels[given]+" = "+labels[missing]+"<br>";
				theanswer=theanswer+equations[0]+parts[given]+" = <b>"+parts[missing]+"</b>";
				}
	if(key==1 || key==10 ){
				theanswer=ansphrase[0]+equations[1]+labels[given]+" = "+labels[missing]+"<br>";
				theanswer=theanswer+equations[1]+parts[given]+" = <b>"+parts[missing]+"</b>";
				}
	if(key==3 || key==12){
			theanswer=ansphrase[0]+equations[1]+labels[given]+" = "+labels[bridge]+" and<br>";
			theanswer=theanswer+equations[0]+labels[bridge]+" = "+labels[missing]+"<br>";
			theanswer=theanswer+equations[1]+parts[given]+" = "+parts[bridge]+"<br>";
			theanswer=theanswer+equations[0]+parts[bridge]+" = <b>"+parts[missing]+"</b>";				
			}
	if(key==20 || key==31){
			theanswer=ansphrase[0]+equations[2]+labels[given]+"</sup> = "+labels[missing]+"<br>";
			theanswer=theanswer+equations[2]+parts[given]+"</sup> = <b>"+parts[missing]+"</b>";				
			}
	if(key==21 || key==30){
			theanswer=ansphrase[0]+equations[2]+labels[given]+"</sup> = "+labels[bridge]+" and<br>";
			theanswer=theanswer+equations[1]+labels[bridge]+" = "+labels[missing]+"<br>"
			theanswer=theanswer+equations[2]+parts[given]+"</sup> = "+parts[bridge]+"<br>";
			theanswer=theanswer+equations[1]+parts[bridge]+" = <b>"+parts[missing]+"</b>";			
			}
	if(key==23 || key==32){
			theanswer=ansphrase[0]+equations[3]+labels[given]+" = "+labels[missing]+"<br>";
			theanswer=theanswer+equations[3]+parts[given]+" = <b>"+parts[missing]+"</b>";				
			}	
}
	
function answer(theans){
	if(tried==1)alert("You've already done this one! Get a new problem");
	else{
	if(tried==2){totl++;document.forms[0].total.value=totl};
	if(theans>.95*aparts[missing] & theans<1.05*aparts[missing]){
		document.forms[0].results.value="Correct"
		corrt++
		document.forms[0].correct.value=corrt
	}
	else{
		document.forms[0].results.value="Incorrect"
		tried=2
	}	
	}
}
