var Feedback = '';
var CorrectWellDone = 'Correct!';
var TheseAnswersToo = 'Also correct:';
var ThisMuchIsCorrect = 'This much of your answer is correct:';
var TheseWordsAppear = 'These words from your answer are correct:';
var DeadWrong = 'Sorry! Try again.';
var EnterGuess = 'Please enter a guess.';
var GiveHint = 'Hint:';
var TheseCorrect = 'Correct answers:';
var CaseSensitive = 'False';
var platform = 'win';
var CurrentQ = 0;
var RealGuess = '';
var DoneArray = new Array();
DoneArray[1] = 0;
DoneArray[2] = 0;
DoneArray[3] = 0;
DoneArray[4] = 0;
DoneArray[5] = 0;
WinAnswers = new Array();
AnswerList = new Array();
var WinLowerString='abcdefghijklmnopqrstuvwxyz%9A%9C%E0%E1%E2%E3%E4%E5%E6%E7%E8%E9%EA%EB%EC%ED%EE%EF%F0%F1%F2%F3%F4%F5%F6%F8%F9%FA%FB%FC%FD%FE%FF';
var WinUpperString='ABCDEFGHIJKLMNOPQRSTUVWXYZ%8A%8C%C0%C1%C2%C3%C4%C5%C6%C7%C8%C9%CA%CB%CC%CD%CE%CF%D0%D1%D2%D3%D4%D5%D6%D8%D9%DA%DB%DC%DD%DE%9F';
var LowerString = '';
var UpperString = '';
var i = 0;
WinAnswers[1] = 'If my daughter eats too much chocolate, she gets sick.';
WinAnswers[2] = 'If she eats too much chocolate, my daughter gets sick.';
WinAnswers[3] = 'My daughter gets sick if she eats too much chocolate.';
WinAnswers[4] = '';
WinAnswers[5] = 'Ice floats if you drop it in water.';
WinAnswers[6] = 'If you drop ice in water, it floats.';
WinAnswers[7] = 'If you drop it in water, ice floats.';
WinAnswers[8] = '';
WinAnswers[9] = 'If you don\'t eat, you die.';
WinAnswers[10] = 'You die if you don\'t eat.';
WinAnswers[11] = 'If you do not eat, you die.';
WinAnswers[12] = 'You die if you do not eat.';
WinAnswers[13] = 'If there is no rain, the grass doesn\'t grow.';
WinAnswers[14] = 'The grass doesn\'t grow if there is no rain.';
WinAnswers[15] = 'If there is no rain, the grass does not grow.';
WinAnswers[16] = 'The grass does not grow if there is no rain.';
WinAnswers[17] = 'Iron rusts if it gets wet.';
WinAnswers[18] = 'If it gets wet, iron rusts.';
WinAnswers[19] = 'If iron gets wet, it rusts.';
WinAnswers[20] = '';
ISOUpperChars = '%80%81%82%83%84%85%86%87%88%89%8A%8B%8C%8D%8E%8F%90%91%92%93%94%95%96%97%98%99%9A%9B%9C%9D%9E%9F';
ISOUpperChars += '%A0%A1%A2%A3%A4%A5%A6%A7%A8%A9%AA%AB%AC%AD%AE%AF%B0%B1%B2%B3%B4%B5%B6%B7%B8%B9%BA%BB%BC%BD%BE%BF';
ISOUpperChars += '%C0%C1%C2%C3%C4%C5%C6%C7%C8%C9%CA%CB%CC%CD%CE%CF%D0%D1%D2%D3%D4%D5%D6%D7%D8%D9%DA%DB%DC%DD%DE%DF';
ISOUpperChars += '%E0%E1%E2%E3%E4%E5%E6%E7%E8%E9%EA%EB%EC%ED%EE%EF%F0%F1%F2%F3%F4%F5%F6%F7%F8%F9%FA%FB%FC%FD%FE%FF';
ISOUpperChars = unescape(ISOUpperChars);
platform = 'win';
for (i = 1; i < WinAnswers.length; i++){
AnswerList[i] = unescape(WinAnswers[i]);
LowerString = unescape(WinLowerString);
UpperString = unescape(WinUpperString);
}
function ConvertCase(InString, Direction){
var FromString = '';
var ToString = '';
if (Direction == 0){
FromString = UpperString;
ToString = LowerString;
}
else{
FromString = LowerString;
ToString = UpperString;
}
var i = 0;
j = 0;
var OutString = '';
for (i=0; i
j = FromString.indexOf(InString.charAt(i));
OutString += ToString.charAt(j);
}
else{
OutString += InString.charAt(i);
}
}
return OutString;
}
function TrimString(InString){
var x = 0
if (InString.length != 0) {
while ((escape(InString.charAt(InString.length - 1)) == '%20') || (escape(InString.charAt(InString.length - 1)) == '%0A') || (escape(InString.charAt(InString.length - 1)) == '%0D')){
InString = InString.substring(0, InString.length - 1)
}
while ((escape(InString.charAt(0)) == '%20') || (escape(InString.charAt(0)) == '%0A') || (escape(InString.charAt(0)) == '%0D')){
InString = InString.substring(1, InString.length)
}
while (InString.indexOf(' ') != -1) {
x = InString.indexOf(' ')
InString = InString.substring(0, x) + InString.substring(x+1, InString.length )
}
return InString
}
else {
return ''
}
}
function RemovePunctuation(InString){
var OutString = '';
for (i=0; i
else {
OutString += InString.charAt(i);
}
}
return OutString;
}
function CheckBeginning(Guess, Answer){
var OutString = '';
var i = 0;
while (Guess.charAt(i) == Answer.charAt(i)) {
OutString += RealGuess.charAt(i);
i++;
}
return OutString;
}
function CheckEnd(Guess, Answer){
var i=0;
var j=0;
var OutString='';
i = Guess.length;
j = Answer.length;
while (Guess.charAt(i) == Answer.charAt(j)){
OutString = RealGuess.charAt(i) + OutString;
i--;
j--;
}
return OutString;
}
function FindLongest(First, Second, Third, Fourth){
var Longest = 0;
var LongString = '';
Longest = 4;
LongString = Fourth;
if (Third.length >= LongString.length){
Longest = 3;
LongString = Third;
}
if (Second.length >= LongString.length){
Longest = 2;
LongString = Second;
}
if (First.length >= LongString.length){
Longest = 1;
LongString = First;
}
return Longest;
}
function CheckWords(Guess, Answer){
var Start = 0;
var End = 0;
var LoopCounter = 0;
var ReturnList = '';
var i = 0;
var j = 0;
GuessWords = new Array();
AnswerWords = new Array();
Guess = RemovePunctuation(Guess);
Answer = RemovePunctuation(Answer);
while (Guess.indexOf(' ', Start) > -1) {
End = Guess.indexOf(' ', Start);
GuessWords[LoopCounter] = ConvertCase(Guess.substring(Start, End), 0);
LoopCounter++;
Start = End + 1;
}
GuessWords[LoopCounter] = ConvertCase(Guess.substring(Start, Guess.length), 0);
Start = 0;
LoopCounter = 0;
while (Answer.indexOf(' ', Start) > -1) {
End = Answer.indexOf(' ', Start);
AnswerWords[LoopCounter] = Answer.substring(Start, End);
LoopCounter++;
Start = End + 1;
}
AnswerWords[LoopCounter] = Answer.substring(Start, Answer.length);
ReturnList = '';
for (i = 0; i < GuessWords.length; i++){
for (j = 0; j < AnswerWords.length; j++){
if (GuessWords[i] == ConvertCase(AnswerWords[j], 0)){
ReturnList = ReturnList + AnswerWords[j] + ', ' ;
AnswerWords[j] = '';
break;
}
}
}
if (ReturnList.length > 0){
ReturnList = ReturnList.substring(0, ReturnList.length - 2);
}
return ReturnList;
}
function CheckAnswer(Guess, Answer1, Answer2, Answer3, Answer4, QNum){
var i = 0;
var j = 0;
var Beginning = '';
var End = '';
var BestMatch = 0;
var OtherCorrect = '';
var CorrectBit = '';
var CorrectWords = '';
Temp = new Array(4);
Answers = new Array(4);
Feedback = '';
OtherCorrect = '';
CorrectBit = '';
AllDone = true;
if (Guess.length < 1){
WriteFeedback(EnterGuess);
return;
}
Guess = TrimString(Guess);
RealGuess = Guess;
Answers[1] = Answer1;
Answers[2] = Answer2;
Answers[3] = Answer3;
Answers[4] = Answer4;
if (CaseSensitive=='False'){
Guess = ConvertCase(Guess, 1);
for (i=1; i<5; i++){
Answers[i] = ConvertCase(Answers[i], 1);
}
}
for (i = 1; i < 5; i++){
if (Guess == Answers[i]){
Feedback = CorrectWellDone;
DoneArray[QNum] = 1;
for (j = 1; j < DoneArray.length; j++){
if (DoneArray[j] == 0){
AllDone = false;
}
}
if (AllDone == true){
}
BestMatch = i;
for (j = 1; j < 5; j++){
if (j != BestMatch) {
OtherCorrect = OtherCorrect + ' ' + Answers[j] + '
';
}
}
if (OtherCorrect.length > 15){
Feedback = Feedback + ' ' + TheseAnswersToo + '
' + OtherCorrect;
}
WriteFeedback(Feedback);
return;
}
}
for (i = 1; i < 5; i++){
Temp[i] = CheckBeginning(Guess, Answers[i]);
}
BestMatch = FindLongest(Temp[1], Temp[2], Temp[3], Temp[4]);
Beginning = Temp[BestMatch];
if (Beginning.length > 0) {
CorrectBit = Beginning + '... ';
Temp[BestMatch] = CheckEnd(Guess, Answers[BestMatch]);
if (Temp[BestMatch].length > 3){
CorrectBit = CorrectBit + ' ...' + Temp[BestMatch];
}
}
else {
BestMatch = 0;
for (i = 1; i < 5; i++){
Temp[i] = CheckEnd(Guess, Answers[i]);
}
BestMatch = FindLongest(Temp[1], Temp[2], Temp[3], Temp[4]);
End = Temp[BestMatch];
if (End.length > 3) {
CorrectBit = CorrectBit + '... ' + Temp[BestMatch];
}
}
if (CorrectBit.length > 0){
Feedback = ThisMuchIsCorrect + ' ' + CorrectBit + '
';
CorrectWords = CheckWords(Guess, Answers[BestMatch]);
if (CorrectWords.length > 0){
Feedback = TheseWordsAppear + ' ' + CorrectWords + '
' + Feedback;
}
}
else{
for (i = 1; i <5; i++){
if (Answers[i].length > 0){
Temp[i] = CheckWords(Guess, Answers[i]);}
else {
Temp[i] = '';}
}
BestMatch = FindLongest(Temp[1], Temp[2], Temp[3], Temp[4]);
if (Temp[BestMatch].length > 0){
Feedback = TheseWordsAppear + ' ' + Temp[BestMatch];
}
else {
Feedback = DeadWrong;
}
}
WriteFeedback(Feedback);
}
function GetHint(Guess, Answer1, Answer2, Answer3, Answer4, QNum){
var i = 0;
var j = 0;
var Beginning = '';
var End = '';
var BestMatch = 0;
var OtherCorrect = '';
var CorrectBit = '';
var CorrectWords = '';
var AllDone = true;
Temp = new Array(4);
Answers = new Array(4);
RealAnswers = new Array(4);
Feedback = '';
OtherCorrect = '';
CorrectBit = '';
Guess = TrimString(Guess);
RealGuess = Guess;
Answers[1] = Answer1;
Answers[2] = Answer2;
Answers[3] = Answer3;
Answers[4] = Answer4;
RealAnswers[1] = Answer1;
RealAnswers[2] = Answer2;
RealAnswers[3] = Answer3;
RealAnswers[4] = Answer4;
if (CaseSensitive=='False'){
Guess = ConvertCase(Guess, 1);
for (i=1; i<5; i++){
Answers[i] = ConvertCase(Answers[i], 1);
}
}
if (Guess.length == 0){
Feedback = GiveHint + ' ' + RealAnswers[1].charAt(0);
WriteFeedback(Feedback);
return;
}
for (i = 1; i < 5; i++){
if (Guess == Answers[i]){
Feedback = CorrectWellDone;
DoneArray[QNum] = 1;
for (j = 1; j < DoneArray.length; j++){
if (DoneArray[j] == 0){
AllDone = false;
}
}
if (AllDone == true){
}
BestMatch = i;
for (j = 1; j < 5; j++){
if (j != BestMatch) {
OtherCorrect = OtherCorrect + ' ' + Answers[j] + '
';
}
}
if (OtherCorrect.length > 15){
Feedback += ' ' + TheseAnswersToo + ' ' + '
' + OtherCorrect;
}
WriteFeedback(Feedback);
return;
}
}
for (i = 1; i < 5; i++){
Temp[i] = CheckBeginning(Guess, Answers[i]);
}
BestMatch = FindLongest(Temp[1], Temp[2], Temp[3], Temp[4]);
Beginning = Temp[BestMatch];
if (Beginning.length > 0) {
CorrectBit = RealAnswers[BestMatch].charAt(Temp[BestMatch].length);
if (CorrectBit == ' ') {
CorrectBit += RealAnswers[BestMatch].charAt(Temp[BestMatch].length + 1)
}
CorrectBit = Beginning + CorrectBit;
Feedback = GiveHint + ' ' + CorrectBit;
WriteFeedback(Feedback);
return;
}
else {
for (i = 1; i < 5; i++){
Temp[i] = CheckEnd(Guess, Answers[i]);
}
BestMatch = FindLongest(Temp[1], Temp[2], Temp[3], Temp[4]);
End = Temp[BestMatch];
if (End.length > 3) {
CorrectBit = RealAnswers[BestMatch].charAt(0);
Feedback = GiveHint + ' ' + CorrectBit;
WriteFeedback(Feedback);
return;
}
else {
for (i = 1; i <5; i++){
if (Answers[i].length > 0){
Temp[i] = CheckWords(Guess, Answers[i]);}
else {
Temp[i] = '';}
}
BestMatch = FindLongest(Temp[1], Temp[2], Temp[3], Temp[4]);
if (Temp[BestMatch].length > 0){
CorrectBit = RealAnswers[BestMatch].charAt(0);
Feedback = GiveHint + ' ' + CorrectBit;
WriteFeedback(Feedback);
return;
}
else {
Feedback = GiveHint + ' ' + RealAnswers[1].charAt(0);
WriteFeedback(Feedback);
return;
}
}
}
}
function Check(Guess, QNum){
var x = 0;
CurrentQ = QNum;
x = (QNum * 4) - 3;
CheckAnswer(Guess, AnswerList[x], AnswerList[x+1], AnswerList[x+2], AnswerList[x+3], QNum);
}
function Hint(Guess, QNum){
var x = 0;
CurrentQ = QNum;
x = (QNum * 4) - 3;
GetHint(Guess, AnswerList[x], AnswerList[x+1], AnswerList[x+2], AnswerList[x+3], QNum);
}
function ShowAnswer(QNum){
var x = 0;
var i = 0;
CurrentQ = QNum;
x = (QNum * 4) - 3;
Feedback = TheseCorrect + '
';
for (i = x; i < x + 4; i++){
Feedback += AnswerList[i] + '
';
}
WriteFeedback(Feedback);
}
function WriteFeedback(Feedback) {
var x=document.getElementById("xfeedback")
var e = window.event
getMouseXY(e)
//x.style.top="300px"
//x.style.left="100px"
//alert(mY)
x.style.left=mX+20+"px"
x.style.top=mY-25+"px"
x.style.visibility="visible"
x.innerHTML=Feedback
//Object.style.visibility=visible|hidden|collapse
//alert(Feedback);
}
function getMouseXY(e) {
var IE = document.all?true:false;
if (IE) { // grab the x-y pos.s if browser is IE
mX = document.body.scrollLeft;
mY = document.body.scrollTop;
}
else { // grab the x-y pos.s if browser is NS
mX = e.pageX;
mY = e.pageY;
}
}
function HideFeedback() {
document.getElementById("xfeedback").style.visibility="hidden" ;
}