// JavaScript Document
//updated 11/14/00-added complete solution
thepage="Significant Figures"
//updated 12/02/02-netscape 7
attempts=0
theanswer=""
totl=0
corrt=0
answered=0
tried=0
numbers=new Array()
thenumber=0
howlong=0
zeros=0
function parts(p1,p2,p3,p4,p5,p6){
	this.p1=p1
	this.p2=p2
	this.p3=p3
	this.p4=p4
	this.p5=p5
	this.p6=p6
}
ansphrase=new Array()
ansphrase[1]=new parts("The number presented is an integer. In this case, the number of signficant figures is determined by counting from the left until you reach the last non-zero value. 'Trailing' zeros (those to the right of the last non-zero digit) are not significant. Thus,<b> ","</b> has <b>","</b> significant figures.")
ansphrase[3]=new parts("This is a real number containing a decimal point. To determine the number of significant figures, count from the right to the last non-zero value. 'Leading zeros'( those to the left of the last non-zero digit are not significant.Thus,<b> ","</b> has <b>","</b> significant figures.")
ansphrase[2]=new parts("This number is presented in scientific notation. The number of significant figures is determined solely by the coefficient, using the rule for real numbers. To determine the number of significant figures, count from the rightmost position in the coefficient to the last non-zero value. Thus,<b> ","</b> has <b>","</b> significant figures.")
ansphrase[4]=ansphrase[3]
//This is the function started when "New Problem" is pushed	
//This function first clears all old values.
//The coefficient is then generated using Math.random(). 
function startit(){
	clear()
	totl++
	document.forms[0].total.value=totl
	thenumber=""
	choice=Math.ceil(4*Math.random())
	if(choice==1)thenumber=getinteger();
	if(choice>2)thenumber=getreal();
	if(choice==2)thenumber=getscinot();
	buildquest()
	buildanswer(choice)
	document.forms[0].theans.focus()
	document.forms[0].theans.select()
}
function getinteger(){
	howlong=Math.ceil(5*Math.random())
	for(j=1;j<=howlong;j++)thenumber+=Math.ceil(9*Math.random());
	ans=howlong
	return addzeros(thenumber)
}
function getreal(){
	if(Math.random()<.5){
		thenumber="0."
		thenumber=addzeros(thenumber)
		howlong=Math.ceil(5*Math.random())
		for(j=1;j<=howlong;j++)thenumber+=Math.ceil(9*Math.random());
		thenumber=addzeros(thenumber)
		ans=howlong+zeros
		return thenumber
	}
	else{
		howlong=Math.ceil(3*Math.random())
		for(j=1;j<=howlong;j++)thenumber+=Math.ceil(9*Math.random());
		thenumber+="."
		howlong=Math.ceil(3*Math.random())
		for(j=1;j<=howlong;j++)thenumber+=Math.ceil(9*Math.random());
		thenumber=addzeros(thenumber)
		key=""+thenumber
		ans=key.length-1
		return thenumber
	}
}
function getscinot(){
	thenumber=Math.ceil(9*Math.random())+"."
	for(j=1;j<=(Math.floor(4*Math.random()));j++)thenumber+=Math.ceil(9*Math.random());
	thenumber=addzeros(thenumber)
	key=""+thenumber
	ans=key.length-1
	if(Math.random()>.5)sign="+";
		else sign="-";
	exponent=Math.ceil(10*Math.random())
	return (thenumber+"*10<sup>"+sign+exponent+"</sup>")
}
function addzeros(thenumber){
		zeros=Math.ceil(3*Math.random())
		for(j=1;j<=zeros;j++)thenumber+="0"
		return thenumber
}
function buildquest(){
	thequest="Determine the number of signficant figures in "+thenumber
	showquest(thequest)
}
function buildanswer(choice){
	theanswer=ansphrase[choice].p1+thenumber+ansphrase[choice].p2+ans+ansphrase[choice].p3
}
	
// This is the "Check Answer Function
function answer(val){	
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;}
	attempts++
	if (val==ans){
	tried=1
	document.forms[0].results.value="correct"
	corrt++
	document.forms[0].correct.value=corrt}
	else 	{document.forms[0].results.value="incorrect"
		tried=2
		}
	}
}