/    Sign up×
Community /Pin to ProfileBookmark

Javascript quiz. Need help adding the answers to questions asked

My code goes through the answer function (below) and it determins if you answered green. If you answered green a popup says correct other wise incorrect. How can I modify my code so that I can add multiple answers for different questions.Example
q1 answer = green
q2 answer = blue
.
.
q20 answer = Friday

Here is my .js code

[CODE]
var n = 16; // modify this for number of seconds to answer
document.getElementById( ‘time’).value = “Answer in ” + n + ” seconds”;
var i = setInterval(‘count()’ , 1000);
var tooLate;

function count() {
tooLate = 0;
n–;
if(n >=0) {
document.getElementById( ‘time’).value = “Answer in ” + n + ” seconds”;
}
else {
clearInterval(i);

alert(“Too late!”);
if(document.getElementById( ‘answer’).value == correct){
tooLate = 1;
}
}

function answer() {

var correct = “green”; // This is the correct answer
if (tooLate == 0) {
if(document.getElementById( ‘answer’).value == correct) {
clearInterval(i);
alert(“Right Answer with ” + n + ” seconds remaining”);
}
else{
clearInterval(i);
alert(“Incorrect! The answer was ” + correct);
}
}

submitform();

//submit form
function submitform()
{
document.forms[“myform”].submit();
}

}
[/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@tirnaApr 05.2010 — Am I seeing double ??

Your post looks exactly the same as the one that was replied to in another thread.

[URL]http://www.webdeveloper.com/forum/showthread.php?p=1079246#post1079246[/URL]
×

Success!

Help @connollyc4 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...