dcsimg

Lesson 49: The Script and Its Effect



The Script

<SCRIPT LANGUAGE="javascript">

function Gradeit()
{

function getselectedIndex(){
return document.quiz.q1.selectedIndex
return document.quiz.q2.selectedIndex
return document.quiz.q3.selectedIndex
return document.quiz.q4.selectedIndex
return document.quiz.q5.selectedIndex
}

var Answers=new Array(1,2,2,3,1)
var UserAnswers = new Array(document.quiz.q1.selectedIndex,document.quiz.q2.selectedIndex,document.quiz.q3.selectedIndex,document.quiz.q4.selectedIndex,document.quiz.q5.selectedIndex)
var count0 = 0

if (Answers[0] == UserAnswers[0])
{count0 = count0 + 1}
else
{count0 = count0}

if (Answers[1] == UserAnswers[1])
{count1 = count0 + 1}
else
{count1 = count0}

if (Answers[2] == UserAnswers[2])
{count2 = count1 + 1}
else
{count2 = count1}

if (Answers[3] == UserAnswers[3])
{count3 = count2 + 1}
else
{count3 = count2}

if (Answers[4] == UserAnswers[4])
{count4 = count3 + 1}
else
{count4 = count3}

alert("You got " + count4 + "/5 right.")

}
</SCRIPT>

<FORM NAME="quiz">

<b>#1: What is 2 + 2?</b>
<SELECT NAME="q1">
<OPTION SELECTED>Choose One
<OPTION>4
<OPTION>2
<OPTION>22
</SELECT>
<P>

<b>#2: Trees have: </b>
<SELECT NAME="q2">
<OPTION SELECTED>Choose One
<OPTION>engines
<OPTION>leaves
<OPTION>dogs
</SELECT>
<P>

<b>#3: This book is about:</b>
<SELECT NAME="q3">
<OPTION SELECTED>Choose One
<OPTION>Nothing
<OPTION>JavaScript
<OPTION>Love and Romance
</SELECT>
<P>

<b>#4: Who sang "Yesterday"?</b>
<SELECT NAME="q4">
<OPTION SELECTED>Choose One
<OPTION>Van Halen
<OPTION>Metallica
<OPTION>The Beatles
</SELECT>
<P>

<b>#5 What color is blue?</b>
<SELECT NAME="q5">
<OPTION SELECTED>Choose One
<OPTION>blue
<OPTION>green
<OPTION>off-blue
</SELECT>
<P>

<INPUT TYPE="button" VALUE="Grade Me" onClick="Gradeit()">

</FORM>

 

The Script's Effect

#1: What is 2 + 2?

#2: Trees have:

#3: This book is about:

#4: Who sang "Yesterday"?

#5 What color is blue?

 

Back to the Index Page