I usually program in ActionScript and haven't worked with any JavaScript for a really long time. So I have pasted a few chunks of code together and would like to get a bit of help if it is all right. I'm making a very simple quiz and need a bit of help with a few things.
The first thing is making sure when the code is randomized that just the first result doesn't get repeated twice.
The second thing is when I push the enter button the quiz says correct when an answer is correct but I want it to ask another question instead.
Any help is greatly appreciated.
function doSet(){ // this prepares the question
var score, prompting, answer, txt;
offset = Math.floor(Math.random()*(question.length + 1)); //get the random number
if(offset >= question.length){ // make sure its not out of range
doSet();
return;
}
score = document.getElementById('score'); //here we kill off the old text and enter in the new for the question
score.removeChild(score.firstChild);
txt = document.createTextNode('A4JP.com: What is the answer for:');
score.appendChild(txt);
prompting = document.getElementById('prompting'); //put the word to be translated into the 'prompting' div
prompting.removeChild(prompting.firstChild);
txt = document.createTextNode(english[offset]);
prompting.appendChild(txt);
answer = document.getElementById('answer'); // empty out the text field to make it blank
answer.value = '';
}
function doCheck(){ // this checks the answer
var x, y, score, txt;
score = document.getElementById('score');
score.removeChild(score.firstChild); // empty the 'score' div
x= document.getElementById('answer');//read the value in the text input box
if(x.value == question[offset]){ //react to the user input
txt = "Correct!";
}
else{
txt = question[offset];
}
txt = document.createTextNode(txt);
score.appendChild(txt); // display the output
}
function doClick(e){
var key;
if(window.event)
key = window.event.keyCode; //IE
else
key = e.which; //firefox
if (key == 13)
{
doCheck();
}
}
Regards,
edit by admin;please do not post full proper names, please wait for signature permissions before posting the first link only, the 2nd link is not permitted at all. Thank you