home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Multimedia Spanish 3
/
ProOne-MultimediaSpanishIII-WinMac.bin
/
mac
/
span3web
/
readfr.js
< prev
next >
Wrap
Text File
|
1998-04-19
|
10KB
|
436 lines
/**** The "indices" array for disk 3 ****/
var indices = new Array( 432, 438, 443, 448, 453, 459 );
var passage; // the passage to read
var question; // the question
var choice; // the "choice" string (possible fill-ins)
var order; // the randomized order of the questions
var instruction; // the instructions
var scoreData; // list of scores on each question
var currProblem;
var nProblems; // number of problems available to be filled
var nTries; // number of tries on a single problem
var nChoices; // number of choices for this question
var answered; // has this problem been answered OK already?
var score; // your score so far
var possible; // total points possible so far
var playSound; // should we send out sound?
var useSavedData;
var nFeedback = 9; // number of feedback pictures
function stringPart( string, start, length)
{
return string.substring( start, start + length );
}
function SetWords( wArray, startPos )
{
var i;
for (i=2; i<SetWords.arguments.length; i++)
{
wArray[startPos + i - 2] = SetWords.arguments[i];
}
}
function SetNumeric( nArray, n )
{
var i;
for (i=0; i < n; i++)
{
nArray[i] = i;
}
}
function Shuffle( nArray, startAt, n )
{
var i, j, swap;
for (i = startAt; i < startAt + n; i++)
{
j = startAt + Math.round(Math.random() * (n - 1));
swap = nArray[i];
nArray[i] = nArray[j];
nArray[j] = swap;
}
}
/*******************************************************************************
Split words from string str into a word array (wordArr).
Words are delimited by the delim argument.
Returns the number of words that were split out.
Note: this function is here because not all browsers have Javascript's
"split" function enabled.
*******************************************************************************/
function SplitWords( str, delim, wordArr ) // for browsers not having a "split" function
{
var fromPos, toPos, n;
n = 0;
fromPos = 0;
toPos = str.indexOf( delim, 0 );
while (toPos >= 0)
{
wordArr[n++] = str.substring( fromPos, toPos );
fromPos = toPos + 1;
while (str.charAt( fromPos ) == ' ')
{
fromPos++;
}
toPos = str.indexOf( delim, fromPos );
}
/* take last word on line and store it */
wordArr[n++] = str.substring( fromPos, str.length );
return n;
}
function UpdateScore( doc )
{
doc.forms[0].score.value = score + " of " + possible;
}
function LoadSound(name)
{
/****** not used in this module
var d;
d = top.soundFrame.document;
d.open();
d.writeln("<html><head></head><body bgcolor=\"#ffffff\">");
d.writeln("<center>");
if (navigator.appVersion.indexOf("Mac") == -1)
{
d.writeln("<embed src=\"" + name + "\" autostart=\"true\" ");
d.writeln(" width=\"144\" height=\"15\" controls=\"smallconsole\">");
}
else
{
d.writeln("<embed src=\"" + name + "\" width=\"144\" height=\"24\" autoplay=\"true\"",
" autostart=\"true\" controls=\"smallconsole\">");
}
d.writeln("</center>");
d.writeln("</body></html>");
d.close();
*************/
}
function WriteProblem( n )
{
var i;
var prob;
var doc;
var choiceWords;
var swap;
prob = order[currProblem]; // save chosen problem in temp. var for ease of reference
i = scoreData[prob];
nTries = (scoreData[prob] == 0) ? 0 : ((i >> 3) & 0x03);
if ((nTries == 1) && (((i >> 3) & 0x04) != 0))
{
nTries++;
}
answered = ((nTries == 2) || ((scoreData[prob] & 0x07) > 0));
doc = top.problemFrame.document;
doc.open();
doc.writeln("<html><head></head><body bgcolor='#ffffff' link='#006600' vlink='#009900' alink='#00ff00'>");
doc.writeln("<div align='center'><img src='pics/barflgs.gif' width='514' height='16'></div>");
doc.writeln(instruction);
doc.writeln("<hr>");
doc.writeln(passage);
doc.writeln("<hr>");
doc.writeln(question[prob], "<p>");
choiceWords = new Array( 6 );
nChoices = SplitWords( choice[prob], "/", choiceWords );
swap = new Array( nChoices );
SetNumeric( swap, nChoices );
Shuffle( swap, 0, nChoices );
for (i = 0; i < nChoices; i++)
{
doc.write("<a href=\"javascript:top.CheckAnswer(", swap[i], ");\">");
doc.writeln(choiceWords[swap[i]], "</a> ");
}
doc.writeln("<table><tr><td valign='top'>");
doc.writeln("<form name='scoreForm'>");
doc.writeln("Problem ", currProblem + (maxProblem-nProblems) + 1, " of ", maxProblem, ".<br>");
doc.writeln("Your score: <input type='text' size='10' name='score' value=''>");
doc.writeln("</form></td><td width='10'></td><td valign='top'>");
doc.writeln("<img name='feedback_img' src=\"pics/mtpic.gif\" width='150' height='75' border='0'>");
doc.writeln("</td></tr></table>");
if (currProblem != 0)
{
UpdateScore( doc );
}
frames[1].location.href = "vbutnX.htm";
/*
if allowing users to back up to previous problems:
if (currProblem == 0)
{
frames[1].location.href = "vbutnN.htm";
}
else if (currProblem == nProblems-1)
{
frames[1].location.href = "vbutnB.htm";
}
else
{
frames[1].location.href = "vbutnBN.htm";
}
*/
doc.writeln("</body></html>");
doc.close();
}
function ShowAnswer( n )
{
var i;
var prob;
var doc;
var choiceWords;
var swap;
doc = top.problemFrame.document;
prob = order[currProblem]; // save chosen problem in temp. var for ease of reference
doc.open();
doc.writeln("<html><head></head><body bgcolor='#ffffff'>");
doc.writeln("Here is the correct answer:");
doc.writeln("<hr>");
doc.writeln(question[prob], "<p>");
doc.writeln("<font color='#990000'><b>");
choiceWords = new Array( 6 );
SplitWords( choice[prob], "/", choiceWords );
i = answerLetters.indexOf(answer.charAt(2*order[currProblem]));
doc.writeln(choiceWords[i]);
doc.writeln("</b></font><p>");
if (currProblem != nProblems-1)
{
frames[1].location.href = "vbutnN.htm";
}
else
{
frames[1].location.href = "vbutnX.htm";
}
doc.writeln("</body></html>");
doc.close();
}
function CheckAnswer( n )
{
var m;
var dest;
if (answered)
{
return;
}
nTries++;
if (nTries == 1)
{
possible += 1;
}
/* find a random congratulatory picture */
m = Math.floor(Math.random() * nFeedback) + 1;
/* check to see if answer is correct; if so, play sound,
and set answered to TRUE to prevent further answers */
if (answer.charAt(2*order[currProblem]) == answerLetters.charAt(n))
{
top.problemFrame.document.feedback_img.src = "pics/good" + m + ".gif";
top.naviFrame.location.href = (currProblem == nProblems-1 ) ?
"vbutnX.htm" : "vbutnN.htm";
answered = true;
score++;
scoreData[order[currProblem]] = 1 + (nTries << 3);
UpdateScore(top.problemFrame.document);
}
else
{
top.problemFrame.document.feedback_img.src = "pics/bad" + m + ".gif";
scoreData[order[currProblem]] = (nTries << 3);
if (nTries == 2 || nChoices == 2)
{
ShowAnswer();
}
}
}
function GoNext()
{
if (currProblem != nProblems-1)
{
nTries = 0;
currProblem++;
WriteProblem( currProblem );
}
}
function GoBack()
{
if (currProblem != 0)
{
currProblem--;
WriteProblem( currProblem );
}
}
function Setup()
{
var i;
question = new Array(maxProblem);
choice = new Array(maxProblem);
order = new Array(maxProblem);
scoreData = new Array(maxProblem)
nTries = 0;
currProblem = 0;
score = 0;
possible = 0;
// set up the problem order array
SetNumeric( order, maxProblem );
if (randomize)
{
Shuffle( order, 0, maxProblem ); // only if the questions should be in random order
}
for (i=0; i < maxProblem; i++)
{
scoreData[i] = 0;
}
SetPrefs();
score = 0;
possible = 0;
currProblem = 0;
Initialize();
WriteProblem(0);
}
function GoIndex()
{
/* set up the cookie. Remember: lessonNumber is ONE-BASED! */
var str, sub;
var prefix, thisLesson, suffix;
var i, n;
var pos;
var letter;
var today = new Date();
var alpha="0abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
today.setYear(today.getYear() + 1);
if (document.cookie != "")
{
str = document.cookie;
oldLen = str.length;
// create a substring of the proper size
sub = "";
n = indices[lessonNumber] - indices[lessonNumber-1];
for (i=0; i<n; i++)
{
sub = sub + ( alpha.charAt(scoreData[i]) );
}
// grab "spanX=" and everything up to this lesson number
pos = str.indexOf("=") + 1;
prefix = str.substring( 0, pos + indices[lessonNumber-1] );
suffix = str.substring( pos+indices[lessonNumber] );
// construct the new cookie
document.cookie =
prefix +
sub +
suffix + ";expires=" + today.toGMTString();
if (document.cookie.length != oldLen)
{
alert("Saved data length error\n" + "old=" + oldLen +
" new=" + document.cookie.length);
}
}
top.location.href = lessonURL + "?prefs=" + playSound + useSavedData;
}
function SoundOn()
{
// playSound = 1;
// top.soundControlFrame.location.href= "soundon.htm";
}
function SoundOff()
{
// playSound = 0;
// top.soundControlFrame.location.href= "soundoff.htm";
}
function SetPrefs()
{
var prefs;
var i, n;
prefs = top.location.search;
prefs = prefs.substring(prefs.indexOf("=") + 1);
playSound = prefs.charAt(0);
if (playSound == "")
{
playSound = "0";
}
else
{
playSound = "1";
}
useSavedData = prefs.charAt(1);
if (useSavedData == "")
{
useSavedData = "0";
}
else
{
useSavedData = "1";
}
SetNumeric( order, maxProblem );
nProblems = maxProblem;
for (i=0; i < maxProblem; i++)
{
scoreData[i] = 0;
}
}