var userInput = new Array();
var answers = new Array(10);
answers[0] = "B";
answers[1] = "C";
answers[2] = "A";
answers[3] = "C";
answers[4] = "D";
answers[5] = "D";
answers[6] = "D";
answers[7] = "D";
answers[8] = "C";
answers[9] = "A";
function getScore(){
var score=0;
var numQuestions=10;
for (var i=0;iView Results
function returnScore(){
alert("Your score is "+ getScore() +"/"+ tot);
}
How many letters are there in "JS"?
2
1
3
4
How many letters are there in "BMX"?
2
1
3
4
How many letters are there in "A"?
2
1
3
4
var question0s = document.getElementsByName("question0");
for (var i = 0; i < question0s.length; i++) {
if (question0s[i].checked) {
userInput[0] = question0s[i].value;
}
}
userInput[0] = document.querySelector('input[name="question0"]:checked').value;
function getScore(){
for (var i = 0; i < answers.length; i++) {
var currentQuestion = "question" + i;
var questionAnswers = document.getElementsByName(currentQuestion);
for (var j = 0; j < questionResponses.length; j++) {
if (questionResponses[i].checked) {
userInput[i] = question0s[i].value;
}
}
}
// after this completes, you'll have the user input values
// the rest of your code should now work
for (var i=0;iQuiz Questions And Answers
Quiz Questions
< html > < body >
< script >
function returnScore() {
alert("Your score is " + getScore() + "/10");
}
< / script >
< form id = "form1" >
< li >
< h3 > How many letters are there in "JSX" ? < / h3 >
< input type = "radio" name = "question8" value = "A" > 2 < br >
< input type = "radio" name = "question8" value = "B" > 1 < br >
< input type = "radio" name = "question8" value = "C" > 3 < br >
< input type = "radio" name = "question8" value = "D" > 4 < br >
< / li >
< li >
< h3 > How many letters are there in "JS" ? < / h3 >
< input type = "radio" name = "question9" value = "A" > 2 < br >
< input type = "radio" name = "question9" value = "B" > 1 < br >
< input type = "radio" name = "question9" value = "C" > 3 < br >
< input type = "radio" name = "question9" value = "D" > 4 < br >
< / li >
< / form >
< button onclick = "javascript: returnScore()" > View Results < / button >
< script type = "text/javascript" >
var userInput = [];
var answers = []
answers[0] = "B";
answers[1] = "C";
answers[2] = "A";
answers[3] = "C";
answers[4] = "D";
answers[5] = "D";
answers[6] = "D";
answers[7] = "D";
answers[8] = "C";
answers[9] = "A";
function getScore() {
var score = 0;
var numQuestions = 10;
var form = document.getElementById('form1');
userInput[8] = form1.question8.value;
userInput[9] = form1.question9.value;
for (var i = 0; i < numQuestions; i++) {
if (userInput[i] == answers[i]) {
score += 1;
} else {
score += 0;
}
}
return score;
}
< / script >
< / body > < / html >
Today, there have been 39857 visitors (78697 hits) on this page!