wintercookie
MIS
I'm making a test using forms and I type up the javascript that will keep track of the score. Everytime a person submits the score will add up but when they resubmit the score does not start at zero. It just adds to the old score. I want to make my score var a global variable so I can use the score for another function this is what I got so far:
<script type="text/javascript">
var score = 0;
function validate()
{
x1=document.myForm
a1=x1.aa.value
a2=x1.ab.value
a3=x1.ac.value
a4=x1.ad.value
a5=x1.ae.value
a6=x1.af.value
a7=x1.ag.value
a8=x1.ah.value
if (a1 == ""
{
alert("Please fill in something in Question 1"
}
else
{
if (a1 == "pixels" || a1 == "pixel" || a1 == "Pixel" || a1 == "Pixels" || a1 == "PIXEL" || a1 == "PIXELS"
{
alert(a1 + " is the right answer"
score = score + 1;
}
else
{
alert(a1 + " is NOT the right answer for Question 1"
}
}
if (a2 == ""
{
alert("Please fill in something in Question 2"
}
else
{
if (a2 == "Debug" || a2 == "DEBUG" || a2 == "debug" || a2 == "Debugging" || a2 == "DEBUGGING" || a2 == "debugging"
{
alert(a2 + " is the right answer"
score = score + 1;
}
else
{
alert(a2 + " is NOT the right answer for Question 2"
}
}
if (a3 == ""
{
alert("Please fill in something in Question 3"
}
else
{
if (a3 == "byte" || a3 == "Byte" || a3 == "BYTE"
{
alert(a3 + " is the right answer"
score = score + 1;
}
else
{
alert(a3 + " is NOT the right answer for Question 3"
}
}
{
if (a4 == "ONE" || a4 == "one" || a4 == "One"
{
alert(a4 + " is the right answer"
score = score + 1;
}
else
{
alert(a4 + " is NOT the right answer for Question 4"
}
}
{
if (a5 == "UNIX" || a5 == "Unix" || a5 == "Unix"
{
alert(a5 + " is the right answer"
score = score + 1;
}
else
{
alert(a5 + " is NOT the right answer for Question 5"
}
}
{
if (a6 == "programs" || a6 == "program" || a6 == "Programs" || a6 == "PROGRAMS" || a6 == "PROGRAM" || a6 == "Program" )
{
alert(a6 + " is the right answer"
score = score + 1;
}
else
{
alert(a6 + " is NOT the right answer for Question 6"
}
}
{
if (a7 == "virus" || a7 == "VIRUS" || a7 == "Virus"
{
alert(a7 + " is the right answer"
score = score + 1;
}
else
{
alert(a7 + " is NOT the right answer for Question 7"
}
}
{
if (a8 == "no" || a8 == "NO" || a8 == "No"
{
alert(a8 + " is the right answer"
score = score + 1;
}
else
{
alert(a8 + " is NOT the right answer for Question 8"
}
}
if (score > 0)
{
alert("Your total score is: " + score);
}
if (score > 6)
{
document.bgColor="ff99ff";
}
totalscore()
return false;
}
}
<script type="text/javascript">
var score = 0;
function validate()
{
x1=document.myForm
a1=x1.aa.value
a2=x1.ab.value
a3=x1.ac.value
a4=x1.ad.value
a5=x1.ae.value
a6=x1.af.value
a7=x1.ag.value
a8=x1.ah.value
if (a1 == ""
{
alert("Please fill in something in Question 1"
}
else
{
if (a1 == "pixels" || a1 == "pixel" || a1 == "Pixel" || a1 == "Pixels" || a1 == "PIXEL" || a1 == "PIXELS"
{
alert(a1 + " is the right answer"
score = score + 1;
}
else
{
alert(a1 + " is NOT the right answer for Question 1"
}
}
if (a2 == ""
{
alert("Please fill in something in Question 2"
}
else
{
if (a2 == "Debug" || a2 == "DEBUG" || a2 == "debug" || a2 == "Debugging" || a2 == "DEBUGGING" || a2 == "debugging"
{
alert(a2 + " is the right answer"
score = score + 1;
}
else
{
alert(a2 + " is NOT the right answer for Question 2"
}
}
if (a3 == ""
{
alert("Please fill in something in Question 3"
}
else
{
if (a3 == "byte" || a3 == "Byte" || a3 == "BYTE"
{
alert(a3 + " is the right answer"
score = score + 1;
}
else
{
alert(a3 + " is NOT the right answer for Question 3"
}
}
{
if (a4 == "ONE" || a4 == "one" || a4 == "One"
{
alert(a4 + " is the right answer"
score = score + 1;
}
else
{
alert(a4 + " is NOT the right answer for Question 4"
}
}
{
if (a5 == "UNIX" || a5 == "Unix" || a5 == "Unix"
{
alert(a5 + " is the right answer"
score = score + 1;
}
else
{
alert(a5 + " is NOT the right answer for Question 5"
}
}
{
if (a6 == "programs" || a6 == "program" || a6 == "Programs" || a6 == "PROGRAMS" || a6 == "PROGRAM" || a6 == "Program" )
{
alert(a6 + " is the right answer"
score = score + 1;
}
else
{
alert(a6 + " is NOT the right answer for Question 6"
}
}
{
if (a7 == "virus" || a7 == "VIRUS" || a7 == "Virus"
{
alert(a7 + " is the right answer"
score = score + 1;
}
else
{
alert(a7 + " is NOT the right answer for Question 7"
}
}
{
if (a8 == "no" || a8 == "NO" || a8 == "No"
{
alert(a8 + " is the right answer"
score = score + 1;
}
else
{
alert(a8 + " is NOT the right answer for Question 8"
}
}
if (score > 0)
{
alert("Your total score is: " + score);
}
if (score > 6)
{
document.bgColor="ff99ff";
}
totalscore()
return false;
}
}