Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

location href 1

Status
Not open for further replies.

tnbrwneyez

Programmer
Oct 2, 2004
19
US
I need to add a location.href statement and a conditional
assignment operator to the code so that three correct answers will send the user to a "congratulations" page. If users answer fewer than three questions correctly, send them to a "better luck next time" page.
<SCRIPT LANGUAGE="JavaScript">
<!--

var numCorrect = 0;

function takeTest() {
var response="";
var points = 0;

var q1 = "What company developed JavaScript?";
var a1 = "NETSCAPE";

var q2 = "Using JavaScript operator precedence,\n what is the result of the following expression? 2 + 4 * 6";
var a2 = 26;

var q3 = "With what object-oriented programming language\n is JavaScript often compared and confused?";
var a3 = "JAVA";

response = prompt(q1,"");
if (response) points = runningTotal((response.toUpperCase() == a1) ? 1 : 0);
alert(points);

response = prompt(q2,"");
if (response) points = runningTotal((response == a2) ? 1 : 0);
alert(points);

response = prompt(q3,"");
if (response) points = runningTotal((response.toUpperCase() == a3) ? 1 : 0);
alert("You answered a total of " + points + " correctly.");

// Add a location.href statement used with the conditional operator

numCorrect = 0;
points = 0;
}

function runningTotal(i) {
numCorrect+=i;
return numCorrect;
}

// -->
</SCRIPT>

Thanks!
 
//points is assumed to be the vairable holdin the scores:

if(points<3)
{
location.href="falied.html"
}
else
{
location.href="congrats.html"
}

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top