tnbrwneyez
Programmer
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!
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!