"matching quiz" type JS

D

Dennis M

Hi all,

I'm looking for a "matching quiz" type of JS for my site. Let's say you
have 100 song titles and 100 lyric snippets from those songs in a
corresponding random list, and you want to match the correct lyrics to the
song titles by entering the correct number from the lyric snippets in a box
beside song titles. Then the JS should be able to score the number of
correct entries. Could someone please give me the JS for this, or point me
to a website with it? Thanks!
 
B

Bart Van der Donck

Dennis said:
I'm looking for a "matching quiz" type of JS for my site. Let's say you
have 100 song titles and 100 lyric snippets from those songs in a
corresponding random list, and you want to match the correct lyrics to the
song titles by entering the correct number from the lyric snippets in a box
beside song titles. Then the JS should be able to score the number of
correct entries. Could someone please give me the JS for this, or point me
to a website with it? Thanks!

var snippet = ['You know I love you', 'We can only lose',
'All my troubles seemed so far away']
var song = ['Love me do', 'Light my fire', 'Yesterday']

var list = '<select name="box" size="1">'
for (var i=0; i<song.length; ++i)
list+='<option value="' + song + '">' + song + '</option>'
list+='</select>'

for (var i=0; i<snippet.length; ++i)
document.write(snippet +': ' + list + '<hr>')
document.write('<input type="button" value="Score" onClick="r()">')

function r() {
var score = 0
var answers = document.getElementsByName('box')
for (var i=0; i < answers.length; ++i)
if (answers.value == song) ++score
alert('Score: ' + score + '/' + snippet.length)
}

Hope this helps,
 
D

Dennis M

Bart Van said:
Dennis said:
I'm looking for a "matching quiz" type of JS for my site. Let's say you
have 100 song titles and 100 lyric snippets from those songs in a
corresponding random list, and you want to match the correct lyrics to the
song titles by entering the correct number from the lyric snippets in a box
beside song titles. Then the JS should be able to score the number of
correct entries. Could someone please give me the JS for this, or point me
to a website with it? Thanks!

var snippet = ['You know I love you', 'We can only lose',
'All my troubles seemed so far away']
var song = ['Love me do', 'Light my fire', 'Yesterday']

var list = '<select name="box" size="1">'
for (var i=0; i<song.length; ++i)
list+='<option value="' + song + '">' + song + '</option>'
list+='</select>'

for (var i=0; i<snippet.length; ++i)
document.write(snippet +': ' + list + '<hr>')
document.write('<input type="button" value="Score" onClick="r()">')

function r() {
var score = 0
var answers = document.getElementsByName('box')
for (var i=0; i < answers.length; ++i)
if (answers.value == song) ++score
alert('Score: ' + score + '/' + snippet.length)
}

Hope this helps,


How cool, you even used Beatles examples! Thank you very much kind sir! :)
 
D

Dennis M

BTW Bart, can you give me a little more help on how to set up the HTML part
for the song titles and lyric snippets? I already have several "multiple
choice" quizzes on my site, but I can't figure out how to transpose the
HTML for those kind of quizzes into HTML for the matching quiz. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,244
Latest member
cryptotaxsoftware12

Latest Threads

Top