/    Sign up×
Community /Pin to ProfileBookmark

I need to make a quiz where i have one array for the questions, one array for the array for the answers
I don’t know how to get it to compare the users answer to the correct answers to display the score and the percentage.

This is what I’ve come up with so far, I don’t know how to get the line breaks to work.

<html>
<body>
<script type=”text/javascript”>
var Questions = new Array(9);
var Questions = [‘What colour was Arsenals First Kit?’,’Arsenals Stadium Name?’,’Arsenals Top Scorer?’,’Arsenal Team Colours?’,’Arsenals Manager?’,’Who did they lose to in the Championsleague Final?’,’What nationalilty is Robin van Persie?’,’Arsenals Captain?’,’Where did Arsenal Finish Last Season?’,’Where are Arsenal based?’];
var Answers = new Array(29);
var Answers = [‘Red’,’White’,’Redcurrent’,’Wembley’,’Emirates Stadium’,’Highbury’,’Wright’,’Henry’,’Bergkamp’,’Red and White’,’Yellow’,’Black’,’Wenger’,’Taylor’,’Rioch’,’Real Madrid’,’Barcelona’,’Liverpool’,’German’,’Dutch’,’French’,’Clichy’,’Vermaelen’,’Fabregas’,’Second’,’Third’,’Fourth’,’Nottingham’,’Birmingham’,’London’];
document.write(Questions[0]|<BR>);
document.write(Answers[0]<BR>);
document.write(Answers[1]<BR>);
document.write(Answers[2]<BR><BR>);

document.write(Questions[1]<BR>);
document.write(Answers[3]<BR>);
document.write(Answers[4]<BR>);
document.write(Answers[5]<BR><BR>);

document.write(Questions[2])<BR>;
document.write(Answers[6]<BR>);
document.write(Answers[7]<BR>);
document.write(Answers[8]<BR><BR>);

document.write(Questions[3]<BR>);
document.write(Answers[9]<BR>);
document.write(Answers[10]<BR>);
document.write(Answers[11]<BR><BR>);

document.write(Questions[4]<BR>);
document.write(Answers[12]<BR>);
document.write(Answers[13]<BR>);
document.write(Answers[14]<BR><BR>);

document.write(Questions[5]<BR>);
document.write(Answers[15]<BR>);
document.write(Answers[16]<BR>);
document.write(Answers[17]<BR><BR>);

document.write(Questions[6]<BR>);
document.write(Answers[18]<BR>);
document.write(Answers[19]<BR>);
document.write(Answers[20]<BR><BR>);

document.write(Questions[7]<BR>);
document.write(Answers[21]<BR>);
document.write(Answers[22]<BR>);
document.write(Answers[23]<BR><BR>);

document.write(Questions[8]<BR>);
document.write(Answers[24]<BR>);
document.write(Answers[25]<BR>);
document.write(Answers[26]<BR><BR>);

document.write(Questions[9]<BR>);
document.write(Answers[27]<BR>);
document.write(Answers[28]<BR>);
document.write(Answers[29]<BR><BR>);

</script>
</body>
</html>

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERAug 01.2010 — ...

This is what I've come up with so far, I don't know how to get the line breaks to work.
[/QUOTE]

This should fix a part of your problem. ?
<i>
</i>document.write(Questions[0]+'&lt;BR&gt;');
document.write(Answers[0]+'&lt;BR&gt;');
document.write(Answers[1]+'&lt;BR&gt;');
document.write(Answers[2]+'&lt;BR&gt;&lt;BR&gt;');


BTW: Should put your script between [ code] and [ /code] tags (without the spaces)

to make it easier for forum members to read your script.
Copy linkTweet thisAlerts:
@Declan1991Aug 01.2010 — And to make your life a little easier, you can use loops and multidimensional arrays (untested, so maybe I've made a typo). If it doesn't work, or you have any questions or want to extend it, ask.var Questions = ['What colour was Arsenals First Kit?','Arsenals Stadium Name?','Arsenals Top Scorer?','Arsenal Team Colours?','Arsenals Manager?','Who did they lose to in the Championsleague Final?','What nationalilty is Robin van Persie?','Arsenals Captain?','Where did Arsenal Finish Last Season?','Where are Arsenal based?'];
var Answers = [['Red','White','Redcurrent'],['Wembley','Emirates Stadium','Highbury'],['Wright','Henry','Bergkamp'],['Red and White','Yellow','Black'],['Wenger','Taylor','Rioch'],['Real Madrid','Barcelona','Liverpool'],['German','Dutch','French'],['Clichy','Vermaelen','Fabregas'],['Second',' Third','Fourth'],['Nottingham','Birmingham','London']];
for (var i = 0; i &lt; Questions.length; i++) {
document.write(Questions[i] + "&lt;br&gt;");
for (var j = 0; j &lt; Answers[i].length; j++) {
document.write(Answers[i][j]+"&lt;br&gt;");
}
document.write("&lt;br&gt;");
}

As for the scores and percentages, you'll need to look at forms, radio buttons in particular.
Copy linkTweet thisAlerts:
@walcott14authorAug 01.2010 — cheers a big help
Copy linkTweet thisAlerts:
@walcott14authorAug 01.2010 — How does the loop work sorry to be a bother utter rookie at this
Copy linkTweet thisAlerts:
@Declan1991Aug 01.2010 — [url=http://www.w3schools.com/JS/js_loop_for.asp]W3schools lesson on for loops[/url].
×

Success!

Help @walcott14 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.20,
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,
)...