function randomERProblem(form) { 	var theP1 = Math.round(Math.random()*6+2);  	var theP2 = Math.round(Math.random()*6+2); 	var theP3 = Math.round(Math.random()*(17-theP1-theP2)+1);  	var theP4 = 20 - theP1 - theP2 - theP3; 	var theP1 = Math.round(theP1*5); 	var theP2 = Math.round(theP2*5); 	var theP3 = Math.round(theP3*5); 	var theP4 = Math.round(theP4*5); 	var theR1 = Math.round(Math.random()*80-30); 	var theR2 = Math.round(Math.random()*80-30); 	var theR3 = Math.round(Math.random()*80-30); 	var theR4 = Math.round(Math.random()*80-30); 	if ((theR1 < 0) && (theR2 < 0) && (theR3 < 0) && (theR4 < 0)) { 		theR2 = Math.round(theR2*(-1)); 		theR4 = Math.round(theR4*(-1)); 	}  	form.p1.value="" + theP1; 	form.p2.value="" + theP2; 	form.p3.value="" + theP3; 	form.p4.value="" + theP4; 	form.r1.value="" + theR1; 	form.r2.value="" + theR2; 	form.r3.value="" + theR3; 	form.r4.value="" + theR4; 	form.er.value=""; 	form.va.value=""; 	form.sd.value=""; }  function findER(form) { 	var theP1Str = form.p1.value; 	if (!isPositiveNumber(theP1Str)) { 		return false; 	} 	var theP2Str = form.p2.value; 	if (!isPositiveNumber(theP2Str)) { 		return false; 	} 	var theP3Str = form.p3.value; 	if (!isPositiveNumber(theP3Str)) { 		return false; 	} 	var theP4Str = form.p4.value; 	if (!isPositiveNumber(theP4Str)) { 		return false; 	} 	var theR1Str = form.r1.value; 	if (!isNumber(theR1Str)) { 		return false; 	} 	var theR2Str = form.r2.value; 	if (!isNumber(theR2Str)) { 		return false; 	} 	var theR3Str = form.r3.value; 	if (!isNumber(theR3Str)) { 		return false; 	} 	var theR4Str = form.r4.value; 	if (!isNumber(theR4Str)) { 		return false; 	} 	var theP1 = parseFloat(theP1Str); 	var theP2 = parseFloat(theP2Str); 	var theP3 = parseFloat(theP3Str); 	var theP4 = parseFloat(theP4Str); 	var theR1 = parseFloat(theR1Str); 	var theR2 = parseFloat(theR2Str); 	var theR3 = parseFloat(theR3Str); 	var theR4 = parseFloat(theR4Str); 	if ((theP1 + theP2 + theP3 + theP4) != 100) { 		alert("The sum of the probabilities must equal 100\%"); 		return true; 	} 	var theER = (theP1*theR1 + theP2*theR2 + theP3*theR3 + theP4*theR4)/100; 	var theVAR = (theP1/100)*((theR1/100)-(theER/100))*((theR1/100)-(theER/100)); 	theVAR += (theP2/100)*((theR2/100)-(theER/100))*((theR2/100)-(theER/100)); 	theVAR += (theP3/100)*((theR3/100)-(theER/100))*((theR3/100)-(theER/100)); 	theVAR += (theP4/100)*((theR4/100)-(theER/100))*((theR4/100)-(theER/100)); 	var theSD = Math.sqrt(theVAR); 	form.er.value = "" + Math.round(theER*100)/100; 	form.va.value = "" + Math.round(theVAR*10000)/10000; 	form.sd.value = "" + Math.round(theSD*10000)/100; 	return true; }  function helpER(form) { 	var theP1Str = form.p1.value; 	if (!isPositiveNumber(theP1Str)) { 		return false; 	} 	var theP2Str = form.p2.value; 	if (!isPositiveNumber(theP2Str)) { 		return false; 	} 	var theP3Str = form.p3.value; 	if (!isPositiveNumber(theP3Str)) { 		return false; 	} 	var theP4Str = form.p4.value; 	if (!isPositiveNumber(theP4Str)) { 		return false; 	} 	var theR1Str = form.r1.value; 	if (!isNumber(theR1Str)) { 		return false; 	} 	var theR2Str = form.r2.value; 	if (!isNumber(theR2Str)) { 		return false; 	} 	var theR3Str = form.r3.value; 	if (!isNumber(theR3Str)) { 		return false; 	} 	var theR4Str = form.r4.value; 	if (!isNumber(theR4Str)) { 		return false; 	} 	var theP1 = parseFloat(theP1Str); 	var theP2 = parseFloat(theP2Str); 	var theP3 = parseFloat(theP3Str); 	var theP4 = parseFloat(theP4Str); 	var theR1 = parseFloat(theR1Str); 	var theR2 = parseFloat(theR2Str); 	var theR3 = parseFloat(theR3Str); 	var theR4 = parseFloat(theR4Str); 	if ((theP1 + theP2 + theP3 + theP4) != 100) { 		alert("The sum of the probabilities must equal 100\%"); 		return true; 	} 	var theER = (theP1*theR1 + theP2*theR2 + theP3*theR3 + theP4*theR4)/100; 	var theVAR = (theP1/100)*((theR1/100)-(theER/100))*((theR1/100)-(theER/100)); 	theVAR += (theP2/100)*((theR2/100)-(theER/100))*((theR2/100)-(theER/100)); 	theVAR += (theP3/100)*((theR3/100)-(theER/100))*((theR3/100)-(theER/100)); 	theVAR += (theP4/100)*((theR4/100)-(theER/100))*((theR4/100)-(theER/100)); 	var theSD = Math.sqrt(theVAR); 	theVAR = "" + Math.round(theVAR*10000)/10000; 	var theSDDec = "" + Math.round(theSD*10000)/10000; 	theSD = "" + Math.round(theSD*10000)/100; 	theER = "" + Math.round(theER*100)/100; 	var theOut = "<html><head><title>Measures of Risk Help</title></head><body bgcolor='white'>"; 	theOut += "<h3>Measures of Risk Help</h3>"; 	theOut += "<p>The Expected Return can be calculated as follows:</p>"; 	theOut += "<p>E[R] = (" +  Math.round(theP1)/100 + ")(" + Math.round(theR1*100)/100 + "\%) + "; 	theOut += "(" +  Math.round(theP2)/100 + ")(" + Math.round(theR2*100)/100 + "\%) + "; 	theOut += "(" +  Math.round(theP3)/100 + ")(" + Math.round(theR3*100)/100 + "\%) + "; 	theOut += "(" +  Math.round(theP4)/100 + ")(" + Math.round(theR4*100)/100 + "\%) = " + theER + "\%</p>"; 	theOut += "<p><b>The Expected Return = " + theER + "\%</b></p>"; 	theOut += "<p>The Variance can be calculated as follows:</p>"; 	theOut += "<p>Variance = (" +  Math.round(theP1)/100 + ")(" + Math.round(theR1)/100 + " - " + Math.round(theER)/100 + ")<sup>2</sup> + "; 	theOut += "(" +  Math.round(theP2)/100 + ")(" + Math.round(theR2)/100 + " - " + Math.round(theER)/100 + ")<sup>2</sup> + "; 	theOut += "(" +  Math.round(theP3)/100 + ")(" + Math.round(theR3)/100 + " - " + Math.round(theER)/100 + ")<sup>2</sup> + "; 	theOut += "(" +  Math.round(theP4)/100 + ")(" + Math.round(theR4)/100 + " - " + Math.round(theER)/100 + ")<sup>2</sup> = " + theVAR; 	theOut += "<p><b>The Variance = " + theVAR + "</b></p>"; 	theOut += "<p>The Standard Deviation equals the square root of the variance:</p>"; 	theOut += "<p><b>The Standard Deviation = " + theSDDec + " = " + theSD + "\%</b></p>"; 	theOut += "<CENTER>";	theOut += "<P><FORM NAME=\"Form1\">";	theOut += "<INPUT TYPE=\"button\" VALUE=\"   OK   \" onClick=\"window.close();\"></FORM></P></CENTER>"; 	theOut += "</body></html>"; 	var newWin = window.open("","","scrollbars,resizable,width=540,height=340"); 	if (newWin != null) { 		newWin.document.write(theOut); 		newWin.document.close(); 		newWin.focus(); 	} 	return true; }  function isPositiveNumber(inputStr) { 	for (var i = 0; i < inputStr.length; i++) { 		var oneChar = inputStr.substring(i,i+1); 		if (((oneChar >= "0") && (oneChar <= "9")) || (oneChar == ".")) { 		 		} else { 			alert("Please make sure that only numbers are input."); 			return false; 		}  	}	return true; }  function isNumber(inputStr) { 	var oneChar = inputStr.substring(0,1); 	if (!((oneChar == '-') || ((oneChar >= "0") && (oneChar <= "9")) || (oneChar == "."))) { 		alert("Please make sure that only numbers are input."); 		return false; 	} 	for (var i = 1; i < inputStr.length; i++) { 		oneChar = inputStr.substring(i,i+1); 		if (((oneChar >= "0") && (oneChar <= "9")) || (oneChar == ".")) { 		 		} else { 			alert("Please make sure that only numbers are input."); 			return false; 		}  	}	return true; }
