<html>
<head>
<title>Quadratic Equations ... Something Is Missing</title>
<script>
var xt = 0;
var toggle = 1;
var iurl = "";
var stuff = "";
var n1 = 0.0;
var n2 = 0.0;
var n3 = 0.0;
var n4 = 0.0;
var o12 = "";
var o23 = "";
var o34 = "";
var s1 = 0;
var s2 = 0;
var r1 = 0;
var r2 = 0;
function init() {
if (window.location.search.indexOf("n1") != (0 - 1)) {
var myprmstr = window.location.search.substr(1);
var myprmarr = myprmstr.split ("&");
var myparams = {};
var eis = "";
for ( var i = 0; i < myprmarr.length; i++) {
var mytmparr = myprmarr[i].split("=");
myparams[mytmparr[0]] = mytmparr[1];
eis = mytmparr[0] + " = ";
eis = eis + mytmparr[1];
//alert(eis);
//eval(eis);
document.getElementById(mytmparr[0]).value = mytmparr[1];
}
//alert(stuff);
document.forms[0].onsubmit = function() { return examine_answer(); }
} else {
document.forms[0].onsubmit = function() { return examine_answer(); }
}
default_fill();
}
function default_fill() {
if (stuff != "") {
var qwt=document.getElementById('ifrm');
qwt.style.display = 'block';
qwt.innerHTML = '<iframe src="' + iurl + '" id="ifrmqe" style="display:block;width:100%;height:520px;"></iframe>';
alert("Okay?");
stuff = "";
}
var sgrand, crand = "", tn="", sis="+";
var i=0, j=0, mrand=0, srand=0, nrand=0, frand=0, xrand=0, factor=1.0;
var hm = document.getElementById("hm").value;
var difficulty = document.getElementById("difficulty").value;
var thingtotest = ""; //"((" + n1 + ")" + o12 + "(" + n2 + ")" + o23 + "(" + n3 + "))";
for (j=1; j<=hm; j++) {
if (j == 2) {
document.getElementById('hm').style.backgroundColor = "lightblue";
} else if (j == 3) {
document.getElementById('hm').style.backgroundColor = "lightgreen";
} else if (j == 4) {
document.getElementById('hm').style.backgroundColor = "green";
} else if (j == 5) {
document.getElementById('hm').style.backgroundColor = "purple";
} else if (j == 6) {
document.getElementById('hm').style.backgroundColor = "red";
}
mrand = Math.floor((Math.random()*4)+1);
while (crand.indexOf(";" + mrand + ";") != -1) {
mrand = Math.floor((Math.random()*4)+1);
}
crand = crand + ";" + mrand + ";";
}
//alert(crand);
var isok = "n";
var fone = 1;
var fg = 0;
var m_1=-1;
while (isok != "y") {
sis1 = "x²";
sis2 = "x";
sis3 = "";
xrand = -1;
factor = 1.0;
fone = 1;
m_1 = -1;
for (j=1; j<=6; j++) {
tn = "";
//if (crand.indexOf(";" + j + ";") == -1) {
if (difficulty.indexOf("Easy") != -1) {
if (difficulty.indexOf("Super") != -1) {
srand = 0;
factor = 0.0;
if (fone == 1 && j == 1) {
mrand = 1;
fone = 2;
} else if (fone == 2 && j == 3) {
mrand = Math.floor((Math.random()*30)+5);
//alert("mrand=" + mrand + " " + j);
fg = Math.floor((Math.random()*(mrand - 2))+1);
if (Math.floor((Math.random()*4)+1) == 4 && fg >= 2 && fg <= (mrand / 2)) {
fg = eval((0)-(fg));
m_1 = 1;
fone = eval(((mrand) - (fg))*(fg)*(m_1));
} else {
//alert("fg=" + fg + " " + j);
fone = eval(((mrand) - (fg))*(fg)*(m_1));
}
//alert("fone=" + fone + " " + j);
if (Math.floor((Math.random()*2)+1) == 2 && m_1 == -1) {
mrand = eval((0)-(mrand));
}
} else if (fone < 0 && j == 5) {
if (m_1 == 1) {
mrand = fone;
} else {
mrand = eval((0)-(fone));
}
fone = 10;
} else {
mrand = Math.floor((Math.random()*10)+0);
}
if (xrand < 0) xrand = 1;
} else {
mrand = Math.floor((Math.random()*100)+0);
if (xrand < 0) xrand = Math.floor((Math.random()*1)+1);
}
if (xrand == 2) {
sis1 = "";
sis2 = "/x";
sis3 = "/x²";
}
tn = mrand;
} else {
document.getElementById('difficulty').style.backgroundColor = "orange";
srand = Math.floor((Math.random()*2)+1);
mrand = Math.floor((Math.random()*1000)+0);
frand = Math.floor((Math.random()*100)+0);
if (xrand < 0) xrand = Math.floor((Math.random()*2)+1);
if (xrand == 2) {
sis1 = "";
sis2 = "/x";
sis3 = "/x²";
}
if (srand <= 1) {
tn = "" + mrand;
} else {
tn = "-" + mrand;
}
if (frand != 0) tn = tn + "." + frand;
}
//}
//alert(tn + " " + sis);
document.getElementById('o12').value = sis1;
document.getElementById('o23').value = sis2;
document.getElementById('o34').value = sis3;
switch(j)
{
case 1:
n1 = tn;
thingtotest = "((" + tn + ")";
if (crand.indexOf(";" + j + ";") == -1) {
document.getElementById('n1').value = tn;
} else {
document.getElementById('n1').value = "";
document.getElementById('n1').style.backgroundColor = "lightgray";
}
break;
case 3:
n2 = tn;
thingtotest = thingtotest + "(" + tn + ")";
if (crand.indexOf(";" + j + ";") == -1) {
document.getElementById('n2').value = tn;
} else {
document.getElementById('n2').value = "";
document.getElementById('n2').style.backgroundColor = "lightgray";
}
break;
case 5:
thingtotest = thingtotest + "(" + tn + "))";
n3 = tn;
if (crand.indexOf(";" + j + ";") == -1) {
document.getElementById('n3').value = tn;
} else {
document.getElementById('n3').value = "";
document.getElementById('n3').style.backgroundColor = "lightgray";
}
break;
case 6:
if (factor < 0.5) {
n4 = factor;
} else {
n4 = eval(thingtotest);
}
if (crand.indexOf(";" + j + ";") == -1) {
//alert(thingtotest);
if (factor < 0.5) {
document.getElementById('n4').value = n4;
} else {
document.getElementById('n4').value = eval(thingtotest);
}
} else {
document.getElementById('n4').value = "";
document.getElementById('n4').style.backgroundColor = "lightgray";
}
break;
default:
sgrand = Math.floor((Math.random()*2)+1)
if (sgrand == 1) {
thingtotest = thingtotest + "+";
} else {
thingtotest = thingtotest + "-";
}
break;
}
}
o12 = document.getElementById("o12").value;
o23 = document.getElementById("o23").value;
o34 = document.getElementById("o34").value;
if (n4 != 0 && o34 == "") {
n3 -= n4;
n4 = 0;
} else if (n4 != 0) {
n1 -= n4;
n4 = 0;
}
if (o34 == "") {
n4 = n2 * n2 - (4.0 * n1 * n3);
if (n4 >= 0.0 && n1 != 0) isok = "y";
} else {
n4 = n2 * n2 - (4.0 * n1 * n3);
if (n4 >= 0.0 && n3 != 0) isok = "y";
}
}
document.getElementById('r1').value = "";
document.getElementById('r2').value = "";
}
function modechange(huh) {
if (xt == 0) {
xt = 1;
if (huh.value == document.getElementById("o23").value) {
//toggle = 1 - toggle;
if (huh.value == "/x") {
document.getElementById("o12").value = "";
document.getElementById("o34").selectedIndex = 1; //.value = "/x²";
} else {
document.getElementById("o12").selectedIndex = 0; //.value = "x²";
document.getElementById("o34").value = "";
}
} else if (huh.value == document.getElementById("o34").value) {
//toggle = 1 - toggle;
if (huh.value == "") {
document.getElementById("o23").value = "x";
document.getElementById("o12").selectedIndex = 0; //.value = "x²";
} else {
document.getElementById("o23").value = "/x";
document.getElementById("o12").value = "";
}
} else if (huh.value == document.getElementById("o12").value) {
//toggle = 1 - toggle;
if (huh.value == "") {
document.getElementById("o23").value = "/x";
document.getElementById("o34").selectedIndex = 1; //.value = "/x²";
} else {
document.getElementById("o23").value = "x";
document.getElementById("o34").value = "";
}
}
xt = 0;
}
}
function later() {
if (stuff != "") alert(stuff);
default_fill();
}
function examine_answer() {
//alert(1);
iurl = "http://www.rjmprogramming.com.au/PHP/ParabolaLineGraph/parabola_lgraph.php?";
r1 = document.getElementById("r1").value;
r2 = document.getElementById("r2").value;
n1 = document.getElementById("n1").value;
n2 = document.getElementById("n2").value;
n3 = document.getElementById("n3").value;
n4 = document.getElementById("n4").value;
o12 = document.getElementById("o12").value;
o23 = document.getElementById("o23").value;
o34 = document.getElementById("o34").value;
//alert(2);
if (n1 == "" && n2 == "" && n3 == "" && n4 == "" && o12 == "" && o23 == "" && o34 == "") {
alert('Please fill in the unknowns and click "Am I correct?" button');
} else {
if (r1 == "") r1 = 0.00;
if (r2 == "") r2 = 0;
if (n1 == "") n1 = 0.00;
if (n2 == "") n2 = 0;
if (n3 == "") n3 = 0.000;
if (n4 == "") n4 = 0;
//if (o12 == "") o12 = "+";
//if (o23 == "") o23 = "+";
//if (o34 == "") o34 = "+";
var thingtotest1 = ""; // "((" + n1 + ")" + o12 + "(" + n2 + ")" + o23 + "(" + n3 + "))";
if (o12 == "") {
thingtotest1 = "((" + n1 + ")" + "+" + "(" + n2 + ")" + "/(" + r1 + ")" + "+" + "(" + n3 + ")" + "/((" + r1 + ")*(" + r1 + ")))";
} else {
thingtotest1 = "((" + n3 + ")" + "+" + "(" + n2 + ")" + "*(" + r1 + ")" + "+" + "(" + n1 + ")" + "*((" + r1 + ")*(" + r1 + ")))";
}
//alert(thingtotest1);
var ans1 = eval(thingtotest1);
//alert("yes" + thingtotest1);
var diff1 = eval((n4)-(ans1));
//alert("yesyes" + thingtotest1);
var thingtotest2 = ""; // "((" + n1 + ")" + o12 + "(" + n2 + ")" + o23 + "(" + n3 + "))";
if (o12 == "") {
thingtotest2 = "((" + n1 + ")" + "+" + "(" + n2 + ")" + "/(" + r2 + ")" + "+" + "(" + n3 + ")" + "/((" + r2 + ")*(" + r2 + ")))";
} else {
thingtotest2 = "((" + n3 + ")" + "+" + "(" + n2 + ")" + "*(" + r2 + ")" + "+" + "(" + n1 + ")" + "*((" + r2 + ")*(" + r2 + ")))";
}
var ans2 = eval(thingtotest2);
var diff2 = eval((n4)-(ans2));
//alert("oiuoiu" + thingtotest2);
var os1 = document.getElementById('s1');
var os2 = document.getElementById('s2');
s1 = eval(os1.value);
s2 = eval(os2.value);
s2 = eval((s2)+(2));
os2.value = s2;
stuff = "";
var minval=0, maxval=0, mye2=0, mye1=0, mye0=0;
var more = "";
var premore = "";
if (diff1 < 0.0001 && diff1 > -0.0001 && diff2 < 0.0001 && diff2 > -0.0001) {
s1 = eval((s1)+(2));
os1.value = s1;
stuff = 'Congratulations! ' + thingtotest1 + ' = ' + n4 + " " + thingtotest2 + ' = ' + n4;
} else if ((diff1 >= 0.0001 || diff1 <= -0.0001) && (diff2 >= 0.0001 || diff2 <= -0.0001)) {
premore='Sorry to say that ' + thingtotest1 + ' = ' + ans1 + ' ... but you answered ' + n4 + ' ' + thingtotest2 + ' = ' + ans2 + ' ... but you answered ' + n4;
more=" ";
if (n4 != 0 && o34 == "") {
n3 -= n4;
n4 = 0;
} else if (n4 != 0) {
n1 -= n4;
n4 = 0;
}
if (o34 == "") {
mye2 = n1;
mye1 = "+" + n2;
mye1 = mye1.replace("+-", "-");
mye0 = "+" + n3;
mye0 = mye0.replace("+-", "-");
n4 = n2 * n2 - (4.0 * n1 * n3);
n4 = Math.sqrt(n4);
minval = eval(((0.0)-(n2)-(n4))/(2.0*n1));
maxval = eval(((0.0)-(n2)+(n4))/(2.0*n1));
more = " Roots are " + minval;
more = more + " and " + maxval;
} else {
mye2 = n3;
mye1 = "+" + n2;
mye1 = mye1.replace("+-", "-");
mye0 = "+" + n1;
mye0 = mye0.replace("+-", "-");
n4 = n2 * n2 - (4.0 * n1 * n3);
n4 = Math.sqrt(n4);
minval = eval(((0.0)-(n2)-(n4))/(2.0*n3));
maxval = eval(((0.0)-(n2)+(n4))/(2.0*n3));
more = " Roots are " + minval;
more = more + " and " + maxval;
}
stuff = premore + more;
} else if (diff1 >= 0.0001 || diff1 <= -0.0001) {
s1 = eval((s1)+(1));
os1.value = s1;
stuff = 'Half okay ... Sorry to say that ' + thingtotest1 + ' = ' + ans1 + ' ... but you answered ' + n4;
} else {
s1 = eval((s1)+(1));
os1.value = s1;
stuff = 'Half okay ... Sorry to say that ' + thingtotest2 + ' = ' + ans2 + ' ... but you answered ' + n4;
}
}
if (more == "") {
if (n4 != 0 && o34 == "") {
n3 -= n4;
n4 = 0;
} else if (n4 != 0) {
n1 -= n4;
n4 = 0;
}
if (o34 == "") {
mye2 = n1;
mye1 = "+" + n2;
mye1 = mye1.replace("+-", "-");
mye0 = "+" + n3;
mye0 = mye0.replace("+-", "-");
n4 = n2 * n2 - (4.0 * n1 * n3);
n4 = Math.sqrt(n4);
minval = eval(((0.0)-(n2)-(n4))/(2.0*n1));
maxval = eval(((0.0)-(n2)+(n4))/(2.0*n1));
more = " Roots are " + minval;
more = more + " and " + maxval;
} else {
mye2 = n3;
mye1 = "+" + n2;
mye1 = mye1.replace("+-", "-");
mye0 = "+" + n1;
mye0 = mye0.replace("+-", "-");
n4 = n2 * n2 - (4.0 * n1 * n3);
n4 = Math.sqrt(n4);
minval = eval(((0.0)-(n2)-(n4))/(2.0*n3));
maxval = eval(((0.0)-(n2)+(n4))/(2.0*n3));
more = " Roots are " + minval;
more = more + " and " + maxval;
}
}
iurl = iurl + "minval=" + minval + "&maxval=" + maxval + "&e2=" + mye2 + "&e1=" + mye1 + "&e0=" + mye0;
//http://www.rjmprogramming.com.au/PHP/ParabolaLineGraph/parabola_lgraph.php?minval=-1&maxval=0&e2=1&e1=+2&e0=+3
var qwt=document.getElementById('ifrm');
qwt.style.display = 'block';
qwt.innerHTML = '<iframe src="' + iurl + '" id="ifrmqe" style="display:block;width:100%;height:520px;"></iframe>';
//window.open(iurl, 'ifrmqe');
//setTimeout(later, 3000); //alert(stuff);
alert(stuff);
default_fill();
return true;
}
</script>
</head>
<body onload="init();" style="background-color: yellow;">
<div id="ifrm" style="display:none;;width:100%;height:520px;"><iframe src="javascript:false;" id="ifrmqe" style="display:none;width:100%;height:520px;"></iframe></div>
<form style="border: 5px solid blue; padding: 4px 4px 4px 4px;" method="GET">
<h2 style="border: 7px solid lightgreen; padding: 5 5 5 5;"><select id="difficulty" name="difficulty"><option value="SuperEasy" selected="selected">Easier</option><option value="Easy">Easy</option><option value="Harder">Harder</option></select> <select id="hm" name="hm"><option value="0">Quadratic Equation Roots are</option><option value="1">One Number is</option><option value="2">Two Numbers are</option></select> Missing ... Score <input type="text" id="s1" name="s1" style="background-color:pink;" value="0" /> out of <input type="text" id="s2" name="s2" value="0" style="background-color:teal;" /></h2>
<p><span>(<input type="text" id="n1" name="n1" value="" />)<select id="o12" name="o12" onchange="modechange(this);" value=""><option value="x²">x²</option><option value=""></option></select>+(<input type="text" id="n2" name="n2" value="" />)<select id="o23" name="o23" onchange="modechange(this);" value=""><option value="x">x</option><option value="/x">/x</option></select>+(<input type="text" id="n3" name="n3" value="" />)<select id="o34" name="o34" onchange="modechange(this);" value=""><option value=""></option><option value="/x²">/x²</option></select> = <input type="text" id="n4" name="n4" value="" /></span></p>
<p>Roots are: <input type="text" id="r1" name="r1" value="" style="background-color: lightblue;" />, <input type="text" id="r2" name="r2" value="" style="background-color: lightblue;" /></p>
<p><input id="r" type="reset" /> <input title="Fill out above to make the equation true" type="submit" id="s" value="Am I correct?" /></p>
</form>
</body>
</html>