<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 5.50.4522.1800" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Sorry if this has been beaten up before, but I am 
working through the Wrox Beginning Javascript book, and have one thing that I 
dont understand (well, more than one thing, but only one question 
here)</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>the code, from their site, is</FONT></DIV>
<DIV><FONT face=Arial 
size=2>-------------------------------------------------</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&lt;HTML&gt;<BR>&lt;HEAD&gt;<BR>&lt;TITLE&gt;Wrox 
Online Trivia Quiz&lt;/TITLE&gt;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&lt;SCRIPT LANGUAGE=JavaScript&gt;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>var questionNumber;</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>function answerCorrect(questionNumber, 
answer)<BR>{<BR>&nbsp;&nbsp; // declare a variable to hold return 
value<BR>&nbsp;&nbsp; var correct = false;<BR>&nbsp;&nbsp; <BR>&nbsp;&nbsp; // 
if answer provided is same as correct answer then correct variable is 
true<BR>&nbsp;&nbsp; if (answer == 
answers[questionNumber])<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; correct = 
true;<BR>&nbsp;&nbsp; <BR>&nbsp;&nbsp; // return whether the answer was correct 
(true or false)<BR>&nbsp;&nbsp; return correct;<BR>}<BR>function 
getQuestion()<BR>{<BR>&nbsp;&nbsp; questionNumber = Math.floor(Math.random() * 
(questions.length));<BR>&nbsp;&nbsp; var questionHTML = "&lt;P&gt;" + 
questions[questionNumber][0] + "&lt;/P&gt;";<BR>&nbsp;&nbsp; var questionLength 
= questions[questionNumber].length;<BR>&nbsp;&nbsp; var 
questionChoice;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp; for (questionChoice = 1;questionChoice 
&lt; questionLength;questionChoice++)<BR>&nbsp;&nbsp; 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; questionHTML = questionHTML + "&lt;INPUT 
TYPE=radio NAME=radQuestionChoice"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if 
(questionChoice == 1)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; questionHTML = 
questionHTML + " CHECKED";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; questionHTML = questionHTML + 
"&gt;";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; questionHTML = questionHTML + 
questions[questionNumber][questionChoice];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
questionHTML = questionHTML + "&lt;BR&gt;";<BR>&nbsp;&nbsp; }</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp; document.QuestionForm.txtQNumber.value 
= questionNumber + 1;<BR>&nbsp;&nbsp; return questionHTML;<BR>}</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>function buttonCheckQ_onclick() 
<BR>{<BR>&nbsp;&nbsp; var answer = 0;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp; while 
(document.QuestionForm.radQuestionChoice[answer].checked != true)&nbsp;&nbsp; 
<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; answer++;<BR>&nbsp;&nbsp; 
}</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp; answer = String.fromCharCode(65 + 
answer);</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp; if 
(answerCorrect(questionNumber,answer) == true)<BR>&nbsp;&nbsp; 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert("You got it right");<BR>&nbsp;&nbsp; 
}<BR>&nbsp;&nbsp; else<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
alert("You got it wrong");<BR>&nbsp;&nbsp; }</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp; 
window.location.reload();<BR>}</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&lt;/SCRIPT&gt;<BR>&lt;/HEAD&gt;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&lt;BODY&gt;<BR>&lt;SCRIPT 
LANGUAGE=JavaScript&gt;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>// Questions variable will holds questions<BR>var 
questions = new Array();<BR>var answers = new Array();</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>// define question 1 <BR>questions[0] = new 
Array();</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>// the question<BR>questions[0][0] = "The Beatles 
were";</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>// first choice<BR>questions[0][1] = "A sixties 
rock group from Liverpool";</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>// second choice<BR>questions[0][2] = "Four 
musically gifted insects";</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>// third choice<BR>questions[0][3] = "I don't know 
- can I have the questions on Baseball please";</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>// assign answer for question 1 <BR>answers[0] = 
"A";</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>// define question 2<BR>questions[1] = new 
Array();<BR>questions[1][0] = "Homer Simpson's favorite food 
is";<BR>questions[1][1] = "Fresh salad";<BR>questions[1][2] = 
"Doughnuts";<BR>questions[1][3] = "Bread and water";<BR>questions[1][4] = 
"Apples";</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>// assign answer for question 2<BR>answers[1] = 
"B";</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>// define question 3<BR>questions[2] = new 
Array();<BR>questions[2][0] = "Lisa Simpson plays which musical 
instrument";<BR>questions[2][1] = "Clarinet";<BR>questions[2][2] = 
"Oboe";<BR>questions[2][3] = "Saxophone";<BR>questions[2][4] = "Tubular Bells"; 
</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>// assign answer for question 3 <BR>answers[2] = 
"C";</FONT></DIV>
<DIV>&nbsp;</DIV><FONT face=Arial size=2>
<DIV><BR>&lt;/SCRIPT&gt;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&lt;FORM NAME="QuestionForm"&gt;</DIV>
<DIV>&nbsp;</DIV>
<DIV>Question<BR>&lt;INPUT TYPE="text" NAME=txtQNumber SIZE=1&gt;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&lt;SCRIPT LANGUAGE=JavaScript&gt;<BR>&nbsp;&nbsp; 
document.write(getQuestion());<BR>&lt;/SCRIPT&gt;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&lt;INPUT TYPE="button" VALUE="Check Question" NAME=buttonCheckQ 
<BR>&nbsp;&nbsp; onclick="return 
buttonCheckQ_onclick()"&gt;<BR>&lt;/FORM&gt;</DIV>
<DIV>&nbsp;</DIV>
<DIV><BR>&lt;/BODY&gt;<BR>&lt;/HTML&gt;<BR>---------------------------</DIV>
<DIV>this is from chapter 6, if anyone has the book and wants to read about the 
intent of the page.</DIV>
<DIV>&nbsp;</DIV>
<DIV>My question is:&nbsp; the number that appears in the text box at the top of 
the page is correct the first time the page is loaded, but no matter how many 
times I reload the number stays the same.&nbsp; Different questions from the 
question array do appear, and an alert shows that the value of questionNumber 
does change at random.&nbsp;</DIV>
<DIV>Q:&nbsp; why does the indicated number NOT change when the page is 
refreshed.</DIV>
<DIV>&nbsp;</DIV>
<DIV>This happens in IE 4 and 5.5, have not tried on a Netscape machine.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Thanks, looking forward to a lot of learning from the list, hoping to 
contribute something useful someday</FONT></DIV></BODY></HTML>