topical media & game development

game-javascript-math-kennedy-balanceTheEquation.htm / htm

```
<html>
<title>Sunny Boy Says Balance the Equation!</title>
<script language="JavaScript">
// constants
var kSubtraction = '-';
var kMultiplication = 'x';
var kDivision = '\367';  // this is the octal representation of the division sign.
var kMinOperand = 0;
var kMaxOperand = 15;

// Generic Functions
function assert(isTrue, message) { if (!isTrue) { alert(message) } }

function myPop (string){
var generator=window.open('', 'name', 'width=400,height=100,toolbar=0,scrollbars=0,screenX=200,screenY=200,left=200,top=200');

generator.document.write(string);
generator.document.write('<center><a href="javascript:self.close()">Close</a></center>');
generator.document.write('</body></html>');
generator.document.close();
}

function absoluteValue (value){ if (value < 0) return (-1*value); else return value; }

function getRandomNumberInRange(rangeStart, rangeEnd){
assert((rangeStart < rangeEnd), "getRandomNumberInRange: Invalid Input range start =" + rangeStart + " and rangeEnd = " + rangeEnd);
return Math.round(Math.random()*(rangeEnd-rangeStart)+rangeStart);
}

function getRandomVariableLetter(){
switch(getRandomNumberInRange(1,6)){
case 1: return 'b';
case 2: return 'c';
case 3: return 'd';
case 4: return 'm';
case 5: return 'n';
case 6: return 'y';
}
}

function getRandomOperation(){
switch(gPreviousOperation){
case kAddition: gPreviousOperation = kSubtraction; break;
case kSubtraction: gPreviousOperation = kMultiplication; break;
case kMultiplication: gPreviousOperation = kDivision; break;
case kDivision: gPreviousOperation = kAddition; break;
}
return gPreviousOperation;
}

function performOperation (operation, op1, op2){
switch(operation){
case kSubtraction: return op1-op2;
case kMultiplication: return op1 * op2;
case kDivision: return op1/op2;
}
}

function getOppositeOperation (operation){
switch(operation){
case kMultiplication: return kDivision;
case kDivision: return kMultiplication;
}
}

// Dynamic HTML writing functions
function writeTxtAtTDidOptions(tBodyID, string, sizeString, colorString, appendNewLine){
var tbody = document.getElementById(tBodyID);
// create holder for accumulated tbody elements and text nodes
var frag = document.createDocumentFragment();

var font = document.createElement("font");
font.setAttribute("size", sizeString);
font.setAttribute("color", colorString);
var txt = document.createTextNode(string);
font.appendChild(txt);
frag.appendChild(font);

if (!tbody.appendChild(frag)) {
alert("This browser doesn't support dynamic tables.");
}

if (appendNewLine) writeNewLineAtTDid(tBodyID);
}

function writeTxtAtTDid(tBodyID, string){ writeTxtAtTDidOptions(tBodyID, string, "+1", "black", false);}

function writeTabAtTDid(tBodyID){writeTxtAtTDidOptions(tBodyID, "<tab>", "+0", "white", false)}

function writeNewLineAtTDid(tBodyID){
var tbody = document.getElementById(tBodyID);
// create holder for accumulated tbody elements and text nodes
var frag = document.createDocumentFragment();

var newLine = document.createElement("br");
frag.appendChild(newLine);

if (!tbody.appendChild(frag)) {
alert("This browser doesn't support dynamic tables.");
}
}

function writeLinkAtTDidOptions(tBodyID, href, label, sizeString, colorString, isUnderlined, appendNewLine){
var tbody = document.getElementById(tBodyID);
// create holder for accumulated tbody elements and text nodes
var frag = document.createDocumentFragment();

var a = document.createElement("a");
a.setAttribute("href", href);
if (!isUnderlined) a.setAttribute("style", "text-decoration: none");

var font = document.createElement("font");
font.setAttribute("size", sizeString);
font.setAttribute("color", colorString);
var txt = document.createTextNode(label);
font.appendChild(txt);
a.appendChild(font);
frag.appendChild(a);

if (!tbody.appendChild(frag)) {
alert("This browser doesn't support dynamic tables.");
}

if (appendNewLine) writeNewLineAtTDid(tBodyID);
}

// Remove existing content of an element
function clearChildNodes(elemID) {
var elem = document.getElementById(elemID);
while (elem.childNodes.length > 0) {
elem.removeChild(elem.firstChild);
}
}

// question generating objects
// each object is responsible for the following methods
// getWordProblem
// getNumberSentence
// getIncorrectNumberSentence
// getSolutionForVariable
// getIncorrectSolutionForVariable

// first comes the easy problems
function getSimpleWordProblem(){return (this.introText + " " + this.operand1 + " " + this.inBetweenText + " " + this.operand2 + " is " + this.rightSideSolution);}
function getSimpleNumberSentence(){
if (kMultiplication == this.operation)
return (this.operand1 + this.operand2 + " = " + this.rightSideSolution);
else
return (this.operand1 + " " + this.operation + " " + this.operand2 + " = " + this.rightSideSolution);
}

function getSimpleIncorrectNumberSentence(){
var temp = new simpleIncorrectProblemCopier(this);
return temp;
}

function getSolutionForVariable(){return this.valueOfVariable;}

function getIncorrectSolutionForVariable(){
var incorrectSolution = getRandomNumberInRange(this.kMinVariableValue, this.kMaxVariableValue);
if (incorrectSolution == this.valueOfVariable) incorrectSolution++;
return incorrectSolution;
}

function simpleIncorrectProblemCopier(simpleProblem) {
this.operation = simpleProblem.operation;
while (this.operation == simpleProblem.operation) { this.operation = getRandomOperation(); }

this.operand1 = simpleProblem.operand1;
this.operand2 = simpleProblem.operand2;
this.rightSideSolution = simpleProblem.rightSideSolution;
this.variable = simpleProblem.variable;

assert((this.operand1==this.variable || this.operand2==this.variable), "simpleIncorrectProblemCopier(): variable does not match up with op1 or op2");

if (this.operand1 == this.variable){
this.valueOfVariable =
Math.round(absoluteValue(performOperation(getOppositeOperation(this.operation), this.rightSideSolution, this.operand2)));
}
else{
this.valueOfVariable =
Math.round(absoluteValue(performOperation(getOppositeOperation(this.operation), this.rightSideSolution, this.operand1)));
}

if (this.valueOfVariable == simpleProblem.valueOfVariable) this.valueOfVariable = getRandomNumberInRange(kMinOperand, kMaxOperand);

// public methods
this.toString = getSimpleNumberSentence;
this.getNumberSentence = getSimpleNumberSentence;

assert((this.valueOfVariable >= 0), "simpleIncorrectProblemCopier(): valueOfVariable is too small: " + this.valueOfVariable);
}

// first lets construct the problem
// word problem format =   introText op1 inBetweenText op2 is rightSideSolution
// number sentence format = op1 operation op2 = rightside solution
// other needed informatin =  variable and valueOfVariable;
switch(getRandomNumberInRange(1,4)){
case 1: this.introText = "The sum of"; this.inBetweenText = "and"; break;
case 2: this.introText = "Increasing"; this.inBetweenText = "by"; break;
case 3: this.introText = "Total of"; this.inBetweenText = "and"; break;
case 4: this.introText = "Adding"; this.inBetweenText = "and"; break;
}
this.kMinVariableValue = kMinOperand; this.kMaxVariableValue = kMaxOperand;
this.operand1 = getRandomNumberInRange(kMinOperand, kMaxOperand);
this.operand2 = getRandomNumberInRange(kMinOperand, kMaxOperand);
this.rightSideSolution = this.operand1 + this.operand2;
this.variable = getRandomVariableLetter();

this.valueOfVariable = 0;
if (0 == getRandomNumberInRange(0,1)){ this.valueOfVariable = this.operand1; this.operand1 = this.variable; }
else{ this.valueOfVariable = this.operand2; this.operand2 = this.variable; }

// public methods
this.toString = getSimpleWordProblem;
this.getWordProblem = getSimpleWordProblem;
this.getNumberSentence = getSimpleNumberSentence;
this.getIncorrectNumberSentence = getSimpleIncorrectNumberSentence;
this.getSolutionForVariable = getSolutionForVariable;
this.getIncorrectSolutionForVariable = getIncorrectSolutionForVariable;

assert((this.valueOfVariable >= 0), "simpleAdditionProblem(): valueOfVariable is too small: " + this.valueOfVariable);
}

function simpleSubtractionProblem() {
switch(getRandomNumberInRange(1,3)){
case 1: this.introText = "Difference between"; this.inBetweenText = "and"; break;
case 2: this.introText = "Decreasing"; this.inBetweenText = "by"; break;
case 3: this.introText = ""; this.inBetweenText = "minus"; break;
}
this.operation = kSubtraction;
this.kMinVariableValue = kMinOperand; this.kMaxVariableValue = kMaxOperand*2;
this.rightSideSolution = getRandomNumberInRange(kMinOperand, kMaxOperand);
this.operand2 = getRandomNumberInRange(kMinOperand, kMaxOperand);
this.operand1 = this.rightSideSolution + this.operand2;
this.variable = getRandomVariableLetter();

this.valueOfVariable = 0;
if (0 == getRandomNumberInRange(0,1)){ this.valueOfVariable = this.operand1; this.operand1 = this.variable; }
else{ this.valueOfVariable = this.operand2; this.operand2 = this.variable; }

// public methods
this.toString = getSimpleWordProblem;
this.getWordProblem = getSimpleWordProblem;
this.getNumberSentence = getSimpleNumberSentence;
this.getIncorrectNumberSentence = getSimpleIncorrectNumberSentence;
this.getSolutionForVariable = getSolutionForVariable;
this.getIncorrectSolutionForVariable = getIncorrectSolutionForVariable;

assert((this.valueOfVariable >= 0), "simpleSubtractionProblem(): valueOfVariable is too small: " + this.valueOfVariable);
}

function simpleMultiplicationProblem() {
switch(getRandomNumberInRange(1,3)){
case 1: this.introText = "Multiplying"; this.inBetweenText = "and"; break;
case 2: this.introText = "Product of"; this.inBetweenText = "and"; break;
case 3: this.introText = ""; this.inBetweenText = "times"; break;
}

this.operation = kMultiplication;
this.kMinVariableValue = kMinOperand; this.kMaxVariableValue = kMaxOperand;
this.operand1 = getRandomNumberInRange(1, kMaxOperand);
this.operand2 = getRandomNumberInRange(1, kMaxOperand);
this.rightSideSolution = this.operand1 * this.operand2;
this.variable = getRandomVariableLetter();

this.valueOfVariable = this.operand2; this.operand2 = this.variable;

// public methods
this.toString = getSimpleWordProblem;
this.getWordProblem = getSimpleWordProblem;
this.getNumberSentence = getSimpleNumberSentence;
this.getIncorrectNumberSentence = getSimpleIncorrectNumberSentence;
this.getSolutionForVariable = getSolutionForVariable;
this.getIncorrectSolutionForVariable = getIncorrectSolutionForVariable;

assert((this.valueOfVariable >= 0), "simpleMultiplicationProblem(): valueOfVariable is too small: " + this.valueOfVariable);
}

function simpleDivisionProblem() {
switch(getRandomNumberInRange(1,2)){
case 1: this.introText = "Dividing"; this.inBetweenText = "by"; break;
case 2: this.introText = "Quotient of"; this.inBetweenText = "and"; break;
}
this.operation = kDivision;
this.kMinVariableValue = kMinOperand; this.kMaxVariableValue = kMaxOperand*kMaxOperand;
this.rightSideSolution = getRandomNumberInRange(1, kMaxOperand);
this.operand2 = getRandomNumberInRange(1, kMaxOperand);
this.operand1 = this.rightSideSolution*this.operand2;
this.variable = getRandomVariableLetter();

this.valueOfVariable = 0;
if (0 == getRandomNumberInRange(0,1)){ this.valueOfVariable = this.operand1; this.operand1 = this.variable; }
else{ this.valueOfVariable = this.operand2; this.operand2 = this.variable; }

// public methods
this.toString = getSimpleWordProblem;
this.getWordProblem = getSimpleWordProblem;
this.getNumberSentence = getSimpleNumberSentence;
this.getIncorrectNumberSentence = getSimpleIncorrectNumberSentence;
this.getSolutionForVariable = getSolutionForVariable;
this.getIncorrectSolutionForVariable = getIncorrectSolutionForVariable;

assert((this.valueOfVariable >= 0), "simpleDivisionProblem(): valueOfVariable is too small: " + this.valueOfVariable);
}

// now lets do the complicated problems
function getComplexWordProblem(){return (this.operand1 + " " + this.firstOperationText + " " + this.operand2 + " " + this.secondOperationText + " " + this.operand3 + " is " + this.rightSideSolution);}

function getComplexIncorrectNumberSentence(){
var temp = new complexIncorrectProblemCopier(this);
return temp;
}

function complexIncorrectProblemCopier(complexProblem) {
this.operation1 = getRandomOperation(); this.operation2 = getRandomOperation();
while (this.operation1 == complexProblem.operation1) { this.operation1 = getRandomOperation(); }
while (this.operation2 == complexProblem.operation2) { this.operation2 = getRandomOperation(); }

this.operand2 = complexProblem.operand2;
this.operand1 = complexProblem.operand1;
this.operand3 = complexProblem.operand3;
this.rightSideSolution = complexProblem.rightSideSolution;
this.variable = complexProblem.variable;
this.valueOfVariable = complexProblem.valueOfVariable;

function getComplexNumberSentence(){
var numberSentence = ""+this.operand1;

if (kMultiplication == this.operation1) numberSentence = numberSentence + this.operand2;
else numberSentence = numberSentence + " " + this.operation1 + " " + this.operand2;

return (numberSentence + " " + this.operation2 + " " + this.operand3 + " = " + this.rightSideSolution);
}

// public methods
this.toString = getComplexNumberSentence;
this.getNumberSentence = getComplexNumberSentence;

assert((this.valueOfVariable >= 0), "simpleDivisionProblem(): valueOfVariable is too small: " + this.valueOfVariable);
}

this.firstOperationText = "times"; this.secondOperationText = "plus";

this.kMinVariableValue = kMinOperand; this.kMaxVariableValue = kMaxOperand;
this.operation1 = kMultiplication; this.operation2 = kAddition;

this.operand2 = getRandomNumberInRange(1, kMaxOperand);
this.operand1 = getRandomNumberInRange(1, kMaxOperand);
this.operand3 = getRandomNumberInRange(kMinOperand, kMaxOperand);
this.rightSideSolution = this.operand1 * this.operand2 + this.operand3;
this.variable = getRandomVariableLetter();

this.valueOfVariable = this.operand2; this.operand2 = this.variable;

function getComplexNumberSentence(){ return (this.operand1 + this.operand2 + " + " + this.operand3 + " = " + this.rightSideSolution); }

// public methods
this.toString = getComplexWordProblem;
this.getWordProblem = getComplexWordProblem;
this.getNumberSentence = getComplexNumberSentence;
this.getIncorrectNumberSentence = getComplexIncorrectNumberSentence;
this.getSolutionForVariable = getSolutionForVariable;
this.getIncorrectSolutionForVariable = getIncorrectSolutionForVariable;

assert((this.valueOfVariable >= 0), "addAndMultiplicationProblem(): valueOfVariable is too small: " + this.valueOfVariable);
}

function subtractAndMultiplicationProblem() {
this.firstOperationText = "times"; this.secondOperationText = "minus";

this.kMinVariableValue = kMinOperand; this.kMaxVariableValue = kMaxOperand;
this.operation1 = kMultiplication; this.operation2 = kSubtraction;

this.operand2 = getRandomNumberInRange(1, kMaxOperand);
this.operand1 = getRandomNumberInRange(1, kMaxOperand);
this.operand3 = getRandomNumberInRange(kMinOperand, this.operand1*this.operand2);
this.rightSideSolution = this.operand1 * this.operand2 - this.operand3;
this.variable = getRandomVariableLetter();

this.valueOfVariable = this.operand2; this.operand2 = this.variable;

function getComplexNumberSentence(){ return (this.operand1 + this.operand2 + " - " + this.operand3 + " = " + this.rightSideSolution); }

// public methods
this.toString = getComplexWordProblem;
this.getWordProblem = getComplexWordProblem;
this.getNumberSentence = getComplexNumberSentence;
this.getIncorrectNumberSentence = getComplexIncorrectNumberSentence;
this.getSolutionForVariable = getSolutionForVariable;
this.getIncorrectSolutionForVariable = getIncorrectSolutionForVariable;

assert((this.valueOfVariable >= 0), "subtractAndMultiplicationProblem(): valueOfVariable is too small: " + this.valueOfVariable);
}

this.firstOperationText = "divided by"; this.secondOperationText = "plus";

this.kMinVariableValue = kMinOperand; this.kMaxVariableValue = kMaxOperand;
this.operation1 = kDivision; this.operation2 = kAddition;

this.operand2 = getRandomNumberInRange(1, kMaxOperand);
this.operand1 = getRandomNumberInRange(1, kMaxOperand)*this.operand2;
this.operand3 = getRandomNumberInRange(kMinOperand, kMaxOperand);
this.rightSideSolution = this.operand1/this.operand2 + this.operand3;
this.variable = getRandomVariableLetter();

this.valueOfVariable = this.operand1; this.operand1 = this.variable;

function getComplexNumberSentence(){ return (this.operand1 + " \367 " + this.operand2 + " + " + this.operand3 + " = " + this.rightSideSolution); }

// public methods
this.toString = getComplexWordProblem;
this.getWordProblem = getComplexWordProblem;
this.getNumberSentence = getComplexNumberSentence;
this.getIncorrectNumberSentence = getComplexIncorrectNumberSentence;
this.getSolutionForVariable = getSolutionForVariable;
this.getIncorrectSolutionForVariable = getIncorrectSolutionForVariable;

assert((this.valueOfVariable >= 0), "addAndDivisionProblem(): valueOfVariable is too small: " + this.valueOfVariable);
}

function subtractAndDivisionProblem() {
this.firstOperationText = "divided by"; this.secondOperationText = "minus";

this.kMinVariableValue = kMinOperand; this.kMaxVariableValue = kMaxOperand;
this.operation1 = kDivision; this.operation2 = kSubtraction;

this.operand2 = getRandomNumberInRange(1, kMaxOperand);
this.operand1 = getRandomNumberInRange(1, kMaxOperand)*this.operand2;
this.operand3 = getRandomNumberInRange(kMinOperand, this.operand1/this.operand2);
this.rightSideSolution = this.operand1/this.operand2 - this.operand3;
this.variable = getRandomVariableLetter();

this.valueOfVariable = this.operand1; this.operand1 = this.variable;

function getComplexNumberSentence(){ return (this.operand1 + " \367 " + this.operand2 + " - " + this.operand3 + " = " + this.rightSideSolution); }

// public methods
this.toString = getComplexWordProblem;
this.getWordProblem = getComplexWordProblem;
this.getNumberSentence = getComplexNumberSentence;
this.getIncorrectNumberSentence = getComplexIncorrectNumberSentence;
this.getSolutionForVariable = getSolutionForVariable;
this.getIncorrectSolutionForVariable = getIncorrectSolutionForVariable;

assert((this.valueOfVariable >= 0), "subtractAndDivisionProblem(): valueOfVariable is too small: " + this.valueOfVariable);
}

// test writing functions
function requestPrintTest(){
if (document.getElementById) {
// clear all old dynamically created table stuff.
clearChildNodes("wordProblemTag");
clearChildNodes("solution4Tag");
clearChildNodes("solution3Tag");
clearChildNodes("solution2Tag");
clearChildNodes("solution1Tag");
clearChildNodes("resultsTag");

// assure bug-free redraw in Gecko engine by letting window show cleared table
if (navigator.product && navigator.product == "Gecko") {
setTimeout("printTest()", 0);
}
else {
printTest();
}
}
else {
alert("Sorry, dynamic table feature works with IE5 or later for Windows, and Netscape 6 or later.");
}
}

function getNextProblem(){
switch(getRandomNumberInRange(0,7)){
case 0: return new simpleAdditionProblem(); break;
case 1: return new simpleSubtractionProblem(); break;
case 2: return new simpleMultiplicationProblem(); break;
case 3: return new simpleDivisionProblem(); break;
case 4: return new addAndMultiplicationProblem(); break;
case 5: return new subtractAndMultiplicationProblem(); break;
case 6: return new addAndDivisionProblem(); break;
case 7: return new subtractAndDivisionProblem(); break;
}
}

function printTest(){
gCurrentProblem = getNextProblem();
// write the word problem
writeTxtAtTDidOptions("wordProblemTag", gCurrentProblem, "+4", "black", false);

// write the solutions to choose from
switch(getRandomNumberInRange(0,3)){
case 0:
writeLinkAtTDidOptions("solution2Tag", "javascript:requestPrintIncorrectNumberSentence();", "b) " + gCurrentProblem.getIncorrectNumberSentence(), "+0", "brown", false, false);
writeLinkAtTDidOptions("solution3Tag", "javascript:requestPrintIncorrectNumberSentence();", "c) " + gCurrentProblem.getIncorrectNumberSentence(), "+0", "brown", false, false);
writeLinkAtTDidOptions("solution4Tag", "javascript:requestPrintIncorrectNumberSentence();", "d) " + gCurrentProblem.getIncorrectNumberSentence(), "+0", "brown", false, false);
break;
case 1:
writeLinkAtTDidOptions("solution1Tag", "javascript:requestPrintIncorrectNumberSentence();", "a) " + gCurrentProblem.getIncorrectNumberSentence(), "+0", "brown", false, false);
writeLinkAtTDidOptions("solution3Tag", "javascript:requestPrintIncorrectNumberSentence();", "c) " + gCurrentProblem.getIncorrectNumberSentence(), "+0", "brown", false, false);
writeLinkAtTDidOptions("solution4Tag", "javascript:requestPrintIncorrectNumberSentence();", "d) " + gCurrentProblem.getIncorrectNumberSentence(), "+0", "brown", false, false);
break;
case 2:
writeLinkAtTDidOptions("solution1Tag", "javascript:requestPrintIncorrectNumberSentence();", "a) " + gCurrentProblem.getIncorrectNumberSentence(), "+0", "brown", false, false);
writeLinkAtTDidOptions("solution2Tag", "javascript:requestPrintIncorrectNumberSentence();", "b) " + gCurrentProblem.getIncorrectNumberSentence(), "+0", "brown", false, false);
writeLinkAtTDidOptions("solution4Tag", "javascript:requestPrintIncorrectNumberSentence();", "d) " + gCurrentProblem.getIncorrectNumberSentence(), "+0", "brown", false, false);
break;
case 3:
writeLinkAtTDidOptions("solution1Tag", "javascript:requestPrintIncorrectNumberSentence();", "a) " + gCurrentProblem.getIncorrectNumberSentence(), "+0", "brown", false, false);
writeLinkAtTDidOptions("solution2Tag", "javascript:requestPrintIncorrectNumberSentence();", "b) " + gCurrentProblem.getIncorrectNumberSentence(), "+0", "brown", false, false);
writeLinkAtTDidOptions("solution3Tag", "javascript:requestPrintIncorrectNumberSentence();", "c) " + gCurrentProblem.getIncorrectNumberSentence(), "+0", "brown", false, false);
break;
}

writeTxtAtTDid("resultsTag", "Choose the correct number sentence for word problem!");
}

function requestPrintVariableValueResponse(isCorrect){
if (document.getElementById) {
// clear all old dynamically created table stuff.
clearChildNodes("resultsTag");

// assure bug-free redraw in Gecko engine by letting window show cleared table
if (navigator.product && navigator.product == "Gecko") {
setTimeout("printVariableValueResponse(" + isCorrect + ")", 0);
}
else {
printVariableValueResponse(isCorrect);
}
}
else {
alert("Sorry, dynamic table feature works with IE5 or later for Windows, and Netscape 6 or later.");
}
}

function printVariableValueResponse(isCorrect){
if (isCorrect)
writeTxtAtTDid("resultsTag", "Very Good! You are so smart. " + gCurrentProblem.variable + " = " + gCurrentProblem.getSolutionForVariable());
else
writeTxtAtTDid("resultsTag", "Incorrect, Find the value of " + gCurrentProblem.variable + " in " + gCurrentProblem.getNumberSentence() + "? Always check your work!");
}

function requestPrintIncorrectNumberSentence(){
if (document.getElementById) {
// clear all old dynamically created table stuff.
clearChildNodes("resultsTag");

// assure bug-free redraw in Gecko engine by letting window show cleared table
if (navigator.product && navigator.product == "Gecko") {
setTimeout("printIncorrectNumberSentence()", 0);
}
else {
printIncorrectNumberSentence();
}
}
else {
alert("Sorry, dynamic table feature works with IE5 or later for Windows, and Netscape 6 or later.");
}
}

function printIncorrectNumberSentence(){
}

if (document.getElementById) {
// clear all old dynamically created table stuff.
clearChildNodes("solution4Tag");
clearChildNodes("solution3Tag");
clearChildNodes("solution2Tag");
clearChildNodes("solution1Tag");
clearChildNodes("resultsTag");

// assure bug-free redraw in Gecko engine by letting window show cleared table
if (navigator.product && navigator.product == "Gecko") {
}
else {
}
}
else {
alert("Sorry, dynamic table feature works with IE5 or later for Windows, and Netscape 6 or later.");
}
}

// write the solutions to choose from
switch(getRandomNumberInRange(0,3)){
case 0:
writeLinkAtTDidOptions("solution1Tag", "javascript:requestPrintVariableValueResponse(1);", "a) " + gCurrentProblem.getSolutionForVariable(), "+0", "brown", false, false);
writeLinkAtTDidOptions("solution2Tag", "javascript:requestPrintVariableValueResponse(0);", "b) " + gCurrentProblem.getIncorrectSolutionForVariable(), "+0", "brown", false, false);
writeLinkAtTDidOptions("solution3Tag", "javascript:requestPrintVariableValueResponse(0);", "c) " + gCurrentProblem.getIncorrectSolutionForVariable(), "+0", "brown", false, false);
writeLinkAtTDidOptions("solution4Tag", "javascript:requestPrintVariableValueResponse(0);", "d) " + gCurrentProblem.getIncorrectSolutionForVariable(), "+0", "brown", false, false);
break;
case 1:
writeLinkAtTDidOptions("solution1Tag", "javascript:requestPrintVariableValueResponse(0);", "a) " + gCurrentProblem.getIncorrectSolutionForVariable(), "+0", "brown", false, false);
writeLinkAtTDidOptions("solution2Tag", "javascript:requestPrintVariableValueResponse(1);", "b) " + gCurrentProblem.getSolutionForVariable(), "+0", "brown", false, false);
writeLinkAtTDidOptions("solution3Tag", "javascript:requestPrintVariableValueResponse(0);", "c) " + gCurrentProblem.getIncorrectSolutionForVariable(), "+0", "brown", false, false);
writeLinkAtTDidOptions("solution4Tag", "javascript:requestPrintVariableValueResponse(0);", "d) " + gCurrentProblem.getIncorrectSolutionForVariable(), "+0", "brown", false, false);
break;
case 2:
writeLinkAtTDidOptions("solution1Tag", "javascript:requestPrintVariableValueResponse(0);", "a) " + gCurrentProblem.getIncorrectSolutionForVariable(), "+0", "brown", false, false);
writeLinkAtTDidOptions("solution2Tag", "javascript:requestPrintVariableValueResponse(0);", "b) " + gCurrentProblem.getIncorrectSolutionForVariable(), "+0", "brown", false, false);
writeLinkAtTDidOptions("solution3Tag", "javascript:requestPrintVariableValueResponse(1);", "c) " + gCurrentProblem.getSolutionForVariable(), "+0", "brown", false, false);
writeLinkAtTDidOptions("solution4Tag", "javascript:requestPrintVariableValueResponse(0);", "d) " + gCurrentProblem.getIncorrectSolutionForVariable(), "+0", "brown", false, false);
break;
case 3:
writeLinkAtTDidOptions("solution1Tag", "javascript:requestPrintVariableValueResponse(0);", "a) " + gCurrentProblem.getIncorrectSolutionForVariable(), "+0", "brown", false, false);
writeLinkAtTDidOptions("solution2Tag", "javascript:requestPrintVariableValueResponse(0);", "b) " + gCurrentProblem.getIncorrectSolutionForVariable(), "+0", "brown", false, false);
writeLinkAtTDidOptions("solution3Tag", "javascript:requestPrintVariableValueResponse(0);", "c) " + gCurrentProblem.getIncorrectSolutionForVariable(), "+0", "brown", false, false);
writeLinkAtTDidOptions("solution4Tag", "javascript:requestPrintVariableValueResponse(1);", "d) " + gCurrentProblem.getSolutionForVariable(), "+0", "brown", false, false);
break;
}

writeTxtAtTDid("resultsTag", "Correct, what is the value of " + gCurrentProblem.variable + " in " + gCurrentProblem.getNumberSentence() + "?");
}

// generates pop up window with guidance to solve word problems
function requestHelp(){
var generator=window.open('','name','height=400,width=700,scrollbars=1');

generator.document.write('<h1><b><center>Word Problems and Algebra</center></b></h1>');
generator.document.write('<table align="center" border="1"><tr><td><b><font size="+2">+</font></b> plus, add, and, sum, total, increase</td></tr>');
generator.document.write('<tr><td><b><font size="+2">-</font></b> minus, subtract, take away, difference, remains, decrease</td></tr>');
generator.document.write('<tr><td><b><font size="+2">x</font></b> multiply, times, product, double (multiply by 2)</td></tr>');
generator.document.write('<tr><td><b><font size="+2">\367</font></b> divide,  quotient, share, halve (divide by 2)</td></tr>');
generator.document.write('<tr><td><b><font size="+2">=</font></b> equal to, is </td></tr></table><br>');

generator.document.write('Read the word problems carefully so you can make a number sentence. ');
generator.document.write('If you make a number sentence, then your work will be easy.');
generator.document.write('<br>Examples:<br><b>Product of 6 and b is 42</b> means <b>6 x b = 6b = 42</b>');
generator.document.write('<br><b>6 times c plus 8 is equal to 20</b> means <b>6c + 8 = 20</b><br>');

generator.document.write('<h2><b><center>Balancing and Solving for Variables</center></b></h2>');
generator.document.write('To find what the variable equals, we want to use the opposite operation to get the variable by itself. <br>');
generator.document.write('If you see adding, then subtract from both sides. <br>');
generator.document.write('If you see subtraction, then add to both sides. <br>');
generator.document.write('If you see multiplication, then divide from both sides. <br>');
generator.document.write('If you see division, then multiply times both sides. <br>');

generator.document.write('<br>Examples:<br>');
generator.document.write('What is the value of <b>x plus 8 is 12</b>? x + 8 = 12<br>');
generator.document.write('- is the opposite of + then x + 8 - 8 = 12 - 8 and then x + 0 = x = 4<br>');
generator.document.write('So x = 4. <br><br>');

generator.document.write('What is the value of b in <b>6b = 42</b>? 6b = 42 means 6 x b = 42.<br>');
generator.document.write('\367 is the opposite of x.  6 \367 6 x b = 42 \367 6 then 1 x b = b = 42 \367 6 = 7<br>');
generator.document.write('So b = 7.<br><br>');

generator.document.write('Sometimes, there is more than one operation in your equation. ');
generator.document.write('First, do the addition or subtraction first, then do division or multiplication to get the variable alone. ');

generator.document.write('<br><br>Example:<br>');
generator.document.write('6c + 8 = 20<br>');
generator.document.write('6c + 8 - 8 = 20 - 8 Remember, balance the equation by working on both sides!<br>');
generator.document.write('6c = 12<br>');
generator.document.write('6 \367 6 x c = 12 \367 6<br>');
generator.document.write('1 x c = c = 2<br>');

generator.document.write('<center><a href="javascript:self.close()">Close this window.</a></center>');
generator.document.write('</body></html>');
generator.document.close();
}

</script>

<table width="100%" valign="top" align="right" border="0">
<tr>
<td align="left"><font color="brown" size="+2"><b>Balance and Solve the Equation!</b></font></td>
<td align="right">
<a href="javascript:requestHelp();"><font size="-1" color="brown">Help Me!</font></a> |
<a href="mailto:aarontkennedy@gmail.com">;<font size="-1" color="brown">Suggestions</font></a>
</td>
</tr>
</table><br><br><br>

<form name="balance">
<table align="center" width="100%" border="0">
<tr><td width="100%" colspan="4" align="center" id="wordProblemTag"></td></tr>

<tr><td width="100%" colspan="4" align="center"><br></td></tr>

<tr>
<td width="25%" align="left" id="solution1Tag"></td>
<td width="25%" align="left" id="solution2Tag"></td>
<td width="25%" align="left" id="solution3Tag"></td>
<td width="25%" align="left" id="solution4Tag"></td>
</tr>

<tr><td width="100%" colspan="4" align="center"><br></td></tr>

<tr><td width="100%" colspan="4" align="center" id="resultsTag"></td></tr>

<tr>
<td align="center" colspan="4">
<input name="nextQuestionButton" type="button" value="Give Me Another Question!" onClick="requestPrintTest();  return false;">
</td>
</tr>
</table>
</form>

</body>
</html>
```

(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.